Adaptive thresholding 2026-11-05
Adaptive thresholding uses an image threshold that varies with position, often calculated from a neighborhood around each pixel. It can help separate marks from background when illumination changes across an image. A global image thresholding rule instead uses the same threshold everywhere.[ref]
For a simple real-arithmetic local-mean model, put
where is the neighborhood mean and a fixed offset. OpenCV documents local-mean and Gaussian-weighted alternatives, with a declared neighborhood size. Its binary comparison assigns the high output value only above the threshold.[ref]
Consider a three-by-three patch with eight values of and a central value of . For ,
so the centre receives binary value zero. Adding to every intensity gives eight values of and a centre of . Now , so the centre still receives zero. A fixed threshold of would classify the two centre values differently, despite their identical contrast with their local backgrounds.
The invariance follows algebraically. If every intensity in a neighborhood increases by the same , its mean and threshold also increase by . Hence exactly when . This proves an additive-shift property of the stated model, assuming no clipping or rounding; it is not a claim about arbitrary spatial gradients or multiplicative brightness changes.
Neighborhood size and offset affect the result. A very small neighborhood can follow noise or include too little background, while a large one can span changing illumination. Integer rounding and image-edge handling must also be specified for an exact implementation comparison. The resulting binary image remains an intensity-based selection; connected-component labeling and semantic interpretation are further steps.
Foreground-background polarity specifies which of two image classes is treated as the selected structure and which as its background. It involves a numerical convention as well as the intended interpretation: high-valued pixels can represent foreground in one encoding, while a dark feature may require the opposite threshold direction. A binary image's appearance alone does not establish its polarity.
For a chosen intensity threshold , define complementary normalized masks
The second is the complement of a set within the declared pixel grid. For the stipulated row and , the two binary selection masks are and . Equality belongs to the second selection. OpenCV's THRESH_BINARY and THRESH_BINARY_INV use these respective comparison directions, with the chosen output maximum replacing 1.[ref]
An image lookup table is a separate mapping from stored values to displayed colors. ImageJ's Create Mask command writes 255 inside a selection and 0 outside, but its default inverting lookup table can display the selected 255-valued pixels as black.[ref] Reversing that display mapping does not exchange the stored pixel values.
The distinction has a direct computational consequence. In its binary-image input, the documented Sholl analysis implementation treats zero intensities as background regardless of the lookup table or Black Background option.[ref] A visually inverted display can therefore leave the selected numerical structure unchanged, whereas replacing an 8-bit mask by exchanges its zero and 255 classes.
A reproducible geometric measurement records the threshold comparison, the values assigned to selected and excluded pixels, and any display-only inversion. A region of interest can further restrict the grid over which a complement is intended; reversing a mask over the whole image is different from selecting its complement only inside that region.
Image thresholding 2026-11-05
Image thresholding classifies pixels by comparing their intensities with a threshold, often producing a binary image. A global threshold uses the same value throughout the image; adaptive thresholding permits the threshold to depend on position and nearby intensities.[ref]
For example, define
Intensities then become . The comparison at equality matters: a rule using would instead give . OpenCV's THRESH_BINARY uses the strict greater-than rule, assigning its chosen maximum output value only above the threshold.[ref]
Threshold choice affects which distinctions survive. Two different bright intensities can become the same foreground value, while a small change near the boundary can change a pixel's classification. The resulting mask can then feed connected-component labeling, where pixel connectivity separately decides which selected pixels form a region.
A useful motivating experiment keeps one image of dark marks fixed while adding or recording a gradual illumination variation across the background. Compare a global threshold with a declared local-neighborhood rule, inspecting lost strokes and falsely selected background. OpenCV documents local mean and Gaussian-weighted rules with an offset; this addresses varying illumination rather than proving that every resulting region is a meaningful object.[ref]
A histogram can guide global selection, but intensity statistics alone do not determine semantic identity. Noise and overlapping foreground/background intensities can make every threshold imperfect. Report the input representation, comparison convention and any filtering or local-window settings so that a thresholded result can be reproduced.