Digital Image Processing
2024 – 2025
Lecture-8
Dr: Mary monir saied
Email: [email protected]
Digital Image Fundamentals
Morphological Image
Processing
Fundamental Steps of DIP
3
Contents
• Once segmentation is complete, morphological
operations can be used to remove imperfections in the
segmented image and provide information on the form
and structure of the image
• In this lecture we will consider
1.What is Morphology?
2.Fundamentals
3.Basic Morphological Operations
4.Compound Operations
5.Basic Morphological Algorithms 4
1, 0, Black, White?
Throughout all of the following slides whether 0
and 1 refer to white or black is a little
interchangeable
All of the discussion that follows assumes
segmentation has already taken place and that
images are made up of 0s for background pixels
and 1s for object pixels
5
GRAY LEVEL THRESHOLDING
Objects
Set threshold
here
BINARY IMAGE
Problem here
How do we fill “missing pixels”?
1-What is Morphology ?
Morphology: a branch in biology that deals with the
form and structure of animals and plants. “Morphing” in
Biology which means ”changing a shape”.
Image morphological operations are used to
manipulate object shapes such as thinning, thickening,
and filling.
Mathematical morphology extraction of image
component that are useful in the representation and 8
description of regional shape, such as boundaries and
skeletons.
1-What is Morphology ?
•Binary morphological operations are typically
applied to remove imperfections introduced
during segmentation, and so typically operate
on bi-level images.
•Once segmentation is complete, morphology
can be used to remove imperfections in the
segmented image and provide information on
the form and structure of the image. 9
1-What is Morphology ?
10
1-What is Morphology ?
- Example
11
2-Fundamentals
- Basic Set Theory
12
2-Fundamentals
- Reflection and Translation
13
2-Fundamentals
- Logic Operations
14
2-Fundamentals
-Example
15
2-Fundamentals
•Fundamentally morphological image
processing is very like spatial filtering.
•A structuring element (SE) is moved across
every pixel in the original image to give a pixel
in a new processed image.
•The value of this new pixel depends on the
operation performed. 16
2-Fundamentals
Steps
• Pad the binary image with the suitable border of
0’s according to the size of the SE
• Start translating the SE on the padded binary image
in a convolution manner
• At each location, apply a morphological operation
between the SE and the corresponding pixels on
the image
• Place the result in a new buffer at the origin of SE 17
2-Fundamentals
- Structuring Elements, Hits & Fits
•A SE can be any size and make any shape.
•Each SE has its own origin point (black dot in
the fig.)
.
18
2-Fundamentals
- Structuring Elements, Hits & Fits
19
2-Fundamentals
- Structuring Elements, Hits & Fits
0 0 1 0 0
1 1 1 0 1 0 0 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1
1 1 1 0 1 0 0 1 1 1 0
0 0 1 0 0
20
2-Fundamentals
- Structuring Elements, Hits & Fits
21
2-Fundamentals
- Structuring Elements, Hits & Fits
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
0 0 0 1 1 0 0 0 0 0 0 0 1 1 1
0 0 1 B1 1 1 1 0 C0 0 0 0 1 1 1
Structuring
0 1 1 1 1 1 1 1 0 0 0 0 Element 1
0 1 1 1 1 1 1 1 0 0 0 0
0 1 0
0 0 1 1 1 1 1 1 0 0 0 0
1 1 1
0 0 1 1 1 1 1 1 1 0 0 0
0 1 0
0 0 1 1 1 1 1 A1 1 1 1 0
Structuring 22
0 0 0 0 0 1 1 1 1 1 1 0 Element 2
0 0 0 0 0 0 0 0 0 0 0 0
2-Fundamentals
23
2-Fundamentals
Fundamentally morphological image processing
is very like spatial filtering
The structuring element is moved across every
pixel in the original image to give a pixel in a new
processed image
The value of this new pixel depends on the
operation performed
There are two basic morphological operations:
24
erosion and dilation
3- Basic Morphological Operations
1- Dilation
25
3.1 Dilation
• B = structuring element
• If AT LEAST one of the 1’s of the SE coincides
with (1) in the image, then place (1) in the new
buffer at the origin of SE. Else, place 0
(background)
• Note that the SE is reflected around its origin then 26
convolved with the image
3.1 Dilation
Example for Dilation
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1
27
3.1 Dilation
Example for Dilation
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 1 0
28
3.1 Dilation
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
29
3.1 Dilation
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
30
3.1 Dilation
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
31
3.1 Dilation
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
32
3.1 Dilation
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
33
3.1 Dilation
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
34
3.1 Dilation
Original Image Processed Image With Dilated Pixels
35
Structuring Element
3.1 Dilation
1 1 1
36
1 1 1
1 1 1
3.1 Dilation
Dilation allows object to expand, then potentially filling in small holes and
connecting disjoint object.
Dilation expands the connected sets of 1s of a binary image.
It can be used for
1. Expanding shapes
2. Filling holes and gaps.
37
3.1 Dilation
Example :
Dilation expands the connected sets of 1s of a binary image. The shaded pixels
are considered 1s in a binary image which refer to the object.
38
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
39
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
40
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
41
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
42
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
43
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
44
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
45
3.1 Dilation
Dilation Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary OR operation of the
corresponding elements in A.
46
3.1 Dilation
47
3.1 Dilation
Original image Dilation by 3*3 Dilation by 5*5 square
square structuring structuring element
element
48
Watch out: In these examples a 1 refers to a black pixel!
3.1 Dilation
Original image After dilation
49
Structuring element
3.1 Dilation
Dilation can repair breaks
Dilation can repair intrusions
50
Watch out: Dilation enlarges objects
3- Basic Morphological Operations
2- Erosion
51
3.2 Erosion
• If ALL 1’s of the SE coincide with 1’s in the image,
then place 1 in the new buffer at the origin of SE.
Else, place 0 (background)
52
3.2 Erosion
Example for Erosion
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element
Output Image 0
53
3.2 Erosion
Example for Erosion
Input image
1 0 0 0 1 1 1 0 1 1
Structuring Element 1 1 1
Output Image 0 0
54
3.2 Erosion
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
55
3.2 Erosion
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
56
3.2 Erosion
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
57
3.2 Erosion
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
58
3.2 Erosion
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
59
3.2 Erosion
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
60
3.2 Erosion
Erosion shrinks objects by etching away (eroding) their
boundaries. Erosion shrinks the connected sets of 1s of a binary
image.
It can be used for:
1. Shrinking shapes.
2. Removing bridges, branches, protrusions
3.2 Erosion
3.2 Erosion
Original Image Processed Image
63
Structuring Element
3.2 Erosion
1 1 1
64
1 1 1
1 1 1
3.2 Erosion
Erosion Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary AND operation of
the corresponding elements in A.
65
3.2 Erosion
Erosion Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary AND operation of
the corresponding elements in A.
66
3.2 Erosion
Erosion Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary AND operation of
the corresponding elements in A.
67
3.2 Erosion
Erosion Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary AND operation of
the corresponding elements in A.
68
3.2 Erosion
Erosion Technique:
Move B over A, placing origin at each pixel.
By considering 1-pixel location in B, compute the binary AND operation of
the corresponding elements in A.
69
3.2 Erosion
70
3.2 Erosion
Original image Erosion by 3*3 Erosion by 5*5 square
square structuring structuring element
element
71
Watch out: In these examples a 1 refers to a black pixel!
3.2 Erosion
Erosion can split apart joined objects
Erosion can strip away extrusions
Watch out: Erosion shrinks objects
72
4- Compound Operations
More interesting morphological operations can
be performed by performing combinations of
erosions and dilations
The most widely used of these compound
operations are:
Opening
Closing
73
4.1 Opening
74
4.1 Opening
Original Image Processed Image
75
Structuring Element
4.1 Opening
76
4.1 Opening
Note a disc shaped structuring element is used
Original shape After erosion After dilation
(opening)
Opening smoothes the contour of objects, breaks
narrow bridges, and eliminates thin protrusions. 77
4.1 Opening
An application of opening:
You can delete unwanted objects by using Opening
78
4.2 Closing
79
4.2 Closing
Note a disc shaped structuring element is used
Original shape After dilation After erosion
(closing)
Closing smoothes sections of contours as well, but
fuses narrow breaks, eliminate small holes, and fill 80
gaps.
4.2 Closing
81
4.3 opening and Closing
82
4.3 opening and Closing
83
4.3 opening and Closing
84
5- Basic Morphological Algorithms
Using the simple technique we have looked at so
far we can begin to consider some more
interesting morphological algorithms
We will look at:
◦ Boundary extraction
85
5.1 Boundary Extraction
Extracting the boundary (or outline) of an
object is often extremely useful
The boundary can be given simply as
β(A) = A – (AB)
86
5.1 Boundary Extraction
• A simple image and the result of performing boundary extraction
using a square 3*3 structuring element
87
Original Image Extracted Boundary