Dilation
Expand a bright mask by taking the maximum 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.
The 3 × 3 footprint expands the foreground by one pixel on each side.
100 foreground pixels become 174. The 3 × 3 footprint expands the foreground by one pixel on each side.
Write the maximum and advance to the next position.
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
Grow 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
Connect nearby foreground regions, thicken lines, or expand a region of interest.
How it works
- 01Place the kernel at one output position.
- 02Look for any foreground within its footprint.
- 03Write the maximum and advance to the next position.
dilation(A,B)(x) = max over b∈B of A(x+b)
What to tune
Choose the structuring-element shape, anchor and number of iterations to match the scale of the gap.
Where it breaks down
Separate objects may merge. A large kernel can close a gap that carries important structure.
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
Erosion
Shrink a bright mask by taking the minimum 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.