Professional Documents
Culture Documents
Lecture # 11
©Dr J.Iqbal
Structuring Elements
Structuring Element
B
Fit: All of the pixels in the
structuring element cover on
pixels in the image
A
C Hit: Any one pixel in the
structuring element covers an
on pixel in the image
©Dr J.Iqbal
Hit-or-Miss Transform
A tool for shape detection
Basic Idea:
Suppose we have a binary image that contains certain
shapes (circles, squares, lines, etc,….) called image A.
We use another image or matrix to search image A for a
particular pattern of bits. We will call this pattern “shape B”.
We then search image A for shape B.
©Dr J.Iqbal
Hit-or-Miss Transform
Structuring Element
1 0 1 0
1 1 1 1 1 1
1 0 1 0
©Dr J.Iqbal
Hit-or-Miss Transform
Extended Structuring Element
1 1 1
× 0 ×
× 0 ×
©Dr J.Iqbal
Hit-or-Miss Transform
Extended Structuring Element: Example
0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 0
0 0 0 0 1 1 1 0 1 1 1
×
0 ×
0 1 0 0 1 1 1 1 ×
0 ×
0 1 1 1 1 1 0 1
0 0 1 1 1 1 0 1
0 0 0 0 0 0 0 0 ‘Hit’ encountered
0 0 1 1 1 0 0 0
0 0 0 0 1 1 1 0 1 1 1
×
0 ×
0 1 0 0 1 1 1 1 ×
0 ×
0 1 1 1 1 1 0 1
0 0 1 1 1 1 0 1
©Dr J.Iqbal
Hit-or-Miss Transform
0 0 0 0 0 0 0 0
0 0 1 1 1 0 0 0
0 0 0 0 1 1 1 0 1 1 1
×
0 ×
0 1 0 0 1 1 1 1 ×
0 ×
0 1 1 1 1 1 0 1
0 0 1 1 1 1 0 1
‘Hit’ encountered
©Dr J.Iqbal
Hit-or-Miss Transform
Extended Structuring Element: Example
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 0 0 0 0 0
0 0 0 0 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0
×
0 ×
=
0 1 0 0 1 1 1 1 ×
0 × 0 0 0 0 0 0 0 0
0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0
0 0 1 1 1 1 0 1 0 0 0 0 0 0 0 0
©Dr J.Iqbal
Hit-or-Miss Transform
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0
Output: The center of the pattern is 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 and rest everything is 0
0 0 0 0 0 0 0 0
©Dr J.Iqbal
Hit-or-Miss Transform
Example: Search a 100x100 pixel square in an image
How do we search?
Take an image of size 100x100 (B)
representing a white square
We search the pattern in the input
image (A)
If found, we have a “fit”. We mark
the center of the “Hit” with a
white pixel
In the above example, there would be
only 1 fit
©Dr J.Iqbal
Hit-or-Miss Transform
Try to find Shape B in Image A
Do you find any problem with this?
If we search for a 100x100 pixel square in an image, we
will have a positive response for all squares greater
than 100x100 as well
Solution ?
Shape B
©Dr J.Iqbal
Hit-or-Miss Transformation
A basic tool for shape detection
Consider the example shown in figure:
Objective is to find X in the space A
Background of X is given by (W-X)
The set of locations for which X
exactly fits inside A is the intersection
of erosion of A by X and the erosion
of Ac by (W-X), i.e.,
𝐴 * 𝐵 = (𝐴 𝑋) ∩ 𝐴𝑐 (𝑊 − 𝑋)
Black = 1, White =0
©Dr J.Iqbal
Morphological Boundary Extraction
The boundary of set A denoted by 𝛽(𝐴) is obtained by first eroding
A by a suitable structuring element B and then taking the difference
between A and its erosion, i.e.
𝛽(𝑎) = 𝐴 − (𝐴 𝐵).
Black = 1, White =0
©Dr J.Iqbal
Morphological Boundary Extraction (example)
𝛽(𝑎) = 𝐴 − (𝐴 𝐵) ⇒ 9.5 − 1
Black = 0, White =1
©Dr J.Iqbal
Region Filling
Given a pixel inside a boundary, region filling attempts to fill that
boundary with object pixels (1s)
©Dr J.Iqbal
Region Filling
Let A is set containing a subset whose elements are 8-connected
boundary points of a region.
If all boundary points are labeled 1 and non boundary points are
labeled 0, the following procedure fills the region:
– Start from a known point p and taking X0 = p,
– Then taking the next values of Xk as:
𝑋𝑘 = (𝑋𝑘−1 ⊕ 𝐵) ∩ 𝐴𝑐 , 𝑘 = 1,2,3, . . .
B is a suitable structuring element
– Terminate iterations if Xk = Xk-1
– The set union of Xk and A contains the filled set and its
boundaries.
Example: Consider the figure (next page)
©Dr J.Iqbal
Region Filling
0 0 0 0 0 0 0 1 1 1 1 1 1 1
0 1 1 1 1 1 0 1 0 0 0 0 0 1
0 1 0 0 0 1 0 1 0 1 1 1 0 1 0 1 0
0 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1
0 1 0
0 1 0 0 0 1 0 1 0 1 1 1 0 1
0 1 1 1 1 1 0 1 0 0 0 0 0 1 B
0 0 0 0 0 0 0 1 1 1 1 1 1 1
A Ac
©Dr J.Iqbal
Region Filling
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 1 0 0 0 0 0 1 0 0 1 1 1 0 0 0
0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 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 0 0
𝑋0 (𝑋0 ⊕ 𝐵)
𝑋𝑘 = (𝑋𝑘−1 ⊕ 𝐵) ∩ 𝐴𝑐
𝑘 = 1,2,3, ⋯
©Dr J.Iqbal
Region Filling
0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 1 0 1 1 1 0 1 0 0 1 1 0 0 0
0 0 1 0 0 0 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0 1 1 1 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0
𝐴𝑐 𝑋1 = (𝑋0 ⊕ 𝐵) ∩ 𝐴𝑐
𝑋1 = (𝑋0 ⊕ 𝐵)
𝑋𝑘 = (𝑋𝑘−1 ⊕ 𝐵) ∩ 𝐴𝑐
𝑘 = 1,2,3, ⋯
©Dr J.Iqbal
Region Filling
The set union of Xk and A contains the filled set and its boundaries.
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 1 1 1 0 0 0 0 0 0 0 0
0 1 0 0 0 1 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 0 0 1 1 1 0 0
0 1 0 0 0 1 0 0 0 1 1 1 0 0
0 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 0 0 0 0
𝐴 𝑋𝑘
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
©Dr J.Iqbal
Region Filling (Example)
𝑋𝑘 = (𝑋𝑘−1 ⊕ 𝐵) ∩ 𝐴𝑐 , 𝑘 = 1,2,3, . . .
NOTE:
The
intersection of
dilation and the
complement of
A limits the
result to inside
the region of
interest
Black = 1, White =0
©Dr J.Iqbal
Region Filling
©Dr J.Iqbal
Convex Hull (Binary Images)
©Dr J.Iqbal
Convex Hull (Binary Images)
Convex Hull
©Dr J.Iqbal
Convex Hull (Binary Images)
Convex set: A set A is said to be convex if any straight line
segment joining two points of A lies within A.
Convex Hull: Convex hull H of a set S is the smallest convex
set containing S.
To find the Convex Hull C(A) of a set A the following simple
morphological algorithm can be used:
– Let Bi, where i = 1, 2, 3, 4, represent four structuring elements
– Implement: 𝑋𝑘𝑖 = (𝑋𝑘−1 𝑖 𝑖
* 𝐵𝑖 ) ∪ 𝑋𝑘−1 , 𝑖 = 1,2,3,4 𝑘 = 1,2,3, . . .
– Starting with 𝑋0𝑖 = 𝐴.
– Repeat 2nd step until convergence, i.e.4 𝐷𝑖 = 𝑋𝑐𝑜𝑛𝑣𝑖
→ 𝑋𝑘𝑖 = 𝑋𝑘−1𝑖
.
– Convex Hull of A is given as: 𝐶(𝐴) = 𝐷𝑖
𝑖=1
©Dr J.Iqbal
Convex Hull (4 x Structuring Elements)
Black = 1, White =0
©Dr J.Iqbal
Convex Hull (Binary Images)
Pick the first SE and scan whole image for HIT
Replace center with one in case of HIT
Keep iterating until convergence
Select next SE and repeat above three steps
Start At:
𝑋01 = 𝐴
Find:
𝑋11 = (𝑋01 1 1
* 𝐵 ) ∪ 𝑋0
𝑋21 = (𝑋11 * 𝐵1 ) ∪ 𝑋11 i=SA number
⋮ K= no of iteration
𝐴
Call it D1
𝑋𝑘𝑖 = (𝑋𝑘−1
𝑖 𝑖 𝑖
* 𝐵 ) ∪ 𝑋𝑘−1 , 𝑖 = 1,2,3,4 𝑘 = 1,2,3, . . .
D2 D3 D4
©Dr J.Iqbal
Convex Hull (Binary Images)
𝐶(𝐴) = 𝐷𝑖
𝑖=1
©Dr J.Iqbal
Convex Hull (Example)
©Dr J.Iqbal
Thinning (Binary Images)
Thinning: Thinning of a set A by the structuring element B can be
defined in terms of hit-or-miss transform as:
𝐴 ⊗ 𝐵 = 𝐴 − (𝐴 * 𝐵) = 𝐴 ∩ (𝐴 * 𝐵)𝑐
©Dr J.Iqbal
• Thin A by ONE pass with
B1, then thin the result
with one pass of B2 and
so on
• No Iteration with same
SE as we did in convex
Hull
• The entire process is
repeated (iterated) (B1 to
Bn ) until no further
changes occur.
• SE are rotated version
• Zero padded boundry
𝐴 ⊗ 𝐵 = 𝐴 − (𝐴 * 𝐵)
• Grey = 1
• White = 0
• Mythinmain.m
©Dr J.Iqbal
Thinning (Binary Images)
©Dr J.Iqbal
Thinning (Binary Images)
©Dr J.Iqbal
Thickening (Binary Images)
©Dr J.Iqbal
Thickening (example)
To thicken a set A,
• C=Ac
• thin C
• Cc (complement C)
• Remove
disconnected points
©Dr J.Iqbal
Thickening (example)
• Mythickmain.m
©Dr J.Iqbal
Thickening (example)
Error in the book (Errata)
©Dr J.Iqbal
Skeletons (Binary Images)
To understand the skeleton consider the following figure:
©Dr J.Iqbal
Skeletons (Binary Images)
In terms of morphological processes (erosion and openings) the
skeletons can be computed as the union of skeleton subsets:
𝐾
𝑆(𝐴) = 𝑆𝑘 (𝐴)
𝑘=0
𝐴 ∘ 𝐵 = (𝐴 𝐵) ⊕ 𝐵.
(opening)
𝐾
𝑆(𝐴) = 𝑆𝑘 (𝐴)
𝑘=0
©Dr J.Iqbal
Pruning
a. Thinning and skeletonizing tend to leave parasitic components.
b. Pruning methods are essential complement to thinning and
skeletonizing procedures
X 2 X1 * Bk
8
(2) Hit or Miss
k 1
X 4 X1 X 3 (4) Union
©Dr J.Iqbal
Pruning:
Example (1) Thinning
𝑋1 = 𝐴 ⊗ {𝐵}
𝐴 ⊗ 𝐵 = 𝐴 − (𝐴 * 𝐵) = 𝐴 ∩ (𝐴 * 𝐵)𝑐
{𝐵} = {𝐵1 , 𝐵2 , 𝐵3 , . . . . . . , 𝐵𝑛 }
©Dr J.Iqbal
Pruning:
Example
X 2 X1 * Bk
8
k 1
𝑋1 = 𝐴 ⊗ {𝐵} (1)Thinning
(DONE)
𝐴 ⊗ 𝐵 = 𝐴 − (𝐴 * 𝐵) = 𝐴 ∩ (𝐴 * 𝐵)𝑐
{𝐵} = {𝐵1 , 𝐵2 , 𝐵3 , . . . . . . , 𝐵𝑛 }
©Dr J.Iqbal
Pruning:
Example
𝑋3 = 𝑋 2⊕
(2) Hit𝐻or∩ 𝐴 (3) Dilation (3 times) &
𝐻: 3 × 3 structuring
Miss (DONE) element Intersection after each
step
X 2 X1 * Bk
8
k 1
©Dr J.Iqbal
Pruning:
Example
©Dr J.Iqbal
Morphological Reconstruction
It involves two images:-
a. One image contains the starting points for the
transformation (The image is called marker)
b. Another image (mask) constrains the transformation
c. Processing is based on connectivity that is defined by
the structuring element
d. Processing repeats until stabilization
©Dr J.Iqbal
Geodesic Dilation
Let F denote the marker image and G the mask image,
F ⊆ G. The geodesic dilation of size 1 of the marker image
(1)
with respect to the mask, denoted by DG (F), is defined as
(1)
DG (F) = F ⊕ B ∩ G
©Dr J.Iqbal
Geodesic Dilation
(1)
DG (F) = F ⊕ B ∩ G
©Dr J.Iqbal
Geodesic Erosion
Let F denote the marker image and G the mask image.
The geodesic erosion of size 1 of the marker image with
(1)
respect to the mask, denoted by EG (F), is defined as
(1)
EG (F) = F−B ∪G
©Dr J.Iqbal
Geodesic Erosion
(𝟏)
𝐄𝐆 (𝐅) = 𝐅−𝐁 ∪𝐆
©Dr J.Iqbal
Reconstruction by Dilation
©Dr J.Iqbal
Reconstruction by Dilation
©Dr J.Iqbal
Reconstruction
Morphological reconstruction byby Erosion
erosion of a mask image
GMorphological
from a markerreconstruction
image F, denoted RG (F), is of
E
by erosion defined
a maskasimage
the geodesic
G from erosion
a marker of FF,with
image respect
denoted to G,
REG (F), is iterated until
defined as
stability is achieved;
the geodesic erosionthat
of F iwith
s, respect to G, iterated until
stability is achieved; that is,
R
E G
E
(F) = EG (F)
(k)
(k)
R G (F) = EG (F)
©Dr J.Iqbal
Opening by Reconstruction
The opening by reconstruction of size n of an image F is
The opening by reconstruction of size n of an image F is
defined as the reconstruction by dilation of F from the
defined as the reconstruction by dilation of F from the
erosion
erosionofofsize
sizennofofF;F;that
thatisis
(𝑛)(n)
𝑂𝑅OR(𝐹) D𝐷
(F) = RF𝐹
= 𝑅 F𝐹-nB
− 𝑛𝐵
©Dr J.Iqbal
Opening by Reconstruction
Mask (G) Marker (F)
4x4 SE
©Dr J.Iqbal