Skip to main content
BVDART Logo
← All guidesFilters & transforms

Mathematical morphology

Morphology transforms shapes by comparing a neighborhood defined by a structuring element. It works on binary images and can also operate on grayscale or channel values.

Edit a binary shape and its structuring element

Edit the foreground43 px
Edit the structuring element
min → max →
Open38 px
Watch both stages

01 · Erode

02 · Dilate

Filled cells represent foreground (1). Opening removes the isolated speck; closing fills the hole. The center tap remains active. Outside the finite mask is 0; dilation reflects asymmetric taps. Use arrow keys to move between mask cells, then Space to toggle.

Pair erosion with opening, then dilation with closing, to distinguish removing specks from filling holes. Use any control to take over.

What to try
  1. Toggle foreground cells and taps around the fixed center of the structuring element.
  2. Compare erosion, dilation, opening and closing; inspect both stages of the composed operations.
Open in the Lab ↗

What to look for: Opening removes a small isolated speck; closing can fill the hole. A foreground cell is 1, the exterior is 0, and asymmetric taps are reflected for dilation.

How it works

Dilation takes a neighborhood maximum and expands bright regions; erosion takes a minimum and contracts them. Opening applies erosion then dilation, removing small bright structures. Closing reverses the order and fills small dark interruptions. Square, disc and cross neighborhoods differ in their directional behavior.

The morphological gradient subtracts erosion from dilation to emphasize boundaries. White top-hat extracts bright detail removed by opening; black top-hat extracts dark detail removed by closing. The result depends on scale: a feature can survive a small element and disappear under a larger one.

Use it in the Lab

Use morphology after thresholding to alter a mark’s silhouette, connect regions, separate thin bridges or extract small details. In the Lab, choose luminance, RGB or alpha processing according to what should count as the shape.

Limits & distinctions

Per-channel RGB morphology can create colors absent from the source. Alpha morphology changes coverage; luminance morphology changes a tonal interpretation.

Sources & references

Guide updated