Skip to content

Global thresholding

Algorithm atlasSegmentation

Divide pixels using one intensity threshold, or choose it automatically with Otsu or the triangle method.

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

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

STEP 03 / 03

Write the selected binary, truncated, or retained value.

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 ↗

Threshold grayscale pixels, optionally choosing the level with Otsu.

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

Separate a well-lit foreground from a background with a different intensity distribution.

How it works

  1. 01Read the intensity at a pixel.
  2. 02Compare it with a global threshold.
  3. 03Write the selected binary, truncated, or retained value.

binary(x,y) = I(x,y) > T ? maxval : 0

What to tune

type controls the rule; maxval sets the foreground value. The returned scalar is the threshold that was used.

Where it breaks down

One threshold struggles with shadows and uneven illumination. Otsu is most useful when a histogram separates into distinct populations.

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.