Skip to content

Gray-Scale Mathematical Morphology

Binary morphology describes objects as sets of foreground locations. Gray-scale morphology extends the same geometric ideas to images whose pixels have ordered intensity values.

This page does not repeat binary dilation, erosion, opening, closing, or the general theory of minimum and maximum filters. Instead, it focuses on the ideas that become important when morphology acts on gray-scale functions: ordering, umbras, threshold sets, gray-scale morphological operators, and stack filters.

1. From Binary Sets to Gray-Scale Functions

A binary image can be represented by a foreground set \(X\). A gray-scale image instead assigns an intensity to every spatial location:

\[ f:D\rightarrow Q, \]

where \(D\) is the image domain and \(Q\) is an ordered set of gray levels.

For an 8-bit image,

\[ Q=\{0,1,\ldots,255\}. \]
A Gray-Scale Image Is a Function of Position
30
50
70
50
30
50
100
170
100
50
70
170
240
170
70
50
100
170
100
50
30
50
70
50
30
In binary morphology we compare membership in sets. In gray-scale morphology we also use the ordering of intensity values.

2. Pointwise Minimum, Maximum, and Ordering

Given two gray-scale functions \(f\) and \(g\), their pointwise meet and join are

\[ (f\wedge g)(p) = \min\{f(p),g(p)\} \] \[ (f\vee g)(p) = \max\{f(p),g(p)\}. \]

Pointwise Meet

40
180
90
220
110
80
120
160
150
130
40
120
90
150
110
\(f\wedge g=\min(f,g)\)

Pointwise Join

40
180
90
220
110
80
120
160
150
130
80
180
160
220
130
\(f\vee g=\max(f,g)\)
These are pointwise lattice operations. They are not the same thing as applying a neighborhood minimum or maximum filter to an image.

3. The Umbra of a Gray-Scale Function

A useful way to connect a gray-scale function to set morphology is to imagine stacking points underneath its intensity graph.

For a nonnegative discrete gray-scale function \(f\), define its umbra as

\[ U(f) = \{ (p,t) \mid p\in D,\; 0\le t\le f(p) \}. \]
Umbra: Everything at or Below the Gray-Level Function
1
3
2
4
2
\(p_1\)
\(p_2\)
\(p_3\)
\(p_4\)
\(p_5\)
The bar height represents \(f(p)\). The entire blue region below that height belongs to \(U(f)\). Horizontal slices through this higher-dimensional set produce the threshold sets introduced next.

4. Threshold Sets

For a gray level \(t\), define the threshold set

\[ T_t(f) = \{ p\in D \mid f(p)\ge t \}. \]

Each \(T_t(f)\) is a binary set containing the locations whose gray level reaches at least \(t\).

Example on \(Q=\{0,1,2,3\}\)
\(f\)
0
1
3
2
3
1
0
\(T_1(f)\)
0
1
1
1
1
1
0
\(T_2(f)\)
0
0
1
1
1
0
0
\(T_3(f)\)
0
0
1
0
1
0
0
As \(t\) increases, threshold sets can only become smaller: \[ T_{t+1}(f)\subseteq T_t(f). \]

5. Reconstructing Gray Levels from Threshold Sets

The threshold representation does not discard the original gray-level information.

For the unit-spaced discrete gray scale

\[ Q=\{0,1,\ldots,L\}, \]

the original value at \(p\) can be recovered by counting the positive threshold sets that contain \(p\):

\[ f(p) = \sum_{t=1}^{L} \mathbf{1}_{T_t(f)}(p). \]
Gray-Scale Image \(f\)
↓
Binary Layers \(T_1(f),T_2(f),\ldots,T_L(f)\)
↓
Add the Binary-Layer Values at Each Location
↓
Recover \(f\)
A gray-scale image can therefore be viewed as a stack of nested binary threshold sets.

6. Gray-Scale Structuring Elements

In binary morphology, a structuring element mainly specifies a set of spatial locations relative to its origin. In gray-scale morphology, the structuring element may also assign a height value to each location in its support.

This leads to an important distinction between flat and non-flat structuring elements.

Flat and Non-Flat Structuring Elements

Flat Structuring Element

Every active location has the same height. Using the usual zero-height convention:
0
0
0
0
0
\[ b(u,v)=0, \qquad (u,v)\in D_b \]
All locations in the support \(D_b\) have zero gray-level height.

Because every active value is zero, only the spatial support of the structuring element affects the flat gray-scale operation.

Non-Flat Structuring Element

Active locations can have different gray-level heights.
1
1
3
1
1
\[ b: D_b \rightarrow \mathbb{R} \]
Each location \((u,v)\in D_b\) may have its own height \(b(u,v)\).

A non-flat structuring element therefore contributes both its spatial support and its gray-level height values to the operation.

Active SE support
Origin
A flat SE tells us primarily where to look. A non-flat SE tells us both where to look and what height to add or subtract.
The examples later on this page and in the interactive visualizer use symmetric flat structuring elements. This keeps the focus on the maximum/minimum interpretation of gray-scale dilation and erosion.

7. Gray-Scale Dilation

For a gray-scale image \(f\) and a gray-scale structuring element \(b\), dilation combines the image values with the structuring-element values and selects the largest result:

\[ (f\oplus b)(x,y) = \max_{(u,v)\in D_b} \left[ f(x-u,y-v)+b(u,v) \right]. \]
In more general mathematical treatments, gray-scale dilation may be written using the supremum \(\sup\). For finite digital images and finite structuring elements, the largest value is attained, so the ordinary maximum \(\max\) is sufficient here.

If the structuring element is flat, then \(b(u,v)=0\) on its support. The equation simplifies to

\[ (f\oplus B)(x,y) = \max_{(u,v)\in B} f(x-u,y-v). \]
Example Neighborhood
70
90
85
95
110
210
80
100
75

Flat Dilation

\[ \max \{ 70,90,85, 95,110,210, 80,100,75 \} = 210 \]

The output pixel receives the largest intensity found under the active structuring-element support.

For a flat structuring element, gray-scale dilation acts as a local maximum. Bright structures therefore tend to expand, while small dark gaps may become smaller.
A useful memory rule is: dilation looks upward for the largest nearby gray value.

8. Gray-Scale Erosion

Gray-scale erosion performs the complementary operation. It subtracts the structuring-element values from the image values and selects the smallest result:

\[ (f\ominus b)(x,y) = \min_{(u,v)\in D_b} \left[ f(x+u,y+v)-b(u,v) \right]. \]
In more general mathematical treatments, gray-scale erosion may be written using the infimum \(\inf\). For finite digital images and finite structuring elements, the smallest value is attained, so the ordinary minimum \(\min\) is sufficient here.

For a flat structuring element, \(b(u,v)=0\), so erosion simplifies to

\[ (f\ominus B)(x,y) = \min_{(u,v)\in B} f(x+u,y+v). \]
Same Example Neighborhood
70
90
85
95
110
210
80
100
75

Flat Erosion

\[ \min \{ 70,90,85, 95,110,210, 80,100,75 \} = 70 \]

The output pixel receives the smallest intensity found under the active structuring-element support.

For a flat structuring element, gray-scale erosion acts as a local minimum. Dark structures therefore tend to expand, while small bright peaks may become smaller.
A useful memory rule is: erosion looks downward for the smallest nearby gray value.
These maximum and minimum interpretations overlap with ideas from nonlinear filtering, but here they are being used specifically as morphological operations defined by a structuring element.

9. Gray-Scale Opening and Closing

The compositions are the same as in binary morphology, but the intermediate images now contain gray levels.

min → max

Gray-Scale Opening

First erosion, then dilation
\[ f\circ B = (f\ominus B)\oplus B \]

Opening suppresses bright structures that are too small to survive the erosion stage.

max → min

Gray-Scale Closing

First dilation, then erosion
\[ f\bullet B = (f\oplus B)\ominus B \]

Closing suppresses small dark structures and fills narrow dark valleys.

We do not need to relearn the opening/closing sequence. The new idea is how that sequence behaves on ordered gray levels instead of binary membership.

10. Morphological Gradient and Top-Hats

Once gray-scale dilation, erosion, opening, and closing are available, several useful intensity-domain operations follow naturally.

Morphological Gradient

\[ G_B(f) = (f\oplus B) – (f\ominus B) \]

Measures the difference between the local upper and lower morphological envelopes.

Large values often occur near strong intensity transitions.

White Top-Hat

\[ T_W(f) = f-(f\circ B) \]

Extracts bright structures removed by the opening.

Black Top-Hat

\[ T_B(f) = (f\bullet B)-f \]

Extracts dark structures removed by the closing.

11. Gray-Scale Morphology Through Threshold Sets

For flat morphology, thresholding and the basic morphological operations fit together in a particularly useful way.

\[ T_t(f\oplus B) = T_t(f)\oplus B \] \[ T_t(f\ominus B) = T_t(f)\ominus B. \]
Gray-Scale Image \(f\)
↓
Form Threshold Sets \(T_1(f),T_2(f),\ldots\)
↓
Apply Binary Morphology to Each Layer
↓
Stack the Filtered Layers
↓
Gray-Scale Morphological Result
This is the bridge between the binary morphology learned earlier and gray-scale morphology: a gray-scale image can be decomposed into binary layers, processed consistently, and assembled again.

12. Stack Filters

Threshold decomposition also provides the architecture for a broader family of nonlinear filters called stack filters.

A stack filter applies the same positive Boolean function to the neighborhood in each binary threshold layer, then reconstructs the gray-scale result.

Input Gray-Scale Sequence \(x_k\)
↓
Form \(T_1(x),T_2(x),\ldots,T_L(x)\)
↓
Apply the Same Positive Boolean Function \(\mathcal{B}\) to Every Threshold Layer
↓
Obtain Filtered Binary Layers
↓
Stack the Layers to Form \(y_k\)

Example: Three-Point Median as a Stack Filter

For three binary inputs \(a,b,c\), the majority function is

\[ \mathcal{B}(a,b,c) = ab \vee ac \vee bc. \]

It outputs 1 when at least two of its three binary inputs are 1.

At each threshold,

\[ Y_t(k) = \mathcal{B} \left( T_t(x_{k-1}), T_t(x_k), T_t(x_{k+1}) \right). \]

For the unit-spaced gray scale \(Q=\{0,1,\ldots,L\}\),

\[ y_k = \sum_{t=1}^{L} Y_t(k). \]
The interactive stack-filter example uses \(Q=\{0,1,2,3\}\). This section focuses on the threshold-stack architecture; the broader treatment of median and order-statistic filters remains on the Nonlinear Filtering page.

13. Comparing Gray-Scale Morphological Operations

Operation Flat-SE Interpretation Typical Gray-Scale Effect
Dilation Local maximum over \(B\) Expands bright structures and raises local peaks
Erosion Local minimum over \(B\) Expands dark structures and lowers local valleys
Opening Erosion → dilation Suppresses small bright features
Closing Dilation → erosion Suppresses small dark features
Morphological Gradient Dilation − erosion Emphasizes local intensity transitions
White Top-Hat \(f-\text{opening}\) Extracts small bright structures
Black Top-Hat \(\text{closing}-f\) Extracts small dark structures

14. Interactive Gray-Scale Morphology Explorer

The visualizer below deliberately has two different modes so it does not repeat the binary morphology or nonlinear-filter visualizers.

Gray-Scale Morphology

Edit a gray-scale image and inspect dilation, erosion, opening, closing, morphological gradient, and top-hats.

The visualizer uses a symmetric flat cross or square structuring element and shows the neighborhood used at the selected pixel.

Threshold Stack

Edit a 1-D image on \(Q=\{0,1,2,3\}\).

See all threshold sets, apply a three-point majority Boolean filter to each layer, and reconstruct the gray-scale output.

15. Summary

Concept Main Idea
Gray-Scale Function \(f:D\rightarrow Q\)
Meet / Join Pointwise minimum and maximum
Umbra Set of spatial locations and gray-level coordinates at or below \(f\)
Threshold Set \( T_t(f) = \{p\mid f(p)\ge t\} \)
Flat SE \(b(u,v)=0\) on its support
Non-Flat SE \(b:D_b\rightarrow\mathbb{R}\) assigns a height to each support location
Flat Dilation Maximum over the active SE support
Flat Erosion Minimum over the active SE support
Opening / Closing Gray-scale extensions of the binary compositions
Threshold Decomposition Represent a gray-scale image as nested binary layers
Stack Filter Apply the same positive Boolean function to every threshold layer and reconstruct the gray-scale result

Operation
Symmetric Flat Structuring Element
Paint Gray Level
Input f
Choose a paint value, then click a pixel to edit and inspect it.
Output
Click an output pixel to inspect the same spatial location.
Selected Pixel
(3, 3)
SE Support
Input Neighborhood
Boundary handling in this interactive example: replicate the nearest image value.
Calculation
Gray Scale
Q = {0, 1, 2, 3}
Click a source value to cycle 0 → 1 → 2 → 3 → 0. Samples outside the displayed sequence are 0.
Highlight Threshold
Every threshold layer is always calculated. This control only highlights one input/output threshold pair.
Input x(k)
T1(x)
T2(x)
T3(x)
B[T1]
B[T2]
B[T3]
Output y(k)
At every threshold, B(a,b,c) = ab ∨ ac ∨ bc. Reconstruct with y(k) = Y1(k) + Y2(k) + Y3(k).
Ready.

Published inDigital Image Processing

Be First to Comment

Leave a Reply

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