Global thresholding
Divide pixels using one intensity threshold, or choose it automatically with Otsu or the triangle method.
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.
This binary example keeps pixels strictly greater than 128.
171 of 384 pixels pass the rule. The mask records membership, not the original brightness.
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
Experiment at pixel level
Threshold grayscale pixels, optionally choosing the level with Otsu.
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
Separate a well-lit foreground from a background with a different intensity distribution.
How it works
- 01Read the intensity at a pixel.
- 02Compare it with a global threshold.
- 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.
Related methods
Adaptive thresholding
Compute a different intensity threshold for each local neighbourhood.
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.