Erosion
Shrink a bright mask by taking the minimum under a structuring element.
Two objects and a single-pixel speck make growth, shrinkage and cleanup easy to compare.
The orange window straddles the object boundary. Its covered pixels determine the new centre value.
A foreground pixel survives only if the entire 3 × 3 footprint is foreground.
100 foreground pixels become 49. A foreground pixel survives only if the entire 3 × 3 footprint is foreground.
Write the minimum; binary foreground survives only when all covered pixels are foreground.
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
Shrink white regions in a thresholded mask.
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
Remove small bright specks, break thin bridges, or require an entire neighbourhood to be foreground.
How it works
- 01Move a structuring element over the mask.
- 02Inspect all covered pixel values.
- 03Write the minimum; binary foreground survives only when all covered pixels are foreground.
erosion(A,B)(x) = min over b∈B of A(x+b)
What to tune
Kernel shape encodes which neighbours matter; iterations repeat the operation and increase the shrinkage.
Where it breaks down
Thin valid structures disappear. Grayscale erosion is a minimum filter, not merely a binary shape operation.
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
Dilation
Expand a bright mask by taking the maximum under a structuring element.
Opening, closing and morphology
Compose erosions and dilations to remove small structures or measure their boundaries.
Distance transforms
For every nonzero pixel, measure the distance to the nearest zero pixel.
Skeleton thinning
Iteratively remove boundary pixels while trying to preserve the connectivity of a binary shape.