Erosion
Shrink foreground regions in a binary mask so thin noise and small protrusions disappear.
Morphology is nested under Segmentation & edges , so the broader pipeline usually still applies here.
Interactive playground
Tweak the operator or scene live so the article connects to an immediate visual result.
Erosion
Shrink bright mask regions so thin noise disappears and boundaries contract.
Source image
Procedural inputWebGPU result
Eroded maskControls
Adjust the neighborhood size, repeat count, or decision threshold to see how the shader compounds the result.
Checking WebGPU support...
Family
Foundations -> Segmentation & edges -> Morphology
Binary-mask operators such as dilation, erosion, opening, and closing.
Builds on
2 topics
Read these first if you want the surrounding pipeline context.
Unlocks
2 next topics
Use these follow-ups when you want to keep turning the image-processing pipeline forward.
Learning paths
1
This topic appears in curated graphics progressions so the next step is obvious.
Choose this over that
Shrink the mask only when that is really the goal
Erosion is the mirror image of dilation, and opening/closing use both in sequence to clean binary masks more selectively.
Erosion
Choose this when: Foreground regions should contract so tiny bright noise disappears.
Choose something else when: You actually need to bridge gaps or grow the mask.
Dilation
Choose this when: Broken regions should reconnect and the mask should expand.
Choose something else when: Boundary shrinkage is the desired effect.
Opening and Closing
Choose this when: The mask needs a cleaner composite operation that shrinks and regrows in a controlled order.
Choose something else when: A single erosion already gives the result you want.
Problem
Sometimes the mask error goes in the opposite direction:
- bright specks should disappear
- boundaries are too fat
- tiny protrusions should be trimmed away
You want the foreground to contract rather than expand.
Intuition
Erosion asks:
Are all pixels inside the structuring element foreground?
If even one required neighbor is background, the output becomes background.
So erosion behaves like a local min over a binary mask.
The operator
Using a 3 x 3 structuring element, each output pixel becomes 1 only if every pixel in that neighborhood is 1.
In pseudocode:
output[x, y] = 1 if all input neighbors in the window are 1
That causes bright regions to shrink inward.
Worked example
Suppose a 1D mask is:
0 1 1 1 0
With a radius-1 erosion:
0 0 1 0 0
Only the interior survives. Borders contract.
In 2D, that removes thin protrusions and small bright islands quickly.
What erosion is good at
- removing isolated bright noise
- trimming overly thick masks
- stripping away small protrusions
- preparing for opening
But erosion can also destroy thin legitimate structures if you use too large a radius.
Complexity
For an image with pixels and a structuring element of size :
- direct erosion costs
As with dilation, small fixed kernels are common in practice.
GPU implementation note
Erosion is the mirror image of dilation in GPU terms:
- each output pixel scans a local window
- the operator reduces the neighborhood with a min-like rule
- radius changes are very easy to expose interactively
So it is a great pair with dilation for teaching morphology.
When to choose it
Choose erosion when:
- the foreground should shrink
- tiny bright defects should disappear
- object boundaries are too fat
Choose something else when:
- gaps need to close rather than widen
- regions are already thin and fragile
- a one-step shrink is too destructive
Key takeaways
- Erosion shrinks foreground regions
- It is the binary-mask counterpart of a local min
- It removes small bright structures aggressively
- It is the opposite primitive from dilation
- Opening uses erosion first to remove noise before regrowing the surviving structure
Practice ideas
- Erode the same mask with multiple radii and note when legitimate thin structures vanish
- Compare erosion and dilation on a mask that contains both holes and bright specks
- Use erosion as the first step of opening, then see why the following dilation does not simply undo everything
Relation to other topics
- Thresholding often creates the mask erosion operates on
- Dilation expands masks, while erosion contracts them
- Opening and closing combine both primitives, with order determining behavior
Build on these first
These topics supply the mental model or preceding stage that this page assumes.
Image Processing Fundamentals
Build the mental model behind blur, thresholding, edges, and morphology: pixels, neighborhoods, kernels, masks, and why local operators compose into pipelines.
Thresholding
Convert a grayscale image into a binary mask by splitting values into foreground and background.
What this enables
Once the current operator feels natural, these are the most useful follow-up jumps.
Related directions
These topics live nearby conceptually, even if they are not strict prerequisites.
Distance Transform
For every foreground pixel, compute how far it sits from the background or boundary so the mask gains geometric thickness information.
Dilation
Grow foreground regions in a binary mask so gaps close and thin structures get thicker.
Opening and Closing
Compose erosion and dilation to remove bright specks or fill small holes without manually editing the mask.
More from Morphology
Stay in the same family when you want parallel operators built from the same mental model.
Dilation
Grow foreground regions in a binary mask so gaps close and thin structures get thicker.
Opening and Closing
Compose erosion and dilation to remove bright specks or fill small holes without manually editing the mask.
Skeletonization
Reduce a thick binary shape to a thin centerline while trying to preserve its topology.
Paths that include this topic
Follow one of these sequences if you want a guided next step instead of open-ended browsing.
Mask analysis and cleanup
Build a binary mask, explore connectivity, then repair or simplify it with morphology-aware tools.
From the blog
Pair the graphics atlas with recent writing from the broader site whenever you want a wider engineering lens.