Skip to content

Erosion

Algorithm atlasMorphology

Shrink a bright mask by taking the minimum under a structuring element.

Try it on your image ↓

VISUAL WALKTHROUGHMorphology
REFERENCE INPUTBinary mask

Two objects and a single-pixel speck make growth, shrinkage and cleanup easy to compare.

RESULTChanged foreground

100 foreground pixels become 49. A foreground pixel survives only if the entire 3 × 3 footprint is foreground.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

Shrink white regions in a thresholded mask.

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

Remove small bright specks, break thin bridges, or require an entire neighbourhood to be foreground.

How it works

  1. 01Move a structuring element over the mask.
  2. 02Inspect all covered pixel values.
  3. 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.