= Adaptive thresholding
<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.<Image Thresholding in the OpenCV documentation>[Adaptive Thresholding, varying illumination and local neighborhoods]{ref}
For a simple real-arithmetic local-mean model, put
$$
T(x,y)=\overline I_{\mathcal N(x,y)}-C,\qquad
B(x,y)=\mathbf1\{I(x,y)>T(x,y)\},
$$
where $\overline I_{\mathcal N}$ is the neighborhood <mean> and $C$ 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.<Image Thresholding in the OpenCV documentation>[Adaptive Thresholding, ADAPTIVE_THRESH_MEAN_C, ADAPTIVE_THRESH_GAUSSIAN_C, blockSize and C; Simple Thresholding]{ref}
Consider a three-by-three patch with eight values of $100$ and a central value of $80$. For $C=10$,
$$
\overline I=\frac{880}{9},\qquad T=\frac{790}{9}\simeq87.78,
$$
so the centre receives binary value zero. Adding $60$ to every intensity gives eight values of $160$ and a centre of $140$. Now $T=1330/9\simeq147.78$, so the centre still receives zero. A fixed threshold of $110$ 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 $b$, its mean and threshold also increase by $b$. Hence $I+b>T+b$ exactly when $I>T$. 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.
Back to article page