Tutorial 4 - Morphological Operations
Tutorial 4 - Morphological Operations
TUTORIAL 4
➢ Used in:
▪ Image enhancement.
▪ Noise reduction.
▪ Curve filling.
▪ Image segmentation.
Fundamentals
➢ Set
▪ In binary images, sets represents
groups of pixels at specific
locations.
▪ Morphological operations
change the “shape” of the
objects of interest according to
set theory concepts, e.g. union,
intersection, and complement.
Fundamentals
➢ Reflection
The reflection of set B, denoted by B̂ , is defined as:
Bˆ = {z | z = −b, for b B}
➢ Translation
The translation of set B, by point z, denoted by ( B) z , is defined as:
( B) z = {c | c = b + z, for b B}
Structuring Element
➢ Note
▪ The origin of the SE may not be in its center.
Image and SE Representation
1. Dilation.
2. Erosion.
1. Dilation
Or
ˆ ) A] A}
A B = { z | [( B z
This means that the dilation of A by B is the set of all displacements z, such that B̂ and A
overlap by at least one element
1. Dilation
➢ Example
▪ The first SE is symmetric. The increase in
vertical and horizontal direction is equal.
This means that the erosion of A by B is the set of all points z such that B translated by z is
contained in A.
In this example, the border’s pixels are handled using border replication.
2. Erosion
➢ Example
▪ The first SE is symmetric. The decrease in
vertical and horizontal direction is equal.
1. Opening.
2. Closing.
1. Opening
This means that the opening of A by B is obtained by taking the union of all translates
of B that fit into A. Accordingly, Opening results can be obtained by rolling the
structuring element B on the inside boundary of the shape to determine the new
boundaries.
1. Opening
➢ Examples
➢ Note
▪ The difference between opening and erosion is that opening
keeps the original shape while erosion shrinks it.
2. Closing
▪ Closing results can be obtained by rolling the structuring element B on the outside
boundary of the shape to determine the new boundaries.
2. Closing
➢ Examples
The result of closing using a circular SE of radius greater than the small circular
holes in the image.
2. Closing
➢ Examples
2. Closing
➢ Used for
▪ Filling gaps and eliminating small holes.
➢ Note
▪ The difference between closing and dilation is that closing
keeps the original shape while dilation grows it.
Opening/Closing Example
▪ Step 1: Erosion removes the
small noise but thins edges.
1. Hit or Miss.
2. Boundary Extraction.
3. Region/Hole Filling.
4. Extraction of Connected Components.
1. Hit or Miss
where, B1 is the set formed from elements of B associated with an object and B2 is the
set of elements of B associated with the corresponding background.
➢ Used for
▪ Detecting a shape that exists exactly in the image.
1. Hit or Miss
➢ Examples
1. Hit or Miss
➢ Examples
2. Boundary Extraction
It is the difference between the original image and the erosion result.
2. Boundary Extraction
➢ Examples
3. Region/Hole Filling
▪ It is an iterative process
where step k gets its input
from the previous step
output (k-1).
▪ It is an iterative process
where step k gets its input
from the previous step
output (k-1).
C D
E F
Question 4
Question 4
Question 5
Question 5
▪ Steps:
1. Invert the image to make the disks white and the background black.
2. Apply erosion using SE of the same size as disks → white pixels in the center of
the disk.
3. Count the number of white pixels.
Question 9
Question 9
a) 1. Color the image border pixels the same color
as the particles (white).
2. Apply the connected component algorithm
starting from a pixel on that border.
3. Subtract the added boundary.
Assignment 2
Question 12
Assignment 2
Question 13
Question 13
1. Convert the colored image to gray then threshold it to get a binary image (object
255, background 0).
2. Resize the test image to be of the same shape as the train image.
3. Compute the intersection between the test image and each train image.
4. Count the number of pixels in the intersected images (c).
5. Compute similarity score: c / (white pixels in test image)
6. The answer is the training sample of the highest similarity score.
Assignment 2