Dilation
Grow foreground regions in a binary mask so gaps close and thin structures get thicker.
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.
Dilation
Grow bright mask regions outward so narrow gaps close and thin structures thicken.
Source image
Procedural inputWebGPU result
Dilated 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
1 next topic
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
Expanding vs. shrinking a mask
Dilation, erosion, and their composites all inspect local neighborhoods, but they move boundaries in opposite directions.
Dilation
Choose this when: Small gaps should close and foreground regions should expand outward.
Choose something else when: Thin noise or boundary fattening is actually a problem.
Erosion
Choose this when: You need to trim mask boundaries or remove tiny foreground specks.
Choose something else when: The mask should grow, not shrink.
Opening and Closing
Choose this when: One primitive operation is not enough and the mask needs a composite clean-up pass.
Choose something else when: A single grow or shrink step already solves the issue.
Problem
A binary mask is often almost correct but not quite:
- tiny gaps split a region in two
- lines are thinner than they should be
- nearby foreground pieces fail to touch
You want to grow the foreground outward in a controlled way.
Intuition
Dilation asks:
Does this pixel have any foreground neighbor inside the structuring element?
If the answer is yes, the output becomes foreground.
So dilation behaves like a local max over a binary mask.
The operator
Using a 3 x 3 structuring element, each output pixel becomes 1 if any pixel in that neighborhood is 1.
In pseudocode:
output[x, y] = 1 if any input neighbor in the window is 1
That causes bright regions to expand outward.
Worked example
Suppose a 1D mask is:
0 0 1 0 0
With a radius-1 dilation, the foreground grows:
0 1 1 1 0
In 2D, the same effect thickens shapes and can bridge narrow gaps.
What dilation is good at
- reconnecting nearly-touching regions
- thickening thin lines
- filling tiny breaks
- making later selection logic less fragile
But dilation also has a cost: it can overgrow objects and blur their binary boundaries outward.
Complexity
For an image with pixels and a structuring element of size :
- direct dilation costs
For small fixed kernels, that is often perfectly practical.
GPU implementation note
Dilation maps cleanly to WebGPU:
- each output pixel checks a local neighborhood
- there are no cross-pixel dependencies beyond that neighborhood
- the operator is effectively a local max on binary values
That makes it easy to animate the effect of increasing the morphology radius.
When to choose it
Choose dilation when:
- foreground regions should expand
- tiny gaps should seal
- thin structures should be reinforced
Choose something else when:
- the mask is already too thick
- small bright noise should disappear rather than spread
- you need a more selective two-step cleanup
Key takeaways
- Dilation grows foreground regions
- It is the binary-mask counterpart of a local max
- It is excellent for closing tiny breaks, but it can also overgrow shapes
- Dilation is one of the two primitive morphology operators
- Composite tools such as closing are built from it
Practice ideas
- Dilate a sparse mask with radius 1, 2, and 3 and note when separate components merge
- Compare direct dilation with closing on a mask that has both narrow gaps and isolated noise
- Build a threshold -> dilation pipeline and describe what gets fixed and what gets worse
Relation to other topics
- Thresholding often produces the mask that dilation then repairs
- Erosion is the opposite primitive: it shrinks foreground rather than grows it
- Opening and closing combine dilation and erosion to solve more targeted cleanup problems
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.
Flood Fill
Grow one connected region from a seed pixel, making it the canonical seeded region-growing primitive.
Erosion
Shrink foreground regions in a binary mask so thin noise and small protrusions disappear.
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.
Erosion
Shrink foreground regions in a binary mask so thin noise and small protrusions disappear.
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.