Morphological operations transform a binary image using a small pattern called a
structuring element (SE).
Dilation: increases object area and accentuates features. Implements a sliding-maximum over the SE (a max filter): a pixel becomes 1 if any pixel under the SE is 1.
Erosion: decreases object area and removes small features. Implements a sliding-minimum (a min filter): a pixel stays 1 only if all pixels under the SE are 1.
Opening (erosion → dilation): removes small noise and thin protrusions smaller than the SE while preserving larger shapes.
Closing (dilation → erosion): fills small holes and bridges small gaps narrower than the SE.
Boundary: estimates the outline via A − (A ⊖ SE) (original minus eroded).
The canvas shows an upscaled binary grid. Buttons apply operations in-place; Undo reverts the last change.
Structuring element
Radius: 3
SE preview
Grow shapes: set a pixel to 1 if any pixel in its SE-neighborhood is 1 (max filter).
Shrink shapes: keep a pixel 1 only if all pixels in its SE-neighborhood are 1 (min filter).
Erode then dilate: remove small speckles/protrusions smaller than the SE; smooths contours.
Dilate then erode: fill small holes and bridge narrow gaps; connects nearby components.
Outline estimate: A − (A ⊖ SE); yields a ~1–r pixel wide border depending on the SE.