Dip 4
Dip 4
A B {w | w A OR w B}
A B {w | w A AND w B}
A B {w | w A, w B} A
Bc
Ac {w | w A}
9 Preliminaries (cont.)
The above operations assume that the
images containing the sets are binary and
involve only the pixel location.
Union and intersection are different when we
define set operations involving intensity
values:
A B z max(
a, b)| a A, The elements of the sets
are gray values on the
b B same location z.
A B z min(a, b)| a A,
b B
10
Preliminaries (cont.)
Set reflection: B̂ {w | w b, for b B}
Set translation by z: (B)z {c | c b z, for
b B}
11
Preliminaries (cont.)
Set reflection and translation are employed to
structuring elements (SE).
SE Are small sets or subimages used to
examine the image under study for
proper ties of
Note: gray colour
interest. represents a value of
The origin must be specified. one and white colour
Zeros are appended to SE to a zero value.
give them a rectangular form.
Logic Operations
16
Example
17
11
Preliminaries (cont.)
Set reflection and translation are employed to
structuring elements (SE).
SE Are small sets or subimages used to
examine the image under study for
proper ties of
Note: gray colour
interest. represents a value of
The origin must be specified. one and white colour
Zeros are appended to SE to a zero value.
give them a rectangular form.
12
Preliminaries (cont.)
The origin of the SE B visits every pixel in an image A.
It per forms an operation (generally non linear) between
its elements and the pixels under it.
It is then decided if the pixel will belong to the resulting
set or not based on the results of the operation.
Zero padding is necessary (like in convolution) to
ensure that all of the elements of A are processed.
13 Preliminaries (cont.)
For example, it marks the pixel under its center
as belonging to the result if B is completely
contained in A (A 2, B 2).
14 Morphological
Operations
• Some basic operations
– Erosion.
– Dilation.
– Opening.
– Closing.
• Applications
– Morphological filtering.
– The hit-or-miss transformation.
Structuring Element (SE)
▪ small set to probe the image under study.
for each SE, define origo
▪ shape and size must be adapted to geometric
prope ies for the objects
22
• Morphological operations apply a structuring element to
an input image, creating an output image of the same
size.
• In a morphological operation, the value of each pixel in
the output image is based on a comparison of the
corresponding pixel in the input image with its
neighbors.
15
Erosion
The erosion of a set A by a SE B is defined as
A B { z |(B) z A}
The result is the set of all points z such that B
translated by z is contained in A.
Equivalently:
A B {z |(B) z A } c
16
Erosion (cont.)
15x15 45x4
5
19
Erosion (cont.)
Erosion can split apar tjoined objects
Output Image 0
21-Jun-23 35
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0
21-Jun-23 36
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0
21-Jun-23 37
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0 0
21-Jun-23 38
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0 0 1
21-Jun-23 39
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0 0 1 0
21-Jun-23 40
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0 0 1 0 0
21-Jun-23 41
Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0 0 0 1 0 0 0
21-Jun-23 42
20
Dilation
The dilation of a set A by a SE B is defined as
A B {z |(B̂ ) z A }
The result is the set of all points z such that the
reflected B translated overlap with A at at least
one element.
Equivalently: A B {z |[(B̂ ) z A] A}
C. Nikou – Digital Image Processing
21
Dilation (cont.)
Output Image 1
21-Jun-23 52
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0
21-Jun-23 53
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0 1
21-Jun-23 54
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0 1 1
21-Jun-23 55
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0 1 1 1
21-Jun-23 56
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0 1 1 1 1
21-Jun-23 57
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0 1 1 1 1 1
21-Jun-23 58
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0 1 1 1 1 1 1
21-Jun-23 59
Erosion on Gray Value Images
• View gray value images as a stack of binary images!
62
Erosion on Gray Value Images
64
Dilation on Gray Value Images
66
Duality
Erosion and dilation are dual operations with
respect to set complementation and reflection:
( A B)c Ac B̂
Also,
( A B)c Ac B̂
The duality is useful when the SE is symmetric:
The erosion of an image is the dilation of its
background.
C. Nikou – Digital Image Processing
25 Compound
Operations
More interesting morphological operations
can be per formed by combining erosions
and dilations in order to reduce shrinking or
thickening.
The most widely used of these compound
operations are:
– Opening
– Closing
C. Nikou – Digital Image Processing
Opening
• Similar to Erosion
• Spot and noise removal
• Less destructive
• Erosion next dilation
• the same structuring element for both operations.
• Input:
• Binary Image
• Structuring Element, containing only 1s!
69
Opening
erosion followed by dilation, denoted ∘
Uses of Opening
• eliminates protrusions
• breaks necks
• smoothes contour
70
Opening
71
Opening
72
Opening
73
Opening
• Take the structuring element (SE) and slide it around inside each
foreground region.
• All pixels which can be covered by the SE with the SE being entirely
within the foreground region will be preserved.
• All foreground pixels which can not be reached by the structuring
element without lapping over the edge of the foreground object will be
eroded away!
• Opening is idempotent: Repeated application has no fu her
effects!
74
Opening
• Structuring element: 3x3 square
21-Jun-23 75
Opening Example
• Opening with a 11 pixel diameter disc
21-Jun-23 76
Opening Example
• 3x9 and 9x3 Structuring Element
3*9
9*3
21-Jun-23 77
Opening on Gray Value Images
• 5x5 square structuring element
21-Jun-23 78
Use Opening for Separating Blobs
• Use large structuring element that fits into the big blobs
• Structuring Element: 11 pixel disc
21-Jun-23 79
CLOSING
6/21/2023 80
Closing
• Similar to Dilation
• Removal of holes
• Tends to enlarge regions, shrink background
• Closing is defined as a Dilatation, followed by an Erosion using
the same structuring element for both operations.
• Dilation next erosion!
• Input:
• Binary Image
• Structuring Element, containing only 1s!
81
Closing
dilation followed by erosion, denoted •
• smooth contour
• fuse narrow breaks and long thin gulfs
• eliminate small holes
• fill gaps in the contour
82
Closing
83
Closing
84
Closing
85
Closing
• Take the structuring element (SE) and slide it around outside
each foreground region.
• All background pixels which can be covered by the SE with the SE being
entirely within the background region will be preserved.
• All background pixels which can not be reached by the structuring
element without lapping over the edge of the foreground object will be
turned into a foreground.
• Closing is idempotent: Repeated application has no fu her
effects!
21-Jun-23 86
Closing
• Structuring element: 3x3 square
21-Jun-23 87
Closing Example
• Closing operation with a 22 pixel disc
• Closes small holes in the foreground
21-Jun-23 88
Closing Example 1
1. Threshold
2. Closing with disc of size 20
21-Jun-23 91
Opening & Closing
• Opening is the dual of closing
• i.e. opening the foreground pixels with a pa icular structuring
element
• is equivalent to closing the background pixels with the same
element.
92
31 Opening and
Closing
Erosion: elements where the
disk can not fit are eliminated.
Opening: outward corners are
rounded.
Dilation: inward intrusions are
reduced in depth.
( A B )c c A ( A ∘B)c A B̂
c
B̂
C. Nikou – Digital Image Processing
Prope ies
Opening
(i) A°B 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
Note: repeated openings/closings has no effect! 95
Closing
Opening
34 Morphological Filtering
Example
The image contains noise:
•Light elements on dark
background.
•Dark elements on the light
components of the
fingerprint.
Objective: Eliminate noise while distor ting the image
as lit tle as possible.
We will apply an opening followed by closing.
C. Nikou – Digital Image Processing
Morphological Filtering Example
35
(cont.)
A A B
Background noise completely removed (noise
components smaller than the SE).
The size of the dark noise elements in the fingerprint
structure increased (inner
C. Nikou – Digital Image Processing
dark structures).
Morphological Filtering Example
36
(cont.)
A B ( A B) B A ∘B
The dilation reduced the size of the inner noise or
eliminated it completely.
However, new gaps were created by the opening
betweenC. Nikouthe– Digital
fingerprint
Image Processingridges.
Morphological Filtering Example
37
(cont.)
A ∘B A ∘B B
The dilation reduces the new gaps between the
ridges but it also thickens the ridges.
C. Nikou – Digital Image Processing
Morphological Filtering Example
38
(cont.)
A ∘B B [ A ∘B B] B ( A ∘B) B
The final erosion (resulting to a closing of the
opened image) makes the ridges thinner.
C. Nikou – Digital Image Processing
Morphological Filtering Example
39
(cont.)
A (A ∘B) B
The final result is clean of noise but some ridges were
not fully repaired.
We should impose conditions for maintaining the
connectivity
C. Nikou – (we willProcessing
Digital Image see a more advanced algorithm).
HIT and MISS
6/21/2023 104
Hit-or-Miss transformations
Hit-or-Miss transformations
Hit-and-miss Transform
• Used to look for pa icular pa erns of foreground and
background pixels
• Very simple object recognition
• All other morphological operations can be derived from it!!
• Input:
• Binary Image
• Structuring Element, containing 0s and 1s!!
21-Jun-23 107
Hit-and-miss Transform
• Example for a Hit-and-miss Structuring Element
• Contains 0s, 1s and don’t care’s.
• Usually a “1” at the origin!
21-Jun-23 108
Hit-and-miss Transform
• Similar to Pa ern Matching:
• If foreground and background pixels in the structuring element
exactly match foreground and background pixels in the image,
then the pixel underneath the origin of the structuring element is
set to the foreground color.
21-Jun-23 109
Corner Detection with Hit-and-miss
Transform
• Structuring Elements representing four corners
21-Jun-23 110
Corner Detection with Hit-and-miss
Transform
• Apply each Structuring Element
• Use OR operation to combine the four results
21-Jun-23 111
43 Morphological
Algorithms
Using these morphological operations we may
extract image components for shape representation:
• Shape boundaries.
• Region filling.
• Connected components
• Convex hull.
• Shape thinning and thickening.
• Skeletons.
We may also accomplish a morphological image
reconstruction.
C. Nikou – Digital Image Processing
• Boundary Extraction
Boundary Extraction
Algorithm
44 Boundary
Extraction
The boundary of a set A, denoted by β(A),
may be obtained by: