Morphological Closing Explained
Closing dilates first to plug holes, then erodes to pull outlines back. Gaps fill while outer boundaries return to place.
Why Does This Exist?
Dilation alone fills holes but also swells everything permanently. You want the fill without the fattening. Closing inverts the opening recipe: dilate first to plug interior gaps and cracks, then erode to pull the outer boundary back where it belongs.
It is the standard gap filler in morphological operations. Broken text strokes, cracked defect masks, and pinholes in segmentations are its home turf.
Think of It Like This
Caulk then sand
Fill wall cracks with caulk, which bulges proud of the surface like dilation swelling the shape. Then sand flush, which is erosion shaving the bulge back. The cracks stay filled because caulk reached inside them, while the wall face returns to flat. Skipping the sanding leaves lumpy walls, which is why bare dilation is rarely the final step.
How It Actually Works
Closing with structuring element applies dilation then erosion, written . Dilation expands foreground into holes, cracks, and narrow gaps. The erosion pass then strips the added outer layer back off. Exterior boundaries return close to their start, but filled interiors survive because surrounding foreground now supports them against the probe.
Worked example
A block of 1s has a 0 hole at its center. Dilation with a probe: neighbouring 1s overlap the probe at the center, so it becomes 1 and the block is solid. Erosion of the solid block: every probe position sits fully on 1s except at the outer rim, so the interior stays 1. Final result: hole filled, outline unchanged.
Watch Out For
Narrow true gaps get sealed
Closing cannot distinguish a crack from a genuine narrow gap between two objects: both fill. The symptom is merged letters or joined parts after repair. Keep the probe smaller than the narrowest gap you must preserve, and inspect a before-and-after overlay when gaps matter.
The Quick Version
- Closing is dilation followed by erosion with the same probe.
- Holes and cracks fill in the first pass and survive the second.
- Outer boundaries return close to their original place.
- It fills interior defects but cannot remove exterior specks; that is opening.
- Size the probe below the narrowest gap you must keep open.