Morphological Image Processing DIP-2023
Morphological Image Processing DIP-2023
PROCESSING
DIP-2023
WHAT IS MORPHOLOGICAL IMAGE PROCESSING
Typically, objects are defined as sets of foreground pixels. Structuring elements can be
specified in terms of both foreground and background pixels.
In addition, structuring elements sometimes contain so-called “don’t care” elements, denoted by 𝑋,
signifying that the value of that particular element in the SE does not matter.
In this sense, the value can be ignored, or it can be made to fit a desired value in the evaluation of
an expression; for example, it might take on the value of a pixel in an image in applications in
which value matching is the objective.
Z2 and Z3
► set in mathematic morphology represent objects in an image
▪ binary image (0 = white, 1 = black) : the element of the set is the coordinates (x,y) of pixel
belong to the object Z2
► gray-scaled image : the element of the set is the coordinates (x,y) of pixel belong to the
object and the gray levels Z3
11/25/2024 5
Basic Set Theory
11/25/2024 6
Example of object background etc.
The concept of set reflection and translation are used extensively in
morphology in connection with structuring elements. The reflection of
a set (structuring element) B about its origin, denoted by 𝐵
(1) form a new image, of the same size as I, consisting only of background values initially,
(2) translate (slide) B over image I,
(3) at each increment of translation, if B is completely contained in A, mark the location of the origin of B as a foreground
pixel in the new image; otherwise, leave it as a background point.
We begin the discussion of morphology by studying two
An alternate definition
Preliminaries (1)
► Reflection
► Translation
11/25/2024 19
Example: Reflection and Translation
11/25/2024 20
Preliminaries (2)
11/25/2024 21
Examples: Structuring Elements (1)
origin
11/25/2024 22
Examples: Structuring Elements (2)
Accommodate the
entire structuring
elements when its Origin of B visits
origin is on the every element of A
border of the
original set A
At each location of
the origin of B, if B
is completely
contained in A,
then the location is
a member of the
new set, otherwise
it is not a member
of the new set.
11/25/2024 23
Structuring Elements, Hits & Fits
B Structuring Element
A B = z | ( B) Z A =
c
11/25/2024 25
Example
of
Erosion
11/25/2024 26
Erosion Example
Original Image Processed Image With Eroded Pixels
11/25/2024 29
Erosion Example
11/25/2024 30
After erosion
Original
with a disc of
image
radius 10
11/25/2024 31
Dilation
2
With A and B as sets in Z , the dilation of A by B,
denoted A B, is defined as
()
A B= z | B A
z
The set of all displacements z, the translated B and A
overlap by at least one element.
()
A B = z | B A A
z
11/25/2024 32
Examples of Dilation
11/25/2024 33
Dilation Example
Original Image Processed Image
11/25/2024 36
Dilation Example
11/25/2024 37
11/25/2024 38
Duality
11/25/2024 39
11/25/2024
Dilation 40
Duality
► Erosion and dilation are duals of each other with respect to set complementation
and reflection
( A − B) = A B
c c
and
( A B) = Ac − B
c
11/25/2024 41
Duality
► Erosion and dilation are duals of each other with respect to set complementation
and reflection
( A − B) = z | ( B ) Z A
c c
= z | ( B ) Z A =
c c
= z | ( B ) Z Ac
= Ac B
11/25/2024 42
Duality
► Erosion and dilation are duals of each other with respect to set complementation
and reflection
( ) A
c
( A B) = z| B
c
= z | ( B ) A =
c
Z
= Ac − B
11/25/2024 43
11/25/2024 44
Opening and Closing
11/25/2024 45
Opening and Closing
11/25/2024 46
Opening
11/25/2024 47
Opening Example
Original
Image
Image
After
Opening
11/25/2024 48
Closing Example
Original
Image
Image
After
Closing
11/25/2024 49
Useful: Opening & Closing
11/25/2024 50
11/25/2024 53
Duality of Opening and Closing
► Opening and closing are duals of each other with respect to set
complementation and reflection
ˆ
( A • B) = ( A B) c c
11/25/2024 54
The Properties of Opening and Closing
► Properties of Opening
(a) A B is a subset (subimage) of A
(b) if C is a subset of D, then C B is a subset of D B
(c) ( A B) B = A B
► Properties of Closing
B = ( B1 , B2 )
B1 : object
B2 : background
A B = ( A − B1 ) ( Ac − B2 )
11/25/2024 57
11/25/2024 58
11/25/2024 59
11/25/2024 60
11/25/2024 61
11/25/2024 62
11/25/2024 63
11/25/2024 64
11/25/2024 65
Some Basic Morphological Algorithms (1)
► Boundary Extraction
The boundary of a set A, can be obtained by first eroding A by B and then
performing the set difference between A and its erosion.
( A) = A − ( A − B )
11/25/2024 66
Example 1
11/25/2024 67
Example 2
11/25/2024 68
Some Basic Morphological Algorithms (2)
► Hole Filling
A hole may be defined as a background region surrounded by a connected
border of foreground pixels.
Let A denote a set whose elements are 8-connected boundaries, each boundary
enclosing a background region (i.e., a hole). Given a point in each hole, the
objective is to fill all the holes with 1s.
11/25/2024 69
Some Basic Morphological Algorithms (2)
► Hole Filling
1. Forming an array X0 of 0s (the same size as the array containing A), except
the locations in X0 corresponding to the given point in each hole, which we set
to 1.
2. Xk = (Xk-1 + B) Ac
k=1,2,3,…
11/25/2024 70
Example
11/25/2024 71
11/25/2024 72
Some Basic Morphological Algorithms (3)
11/25/2024 73
Some Basic Morphological Algorithms (3)
X k = ( X k −1 + B ) A
B : structuring element
until X k = X k -1
11/25/2024 74
11/25/2024 75
11/25/2024 76
Some Basic Morphological Algorithms (4)
► Convex Hull
A set A is said to be convex if the straight line segment joining any two points
in A lies entirely within A.
The convex hull H or of an arbitrary set S is the smallest convex set containing
S.
11/25/2024 77
Some Basic Morphological Algorithms (4)
► Convex Hull
Let B i , i = 1, 2, 3, 4, represent the four structuring elements.
The procedure consists of implementing the equation:
X ki = ( X k −1 * B i ) A
i = 1, 2, 3, 4 and k = 1, 2, 3,...
with X 0i = A.
When the procedure converges, or X ki = X ki −1 , let D i = X ki ,
the convex hull of A is
4
C ( A) = D i
i =1
11/25/2024 78
11/25/2024 79
11/25/2024 80
Some Basic Morphological Algorithms (5)
► Thinning
The thinning of a set A by a structuring element B, defined
A B = A − ( A * B)
= A ( A * B) c
11/25/2024 81
Some Basic Morphological Algorithms (5)
B = B1
, B 2
, B 3
,..., B n
where B i is a rotated version of B i -1
11/25/2024 82
11/25/2024 83
Some Basic Morphological Algorithms (6)
► Thickening:
11/25/2024 84
Some Basic Morphological Algorithms (6)
11/25/2024 85
Some Basic Morphological Algorithms (7)
► Skeletons
11/25/2024 86
Some Basic Morphological Algorithms (7)
11/25/2024 87
Some Basic Morphological Algorithms (7)
11/25/2024 91
11/25/2024 92
Some Basic Morphological Algorithms (8)
► Pruning
11/25/2024 93
Pruning:
Example
X 1 = A {B}
11/25/2024 94
Pruning:
Example
X 2 = ( X1 * Bk )
8
k =1
11/25/2024 95
Pruning:
Example
X3 = ( X2 H ) A
H : 3 3 structuring element
11/25/2024 96
Pruning:
Example
X 4 = X1 X 3
11/25/2024 97
Pruning:
Example
11/25/2024 98
Some Basic Morphological Algorithms (9)
► Morphological Reconstruction
11/25/2024 99
Morphological Reconstruction: Geodesic Dilation
RGD ( F ) = DG( k ) ( F )
RGE ( F ) = EG( k ) ( F )
( F − nB )
OR( n ) ( F ) = RFD
11/25/2024 107
11/25/2024 108
Filling Holes
1 − I ( x, y ) if ( x, y ) is on the border of I
F ( x, y ) =
0 otherwise
then
c
H =
R (F )
D
Ic
11/25/2024 109
SE : 3 3 1s.
11/25/2024 110
c
H =
R (F )
D
Ic
11/25/2024 111
Border Clearing
It can be used to screen images so that only complete objects
remain for further processing; it can be used as a singal that
partial objects are present in the field of view.
11/25/2024 112
11/25/2024 113
Summary (1)
11/25/2024 114
Summary (2)
11/25/2024 115
11/25/2024 116
11/25/2024 117
Gray-Scale Morphology
f ( x, y ) : gray-scale image
b( x, y ): structuring element
11/25/2024 118
Gray-Scale Morphology: Erosion and Dilation by Flat
Structuring
f − b ( x, y ) = min f ( x + s, y + t )
( s ,t )b
f b ( x, y ) = max f ( x − s, y − t )
( s ,t )b
11/25/2024 119
11/25/2024 120
Gray-Scale Morphology: Erosion and Dilation by Nonflat
Structuring
f − bN ( x, y ) = min f ( x + s, y + t ) − bN ( s, t )
( s ,t )b
f bN ( x, y ) = max f ( x − s, y − t ) + bN ( s, t )
( s ,t )b
11/25/2024 121
Duality: Erosion and Dilation
f −b ( x, y ) = f b ( x, y )
c c
where f c
= − f ( x, y ) and b = b( − x, − y )
f −b = f b
c c
( f b) = ( f − b)
c c
11/25/2024 122
Opening and Closing
f b = ( f − b) b
f • b = ( f b) − b
(f b) = f b=−f
c c
b
(f b) = f b=−f b
c c
11/25/2024 123
11/25/2024 124
Properties of Gray-scale Opening
(a) f bf
(b) if f1f 2 , then ( f1 b ) ( f2 b )
(c ) (f b) b = f b
11/25/2024 125
Properties of Gray-scale Closing
(a) f f b
(b) if f1f 2 , then ( f1 b ) ( f 2 b )
(c ) (f b) b = f b
11/25/2024 126
11/25/2024 127
Morphological Smoothing
► Opening suppresses bright details smaller than the specified SE, and closing
suppresses dark details.
► Opening and closing are used often in combination as morphological filters for
image smoothing and noise removal.
11/25/2024 128
Morphological Smoothing
11/25/2024 129
Morphological Gradient
g = ( f b) − ( f − b)
► The edges are enhanced and the contribution of the homogeneous areas are
suppressed, thus producing a “derivative-like” (gradient) effect.
11/25/2024 130
Morphological Gradient
11/25/2024 131
Top-hat and Bottom-hat Transformations
That ( f ) = f − ( f b)
► The bottom-hat transformation of a grayscale image f is defined as its closing
minus f:
Bhat ( f ) = ( f • b) − f
11/25/2024 132
Top-hat and Bottom-hat Transformations
11/25/2024 133
Example of Using Top-hat Transformation in Segmentation
11/25/2024 134
Granulometry
► Opening operations of a particular size should have the most effect on regions
of the input image that contain particles of similar size
► For each opening, the sum (surface area) of the pixel values in the opening is
computed
11/25/2024 135
Example
11/25/2024 136
11/25/2024 137
Textual Segmentation
11/25/2024 138
Textual Segmentation
11/25/2024 139
Gray-Scale Morphological Reconstruction (1)
► Let f and g denote the marker and mask image with the same size, respectively
and f ≤ g.
The geodesic dilation of size 1 of f with respect to g is defined as
Dg(1) ( f ) = ( f g ) g
where denotes the point-wise minimum operator.
The geodesic dilation of size n of f with respect to g is defined as
Dg( n ) ( f ) = Dg(1) D
g
( n −1)
( f )
with Dg ( f ) = f
(0)
11/25/2024 140
Gray-Scale Morphological Reconstruction (2)
Eg(1) ( f ) = ( f − g ) g
where denotes the point-wise maximum operator.
Eg( n ) ( f ) = Eg(1) E
g
( n −1)
( f )
with E g ( f ) = f
(0)
11/25/2024 141
Gray-Scale Morphological Reconstruction (3)
RgD ( f ) = Dg( k ) ( f
)
with k such that Dg( k ) ( f ) = Dg( k +1) ( f )
The morphological reconstruction by erosion of g by f is defined as
RgE ( f ) = E g( k ) ( f )
with k such that Eg( k ) ( f ) = Eg( k +1) ( f )
11/25/2024 142
Gray-Scale Morphological Reconstruction (4)
f f − nb
OR( n ) ( f ) = R D
The closing by reconstruction of size n of an image f is defined as the
reconstruction by erosion of f from the dilation of size n of f; that is,
CR( n ) ( f ) = R Ef f nb
11/25/2024 143
11/25/2024 144
Steps in the Example
1. Opening by reconstruction of the original image using a horizontal line of size 1x71 pixels in
the erosion operation
f f − nb
OR( n ) ( f ) = R D
f ' = f − OR( n ) ( f )
3. Opening by reconstruction of the f’ using a vertical line of size 11x1 pixels
f f '− nb '
f 1 = OR( n ) ( f ') = R D
4. Dilate f1 with a line SE of size 1x21, get f2.
11/25/2024 145
Steps in the Example
5. Calculate the minimum between the dilated image f2 and and f’, get f3.
RD = f 2 ( f 3)
(k )
f 2 ( f 3) D
with k such that D (f k2) ( f 3) = D (f k2+1) ( f 3)
11/25/2024 146