Professional Documents
Culture Documents
08 Morphological Orperations - PDF
08 Morphological Orperations - PDF
Technology (NUST)
School of Electrical Engineering and Computer Science
(SEECS)
1
Khawar Khurshid
Morphological Operations
2
Khawar Khurshid
Introduction
foreground:
background
I(p) c
I(p) 0
3
Khawar Khurshid
Quick Example
4
Khawar Khurshid
Structuring Elements
Example Structuring
Elements
Structuring Elements
Converted to Rectangular
Arrays
5
Khawar Khurshid
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
6
Khawar Khurshid
Fundamental Morphology
1 if s fits f
g ( x, y )
0 otherwise
8
Khawar Khurshid
Erosion - Steps
For each foreground pixel (which we will call the input pixel)
Superimpose the structuring element on top of the input image so that
the origin of the structuring element coincides with the input pixel
position.
9
Khawar Khurshid
Erosion - Example
Structuring Element
10
Khawar Khurshid
Erosion - Example
Original Image Processed Image
Structuring Element
11
Khawar Khurshid
Erosion - Basics
Effects
12
Khawar Khurshid
Erosion - Basics
14
Khawar Khurshid
Erosion - Results
After erosion
Original
with a disc of
image
radius 10
15
Khawar Khurshid
Erosion - Results
16
Khawar Khurshid
Erosion – Exercise 1
+ =
17
Khawar Khurshid
Erosion – Exercise 2
18
Khawar Khurshid
Erosion – Exercise 2 Results
19
Khawar Khurshid
Dilation
1 if s hits f
g ( x, y )
0 otherwise
20
Khawar Khurshid
Dilation - Steps
For each background pixel (which we will call the input pixel)
Superimpose the structuring element on top of the input image so
that the origin of the structuring element coincides with the input pixel
position.
21
Khawar Khurshid
Dilation - Example
Original Image Processed Image
Structuring Element
22 22
Khawar Khurshid
Dilation - Example
Original Image Processed Image With Dilated Pixels
Structuring Element
23 23
Khawar Khurshid
Dilation - Basics
Effects
Expands the size of foreground (1-valued) objects.
Smoothes object boundaries.
Closes holes and gaps.
24
Khawar Khurshid
Dilation - Basics
25
Khawar Khurshid
Dilation – Example 1
26
Khawar Khurshid
Dilation – Example 2
27
Khawar Khurshid
Dilation – Example 3
28
Khawar Khurshid
Erosion & Dilation - Duality
Dilation and erosion are duals of each other:
29
Khawar Khurshid
Compound Operations
- Opening
- Closing
30
Khawar Khurshid
Opening
31
Khawar Khurshid
Opening
f s(f s) s
32
Khawar Khurshid
Opening
Original
Image
Opening
33
Khawar Khurshid
Opening
Original Image Processed Image
Structuring Element
34
Khawar Khurshid
Closing
f s ( f s) s
35
Khawar Khurshid
Closing
Original
Image
Closing
36
Khawar Khurshid
Closing
Original Image Processed Image
Structuring Element
37
Khawar Khurshid
Closing
38
Khawar Khurshid
Morphological Operations
39
Khawar Khurshid
Hit-or-Miss Transform
Basic Idea:
40
Khawar Khurshid
Hit-or-Miss Transform
Idea
Watch
Suppose out:a We
we have binaryactually
image thatlook forcertain
contains ‘fit’ but we
shapes
(circles, squares, lines, etc,….) called image A
will be calling them ‘hit’ when talking about
hit-or-miss
We use transform
another image or matrix to search image A for a
particular pattern of bits. We will call this pattern “shape B”
41
Khawar Khurshid
Hit-or-Miss Transform
Structuring Element
1 0 1 0
1 1 1 1 1 1
1 0 1 0
42
Khawar Khurshid
Hit-or-Miss Transform
43
Khawar Khurshid
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
Erosion Recap: Slide the SE on the image and look for the ‘fits’
44
Khawar Khurshid
Hit-or-Miss Transform
0 0 0 0 0 0 0 0 ‘Fit’ 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
45
Khawar Khurshid
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
‘Fit’ encountered
46
Khawar Khurshid
Hit-or-Miss Transform
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 1 0 0 1 1 1 1 * 0
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
47
Khawar Khurshid
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
48
Khawar Khurshid
Hit-or-Miss Transform
How do we search?
Take an image of size 100x100 (B)
representing a white square
Shape to pattern
50
Khawar Khurshid
Morphological Operations
Algorithms
51
Khawar Khurshid
Morphological Algorithms
For example:
- Morphological gradients
- Region filling
- Extraction of connected components
- Convex Hull
52
Khawar Khurshid
Morphological Gradients
53
Khawar Khurshid
Boundary Extraction
B(A) = A – A B
54
Khawar Khurshid
Boundary Extraction
55
Khawar Khurshid
Region Filling
56
Khawar Khurshid
Region Filling
If all boundary points are labeled 1 and non boundary points are
labeled 0, the following procedure fills the region:
Inside the boundary
57
Khawar Khurshid
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
58
Khawar Khurshid
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 B 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
( X 0 B)
X0
X k ( X k B) Ac
k 1, 2,3,
59
Khawar Khurshid
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
X 1 ( X 0 B)
Ac X 1 ( X 0 B) Ac
X k ( X k B) Ac
k 1, 2,3,
60
Khawar Khurshid
Region Filling
X k ( X k B) Ac
k 1, 2,3,
NOTE:
The intersection of dilation
and the complement of A
limits the result to inside
the region of interest
61
Khawar Khurshid
Region Filling
62
Khawar Khurshid
Extraction of Connected Components
X k ( X k 1 B) A k 1, 2,3,
B is a suitable structuring element
Algorithm converges if Xk = Xk-1
The component Y is given as Y = Xk
63
Khawar Khurshid
Extraction of Connected Components
64
Khawar Khurshid
End
Morphological
Operations
65
Khawar Khurshid