Skip to content

Adaptive thresholding

Algorithm atlasSegmentation

Compute a different intensity threshold for each local neighbourhood.

Try it on your image ↓

VISUAL WALKTHROUGHSegmentation
REFERENCE INPUTObject under uneven lighting

The same scene stays here while the working view changes.

RESULTBinary selection mask

336 of 384 pixels pass the rule. The mask records membership, not the original brightness.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

Compute a threshold in each local grayscale neighbourhood.

The engine loads on your first run. Your images stay in this browser.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Read documents or segment surfaces under slowly varying illumination.

How it works

  1. 01Estimate a local mean or Gaussian-weighted mean.
  2. 02Subtract the offset C.
  3. 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.