0% found this document useful (0 votes)
50 views147 pages

Dip 4

- Morphological image processing techniques include erosion, dilation, opening, closing, and hit-or-miss transformations. Erosion shrinks objects while dilation enlarges them. - Mathematical morphology is based on set theory and uses structuring elements to examine images and extract components related to shape. It has applications in preprocessing, segmentation, and quantitative analysis. - Morphological operations are useful for tasks like noise filtering, shape analysis, thinning, and feature extraction.

Uploaded by

gigabyte1812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views147 pages

Dip 4

- Morphological image processing techniques include erosion, dilation, opening, closing, and hit-or-miss transformations. Erosion shrinks objects while dilation enlarges them. - Mathematical morphology is based on set theory and uses structuring elements to examine images and extract components related to shape. It has applications in preprocessing, segmentation, and quantitative analysis. - Morphological operations are useful for tasks like noise filtering, shape analysis, thinning, and feature extraction.

Uploaded by

gigabyte1812
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 147

UNIT 4

Morphological Image Processing


CONTENT
• Morphological Image Processing: Erosion and Dilation, opening and
closing, Hit-or-Miss transformations, Basic morphological algorithms:
Boundary extraction, Hole filling, Extraction of connected
components.
3

It provides techniques for pre- and post- processing of an


image (morphological thinning, pruning, filtering).
Its principles are based on set theory. Applications to both
binary and graylevel images.
Mathematic Morphology
• 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
4
Mathematic Morphology
mathematical framework used for:
• pre-processing
• noise filtering, shape simplification, ...
• enhancing object structure
• skeletonization, convex hull...
• Segmentation
• watershed,…
• quantitative description
• area, perimeter, ...
5
4 Preliminarie
s
The four horizontal and ver tical neighbours of
a pixel p are called 4-neighbours of p and are
denoted by N4(p).
The four diagonal neighbours of a pixel p are
denoted by ND(p).
Together N4(p) and ND(p) are called the 8-
neighbours of pixel p and are denoted by
N8(p).
5
Preliminaries (cont.)
Adjacency of pixels
Let V be the set of intensity values used to
define the adjacency (e.g. V={1} for binary
images).
4-adjacency. Two pixels p and q with values
in
V are 4-adjacent if q is in N4(p).
8-adjacency. Two pixels p and q with values
in
6
Preliminaries (cont.)
Adjacency of pixels
m-adjacency (mixed adjacency). Two pixels
p
and q with values in V are m-adjacent if
• q is in N4(p), or
•q is in ND(p) and the set N4(p) ∩ N4(q)
has no pixels whose values are in V .
Mixed adjacency is a modification of the 8-
adjacency. It is introduced to eliminate
7
Preliminaries (cont.)
Not m-connected. They
Adjacency of pixels have a common 4-
connected neighbor.

Pixels in a 8-adjacency m-adjacency


binary image m-connected. They do not have any
common 4-connected neighbor.
The role of m-adjacency is to define a single
path between pixels. It is used in many image
analysis and processing algorithms.
8
Preliminaries (cont.)
Basic set operations.

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.)

Erosion is a shrinking operation


17
Erosion (cont.)
18
Erosion (cont.)
Erosion by a square SE of varying size

Original image 11x11

15x15 45x4
5
19
Erosion (cont.)
Erosion can split apar tjoined objects

Erosion can strip away extrusions

Watch out: Erosion shrinks objects


Example for Erosion
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1

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.)

Dilation is a thickening operation


C. Nikou – Digital Image Processing
22
Dilation (cont.)

Dilation bridges gaps.


Contrary to low pass filtering
C. Nikou – Digital Image Processing
it produces a binary image.
23
Dilation (cont.)
Dilation can repair breaks

Dilation can repair intrusions

Watch out: Dilation enlarges objects


C. Nikou – Digital Image Processing
Typical Uses of Dilation
Example for Dilation
Input image 1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1

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

• Images get darker!


63
Dilation on Gray Value Images
• View gray value images as a stack of binary images!

64
Dilation on Gray Value Images

• More uniform intensity


65
Edge Detection
• Edge Detection
1. Dilate input image
2. Subtract input image from dilated image
3. Edges remain!

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 Thresholded closed 89


Closing Example 2
• Good for fu her processing: E.g. Skeleton
operation looks be er for closed image!

skeleton of skeleton of Thresholded


Thresholded and next closed 90
Closing Gray Value Images
• 5x5 square structuring element

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.

Closing: inward corners are


rounded.
C. Nikou – Digital Image Processing
32
Duality
Opening and closing are dual operations.
Erosion-Dilation duality Opening-Closing duality
( A B )c  c A ( A  B)c  Ac ∘B̂
 B̂

( A  B )c  c A ( A ∘B)c A B̂
 c


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:

C. Nikou – Digital Image Processing


45 Boundary Extraction
(cont.)
• The boundary is one pixel thick due to the 3x3 SE. Other SE wo
result in thicker boundaries.

Original Image Extracted Boundary


C. Nikou – Digital Image Processing
Region Filling Algorithm
46 Region
Filling
Given a pixel inside a boundary, region
filling at tempts to fill the area surrounded by
that boundary with 1s.

Given a point inside


here, can we fill the
whole circle?

C. Nikou – Digital Image Processing


47
Region Filling (cont.)
Form a set X0 with zeros everywhere except
at the seed point of the region.
Then,
X k  ( X k 1  B)  Ac ,

k  1,2,3,...

Where B is a 3x3 cross-shaped SE. The


algorithm terminates when Xk=Xk-1.
The set union of Xk and A contains all the
filled holes
C. Nikou – and their
Digital Image boundaries.
Processing
48
Region Filling (cont.)
This is a first example where the morphological
operation (dilation) is conditioned.
The intersection of the result with Ac limits the
result inside the region of interest.
X k  ( X k 1  B)  Ac ,

k  1,2,3,...

C. Nikou – Digital Image Processing


49
Region Filling (cont.)

C. Nikou – Digital Image Processing


50
Region Filling (cont.)

Original Image One Region All Regions


Filled Filled
C. Nikou – Digital Image Processing
Application
84 s Region filling
(cont.)

We wish to fill the hole of the image I.


The complement builds a wall around the hole.
The marker image F is one at the border except
from border pixels of the original image.
C. Nikou – Digital Image Processing
Application
85 s Region filling
(cont.)

The dilation of the marker F sta s from the


border and grows inward.
The complement is used as an AND mask: it
protects all foreground pixels (including the wall)
from changing during the iterations.
The lastC. operation provides only the hole points.
Nikou – Digital Image Processing
Application
86 s Region filling
Original image
(cont.)
Complement of original image

Marker image (1s almost everywhere Result of hole filling


on the border apa of some points
on the right border) C. Nikou – Digital Image Processing
51 Extraction of connected
components
• Given a pixel on a connected component, find the rest
of the pixels of that component.
• The algorithm may be applied to many connected
components provided we know a pixel on each one of
them.
• Disadvantage:
• we have to provide a pixel on the connected
component.
• There are more sophisticated algorithms that detect the
number of components without manual interaction. The
purpose here is to demonstrate the flexibility of
mathematical morphology.
C. Nikou – Digital Image Processing
Extraction of connected components
52
(cont.)
Form a set X0 with zeros everywhere except at
the seed point of the connected components.
Then,
X k  ( X k 1  B)  A, k  1,2,3,...

Where B is a 3x3 square-shaped SE. The


algorithm terminates when Xk=Xk-1.
Xk contains all the connected components.
C. Nikou – Digital Image Processing
Extraction of connected components
53
(cont.)
Note the similarity with region filling. The only
difference is the use of A instead of Ac.
This is not surprising as we search for foreground
objects.

C. Nikou – Digital Image Processing


Extraction of connected components
54
(cont.)
Image of chicken filet containing bone fragments

Result of simple thresholding

Image erosion to retain only objects of significant size.


15 connected components detected with four of them being
significant in size. This is an indication to remove the chicken
filet from packaging.
C. Nikou – Digital Image Processing
End of Unit 4

You might also like