Adaptive thresholding
Compute a different intensity threshold for each local neighbourhood.
The same scene stays here while the working view changes.
Different parts of the object have different intensities because the illumination changes across the image.
Each pixel uses its own local mean minus C = 5.
336 of 384 pixels pass the rule. The mask records membership, not the original brightness.
Threshold the centre pixel against its local estimate.
Computed teaching example on a 24 × 16 image. Small kernels and simplified settings keep each change visible; use the image laboratory for native OpenCV.
Try it on an image
Experiment at pixel level
Compute a threshold in each local grayscale neighbourhood.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Read documents or segment surfaces under slowly varying illumination.
How it works
- 01Estimate a local mean or Gaussian-weighted mean.
- 02Subtract the offset C.
- 03Threshold the centre pixel against its local estimate.
T(x,y) = local statistic(x,y) − C
What to tune
blockSize must be odd and greater than one; C shifts the threshold; choose mean or Gaussian weighting.
Where it breaks down
Small windows follow texture and noise. Large windows stop adapting to illumination changes. The input is an 8-bit single-channel image.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Global thresholding
Divide pixels using one intensity threshold, or choose it automatically with Otsu or the triangle method.
Connected components
Give every connected foreground region a distinct integer label.
Contour tracing
Trace the boundary of each binary region as an ordered sequence of points.
Marker-based watershed
Grow labelled regions across an image until competing regions meet at boundaries.