Skip to content

Mathematical Morphology

Mathematical morphology is a way to study and modify shapes in an image.

We will start with binary images, where every pixel is either foreground or background.

Not familiar with the mathematical symbols?
You can continue reading without knowing set theory. The Symbols & Definitions page explains the notation used here.

1. Binary Images

A binary image contains only two pixel values:

  • 1 = foreground
  • 0 = background
0
1
1
0
0
0
1
1
1
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0

The blue pixels form the foreground object.

Instead of listing every 0 and 1, morphology often describes an image by storing only the locations of its foreground pixels. We call this collection of foreground locations \(X\).

\[ X \subseteq \mathbb{Z}^2 \]
Read this as: \(X\) is a collection of pixel locations on a 2D grid.

2. Matrix View and Location View

The same binary image can be described in two ways.

Matrix View

Store every pixel as a 0 or 1.

\[ \begin{bmatrix} 0 & 1 & 1 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \end{bmatrix} \]

Location View

Store only the locations where the image contains a 1.

\[ X = \{ (1,0), (2,0), (1,1) \} \]
Key idea: Both representations describe the same binary image. Morphology usually uses the location view because it makes shape operations easier to describe.

3. The Structuring Element

Morphology uses a small pattern called a structuring element.

We call the structuring element \(B\).

1
0
0
1
1
0
0
0
0

The structuring element acts like a small probe that moves across the image.

The locations containing a 1 are the active parts of the structuring element.

Purple cell: the origin, also called the anchor point.
\[ B \subseteq \mathbb{Z}^2 \]
Read this as: \(B\) is a collection of active locations in the structuring element.

4. Moving the Structuring Element

To perform morphology, we move the structuring element across the image one location at a time.

We use \(z\) to represent the current location of the anchor.

\[ B_z \]
\(B_z\) means: the structuring element \(B\) moved to location \(z\).
In the interactive visualizer, the purple outline shows the current location \(z\).

5. Reflection

Dilation uses a reflected version of the structuring element.

\[ B^r \]
\(B^r\) means: the structuring element reflected around its anchor.

On a 2D grid, this can be viewed as rotating the structuring element by \(180^\circ\).

6. Dilation

Dilation usually makes foreground objects larger.

At each location \(z\), ask:

Does at least one active point of the structuring element overlap a foreground pixel?

If yes, the output at that location becomes 1.

\[ X \oplus B = \left\{ z \mid (B^r)_z \cap X \neq \varnothing \right\} \]
Plain English:
Keep \(z\) if the reflected structuring element overlaps the foreground at least once.
Dilation: one overlap is enough → output = 1

7. Erosion

Erosion usually makes foreground objects smaller.

At each location \(z\), ask:

Do all active points of the structuring element fit inside the foreground?

If yes, the output at that location becomes 1.

\[ X \ominus B = \left\{ z \mid B_z \subseteq X \right\} \]
Plain English:
Keep \(z\) only if the entire active structuring element fits inside the foreground.
Erosion: every active point must fit → output = 1

8. Dilation vs. Erosion

Operation Question Output = 1 When Typical Effect
Dilation Does anything overlap? At least one active structuring-element point overlaps \(X\). Expands foreground objects.
Erosion Does everything fit? Every active structuring-element point lies inside \(X\). Shrinks foreground objects.
Easy way to remember:

Dilation: one overlap is enough.
Erosion: everything must fit.

9. Interactive Example

Move the structuring element across the image and watch how the condition changes at each location.

Green = condition satisfied
Red = condition not satisfied
Purple = anchor position


Interactive Morphology Visualizer

Structuring Element
Purple = Origin (0,0)
Reflected Kernel
180° reflection for Dilation / Convolution
Image Grid (Set X)
Editable. Click to toggle and jump window.
Output Array
Computation Result
0
0
Ready. Click "Auto-Play Sweep", "Step Forward", or click directly on the Image Grid.

10. What Do These Operations Do?

Dilation

Dilation can:

  • make objects larger,
  • fill small gaps,
  • connect nearby regions,
  • make thin foreground regions thicker.

Erosion

Erosion can:

  • make objects smaller,
  • remove small foreground regions,
  • break narrow connections,
  • separate nearby objects.

11. Summary

A binary image contains foreground pixels and background pixels.

We call the collection of foreground locations \(X\).

A structuring element, \(B\), is a small pattern used to examine the shape of \(X\).

The anchor tells us where the structuring element is currently positioned.

Dilation produces an output of 1 when at least one active point overlaps the foreground.

Erosion produces an output of 1 only when every active point fits inside the foreground.

Want to understand a symbol in more detail?

See Symbols & Definitions for explanations.


Published inDigital Image Processing

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *