CV Lab 15 · Module 5 — Morphology

Morphological Operations

A completely different kind of filter — instead of blending intensities, morphology reshapes silhouettes. Slide a small "structuring element" across a binary shape: require a full fit and the shape shrinks (erosion); allow any touch and it grows (dilation). Everything else in this lab — opening, closing, gradients — is just those two ideas combined.

Shrink. Grow. Repeat. Erosion shrinks the shape and deletes the small bump entirely — anything thinner than the structuring element disappears. Dilation grows the shape and fills the small notch — any gap smaller than the structuring element gets patched.
Ready.
SE size
5×5
Iterations

Click anywhere on the image to see the structuring element placed at that exact pixel, and whether erosion/dilation turns it on or off.

Structuring element fit-test
Erosion needs ALL cells white

Every operation is built from two moves

Erosion — the strict one

A pixel survives only if every cell of the structuring element sits on foreground. One black pixel anywhere under the element kills it. This is why thin lines, small dots, and sharp points vanish first.

Dilation — the generous one

A pixel turns on if any cell of the structuring element touches foreground. This is why small gaps, thin cracks, and single missing pixels get patched over.

Order matters

Erode-then-dilate (opening) permanently deletes anything too small to survive the erosion step. Dilate-then-erode (closing) permanently fills anything too small to survive as a gap. Same two ingredients, opposite order, opposite job.

Predict, then verify

Your binary image has scattered single-pixel "salt" noise dots everywhere, and the real object also has a couple of small holes punched through it that shouldn't be there. One structuring element, one operation you can run once — which do you reach for?