Skip to content

Add automatic background threshold algorithm (estimate from image edges) #11

@Marek55S

Description

@Marek55S

Summary

Provide an algorithm that automatically estimates a background/offset level and computes a threshold to remove background pixels. A simple and robust approach is to sample pixel strips near the image borders (or configurable regions), estimate a background value (median, mode, or robust mean), and set the threshold as background + k * sigma (or user-adjustable factor). This helps users remove background noise without manual threshold tuning.

User story

As a user, I want the app to automatically compute a reasonable threshold for masking or zeroing low-intensity background pixels so I can quickly focus on signal features without manually guessing threshold values.

Algorithm ideas

  1. Edge-strips sampling (default): sample N rows/cols from each border (top, bottom, left, right) and aggregate samples to estimate background distribution.
  2. Histogram-based: compute histogram, find the dominant low-intensity peak (mode) and set threshold at mode + k * sigma.
  3. Adaptive local: compute local background per tile and combine (more complex, optional).

UI

  • "Auto threshold" option in algorithms menu or new button that computes and previews threshold.
  • Allow user to accept or fine-tune the computed threshold.

Edge cases

  • Images with signal near edges: allow specifying sampling regions or excluding specific edges (optionally, as target images have valuable data centered).
  • 16-bit images: scale computations to appropriate range.
  • Very small images: fallback to global histogram method.

Acceptance criteria

  • The auto computed threshold removes most of the background in representative test images.
  • UI allows previewing and adjusting before applying.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions