Morphological Image Processing
Morphological Image Processing
Image Processing
2
Introduction
⚫ Morphology: a branch of biology that deals with the form and
structure of animals and plants
⚫ It is used to extract image components that are useful in the
representation and description of region shape, such as
⚫ boundaries extraction
⚫ skeletons
⚫ convex hull
⚫ morphological filtering
⚫ thinning
⚫ pruning
3
Basic Set Theory
4
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Reflection and Translation
Bˆ = {w | w −b, for b B}
( A) z = {c | c a + z, for a A}
5
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Example
6
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Structuring element (SE)
7
Examples: Structuring Elements (1)
origin
8
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Examples: Structuring Elements (contd.)
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.
9
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Erosion
⚫ Does the structuring element fit the set?
⚫ Erosion of a set A by structuring element B: all z in A such that B is in A
when origin of B is z
⚫ Portion of A where B is contained in A
A − B = {z|(B)z A}
A − B = {z|(B) z A = } C
Original Image A
1 1 1
1 1 1
1 1 1
11
Structuring Element B
Example (contd.)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0
0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0
0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0
0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0
0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1
1 1 1
1 1 1
12
Structuring Element B
Example (contd.)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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1 1 1 1 1 0
0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1
1 1 1
1 1 1
16
Structuring Element B
Example (contd.)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0
0 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 1 0
1 1 1 1 1 1
1 1 1 0 1 0
17
Structuring Element B Try with this SE
Example of
Erosion
18
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Example of
Erosion (contd.)
19
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Dilation
A B = {z|( Bˆ )z A Φ}
⚫ grow the object
20
Example
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0
0 0 1 0 0 1 0 0
0 0 1 1 1 1 0 0
ˆ ) A Φ}
What is A B ?= {z|( B
0 0 1 1 1 1 0 0 z
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Original Image A
1 1 1
1 1 1
1 1 1
21
Structuring Element B
Example (contd.)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1
1 1 1
1 1 1
22
Structuring Element B
Example (contd.)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1
1 1 1
1 1 1
23
Structuring Element B
Example (contd.)
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 1 0
1 1 1 1 1 1
1 1 1 0 1 0
25
Structuring Element B Try with this SE
Examples of Dilation
26
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Examples of Dilation (contd.)
27
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Erosion : eliminating irrelevant detail
29
Combining erosion and dilation
⚫ WANTED:
⚫ remove structures / fill holes
⚫ without affecting remaining parts
⚫ SOLUTION:
⚫ combine erosion and dilation
⚫ (using same SE)
30
Duality
⚫ Erosion and dilation are duals of each other with respect to
set complementation and reflection.
and
31
Duality (contd.)
⚫ Starting with the definition of erosion, it follows that
⚫ But the complement of the set of z’s that satisfy is the set of z’s
such that . Therefore,
32
Opening
Erosion followed by dilation, denoted ∘
A B = ( A − B) B
⚫ eliminates protrusions (a thing that sticks out from a place or
surface)
⚫ breaks necks
⚫ smoothes contour
33
Image adapted from https://www.americansouthwest.net/utah/goblin_valley/goblins5_l.html
Opening
A B = ( A − B) B
A B = {( B) z | ( B) z A} 34
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Closing
Dilation followed by erosion, denoted •
A • B = ( A B) − B
⚫ smooth contour
⚫ fuse narrow breaks and long thin gulfs
⚫ eliminate small holes
⚫ fill gaps in the contour
35
Closing
A • B = ( A B) − B
36
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
37
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Properties
Opening
(i) AB is a subset (subimage) of A
(ii) If C is a subset of D, then C B is a subset of D B
(iii) (A B) B = A B
Closing
(i) A is a subset (subimage) of A • B
(ii) If C is a subset of D, then C • B is a subset of D • B
(iii) (A • B) • B = A • B
and
40
Hit-or-Miss Transformation ⊛ (HMT)
B = ( B1 , B2 )
B1 : object
B2 : background
A B = ( A − B1 ) ( Ac − B2 )
42
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Boundary Extraction
43
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Boundary Extraction
( A) = A − ( A − B) 44
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Region Filling/Hole Filling
A hole may be defined as a background region surrounded by a connected border
of foreground pixels.
45
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Region Filling/Hole Filling (contd.)
⚫ 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.
⚫ Algorithm
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. X k = ( X k −1 B) A k = 1,2,3,...
c
46
Region Filling/Hole Filling (contd.)
X k = ( X k −1 B) A k = 1,2,3,...
c
47
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Extraction of connected components
48
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Extraction of connected components
(contd.)
Let A be a set containing one or more connected components, and
form an array X0 (of the same size as the array containing A) whose
elements are 0s, except at each location known to correspond to a
point in each connected component in A, which is set to 1.
X k = ( X k −1 + B ) A
B : structuring element
until X k = X k -1 49
Extraction of connected components
(contd.)
X k = ( X k −1 + B ) A 50
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Convex Hull
51
Convex Hull (contd.)
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
52
53
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Thinning
• Thinning of a set A of foreground pixels by a structuring element B,
denoted , can be defined in terms of the hit-or-miss transform.
55
56
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
57
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Skeletons
• Skeleton S(A):
• If z is a point of S(A), and (D)z is the largest disk centered at z
and contained in A, one cannot find a larger disk (not necessarily
centered at z) containing (D)z and simultaneously included in A. A
disk (D)z satisfying these conditions is called a maximum disk.
• If (D)z is a maximum disk, it touches the boundary of A at two or
more different places.
58
Skeletons
(contd.)
59
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Skeletons (contd.)
• The skeleton of A can be expressed in terms of erosions and
openings.
• with
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Pruning
• Pruning methods are an essential complement to thinning and
skeletonizing algorithms.
• These procedures tend to leave spurs (“parasitic” components)
that need to be “cleaned up” by postprocessing.
• A common approach in the automated recognition of hand-printed
characters is to analyze the shape of the skeleton of a character.
These skeletons often contain spurs, caused during erosion by
noise and non-uniformities in the character strokes.
• A morphological technique for handling this problem can be seen,
starting with the assumption that the length of a parasitic
component does not exceed a specified number of pixels. 63
Pruning (contd.)
• Figure shows the skeleton of a hand-printed letter “a.”
• The spur on the leftmost part of the character exemplifies what we
are interested in removing.
• The solution is based on suppressing a spur branch by
successively eliminating its end point.
• Of course, this also shortens (or eliminates)
other branches in the character but, in the
absence of other structural information, the
assumption in this example is that any branch
with three or less pixels is to be eliminated.
64
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
Pruning (contd.)
• Thinning of a set A, with a sequence of structuring elements
designed to detect only end points, achieves the desired result.
That is, let
65
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
66
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.
67
Adapted from Gonzalez, Rafael C. Digital image processing. Pearson education India, 2009.