EE-583: Digital Image Processing
Morphological Image Processing
• The word morphology refers to the scientific branch that deals the forms and
structures of animals/plants.
•Morphology in image processing is a tool for extracting image components
that are useful in the representation and description of region shape, such as
boundaries and skeletons.
•Furthermore, the morphological operations can be used for filtering, thinning
and applied on binary images.
• It takes binary image and mask (structure element) as input and applied set
operations on the image
•The language of the Morphology comes from the set theory, where image
objects can be represented by sets. For example an image object containing
black pixels can be considered a set of black pixels in 2D space of Z 2.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Set Theory Fundamentals
• Given that A is a set in Z2and a=(a1,a2), then
a is an element in A: a A
a is not an element in A: a A
• given sets A and B, A is said to be the subset of B: AB
•The union of A and B is denoted by: C A B
•The intersection of A and B is denoted by: D A B
•Two sets are disjoint/mutually exclusive if A B
•The complement of set A is the set of elements not contained in A, Ac A
•The difference of two sets: A B A, B A B c
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Set Theory Fundamentals
Given 2 sets A and B
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Logic operation involving Binary Images
• Given 1-bit binary images, A and B, the basic logical operations are
illustrated:
• Note that the black indicates
binary 1 and white indicates binary
0 here.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Dilation and Erosion
• Dilation and erosion are the two fundamental operations
used in morphological image processing. Almost all
morphological algorithms depend on these two operations:
Dilation Erosion
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Shapes of Different Structure Elements
Structuring Element is the base structure we will use
to apply a morphological operation. The shape of a
Structuring Element can change depends of what type
of a shape are we looking for in an image.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
• Dilation: Given A and B sets in Z2, the dilation of A by B, is defined by:
A B z ( Bˆ ) z A
•The dilation of A and B is a set of all displacements, z , such that ^B and A
overlap by at least one element. The definition can also be written as:
A B z ( Bˆ ) z A A
•Set B is referred to as the structuring element and used in dilation as well as in
other morphological operations. Dilation expands a given image.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Dilation and Erosion
• Dilation: Given the structuring element B and set A.
Shaded area is the dilation
of A by B
origin
•The structuring element B
enlarges the size of A at its
boundaries. Dilation simply
expands a given image.
•The structuring element B enlarges the size of
A at its boundaries, in relation to the distance
from the origin of the structuring element .
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
• Dilation: Given the following distorted text image where the maximum length
of the broken characters are 2 pixels. The image can be enhanced by bridging
the gaps by using the structuring element given below:
B
3x3 structuring
element
A A B
•Note that the broken characters are joined.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
• Erosion: Given A and B sets in Z2, the erosion of A by structuring element B, is
defined by:
A B z ( B ) z A
•The erosion of A by structuring element B is the set of all points z, such that B,
translated by z, is contained in A.
Shaded area is the erosion
of A by B
structuring
element
•Note that in erosion the structuring element B erodes the input image A at its boundaries.
Erosion shrinks a given image.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Dilation and Erosion
• Erosion: Given the structuring element B and set A.
Shaded line is what is left
from the erosion of A by B
structuring
element
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Dilation and Erosion
• Erosion: Given the following binary image with squares on size 1,3,5,7,9 and
15. You can get rid of all the squares less than size of 15 by erosion followed by
dilation of a structuring element of 13x13.
B
13x13 structuring
element
A A B
Erosion of A by B
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Dilation and Erosion
• Dilation: Cont. from the previous slide. Note that erosion followed by
dilation helps to perform filtering.
B
13x13 structuring
element
A B ( A B) B
dilation by B
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Opening and closing
• Opening: The process of erosion followed by dilation is called opening. It has
the effect of eliminating small and thin objects, breaking the objects at thin
points and smoothing the boundaries/contours of the objects.
• Given set A and the structuring element B. Opening of A by structuring element
B is defined by:
A B ( A B ) B
• Closing: The process of dilation followed by erosion is called closing. It has the effect of
filling small and thin holes, connecting nearby objects and smoothing the
boundaries/contours of the objects.
•Given set A and the structuring element B. Closing of A by structuring element B is
defined by:
A B ( A B ) B
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Opening and closing
• Opening: The opening of A by the structuring element B is obtained by taking
the union of all translates of B that fit into A.
•The opening operation can also be expressed by the following formula:
A B Bz ( Bz ) A
Outer boundary of A
Origin of B
Circular structuring element Shaded area: complete opening
Possible translations of B in A Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Opening and closing
• Closing: The closing has a similar geometric interpretation except that we roll
B on the outside of the boundary.
•The opening operation can also be expressed by the following formula:
A B ( Bz ) ( Bz ) A
Outer boundary of A
Outer boundaries of closing
Shaded area: complete closing
Possible translations of B on the outer boundaries of A Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Opening and closing
B
circular structuring
element
result of erosion of A by B
result of opening of A by B
result of dilation of A by B
result of closing of A by B
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Opening and closing
• Noise Filtering: The morphological operations can be used to remove the noise
as in the following example:
3x3 square
structuring
element
result of opening followed by closing
after Note that impulsive noise within the
opening background and the fingerprints is removed.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Hit-or-Miss Transform (Template Matching)
• Hit-or-miss transform can be used for shape detection/ Template matching.
•Given the shape as the structuring element B1 the Hit-or-miss transform is
defined by:
c
A
* B ( A B1 ) ( A B2 )
• Where B2 =W-X and B1=X. W is the window enclosing B1. Windowing is used to
isolate the structuring element/object.
B2=W-X, used as the second
structuring element.
Complement of B1
Shape that we are searching for
Used as the structuring element (B 1=X) Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Hit-or-Miss Transform
c
A
* B ( A B1 ) ( A B2 )
B2
B1
Complement of A
Erosion of A by B1
Erosion of comp of AC by B2
The location of the matched object/shape,
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Fit Operation Hit Operation Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Output Image
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
A B ( A B1 ) ( Ac B2 )
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Basic Morphological Algorithms
• Boundary Extraction: The boundaries/edges of a region/shape can be
extracted by first applying erosion on A by B and subtracting the eroded A from
A.
( A) A ( A B )
Ex 1: 3x3 Square structuring element is used Ex 2: The same structuring element in Ex1 is used.
for boundary extraction.
Note that thicker boundaries can be obtained by
increasing the size of structuring element.
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Perform the boundary extraction on input
image
A- eroded image
Prepared By: Dr. Hasan Demirel, PhD
Erosion
EE-583: Digital Image Processing
Morphological Image Processing
Basic Morphological Algorithms
• Thinning: Thinning of A by the structuring element B is defined by:
A B A ( A
* B)
hit-or-miss transform/template matching
• Note that we are only interested in pattern matching of B in A, so no background
operation is required of the hit-miss-transform.
{B} {B1 , B 2 , B 3 ,..., B n }
•The structuring element B consists of a sequence of structuring elements, where B i is the
rotated version of Bi-1. Each structuring elements helps thinning in one direction. If there
are 4 structuring elements thinning is performed from 4 directions separated by 90 o. If 8
structuring elements are used the thinning is performed in 8 directions separated by 45 o.
•The process is to thin A by one pass with B1, then the result with one pass of B2, and
continue until A is thinned with one pass of Bn.
A {B} ((...(( A B1 ) B 2 )...) B n )
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Morphological Image Processing
Basic Morphological Algorithms
• Thinning: The following set of structuring elements are used for thinning operation.
...
If there is no change any
more. Declared to be the
thinned object
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Thickening
Input output Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Gray Scale Morphology
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Dilation Example
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Prepared By: Dr. Hasan Demirel, PhD
EE-583: Digital Image Processing
Prepared By: Dr. Hasan Demirel, PhD