0% found this document useful (0 votes)
35 views

Tutorial 4 - Morphological Operations

Uploaded by

Habiba Yasser
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)
35 views

Tutorial 4 - Morphological Operations

Uploaded by

Habiba Yasser
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/ 63

DIGITAL IMAGE PROCESSING

TUTORIAL 4

Morphological Image Processing


AGENDA

❑ Basic Morphological Operations.


❑ Dilation.
❑ Erosion.
❑ Compound Operations.
❑ Morphological Algorithms.
❑ Sheet 3.
Morphological Image Processing

➢ Morphological Image Processing


▪ It is a collection of non-linear operations related to the shape or morphology of
features in an image.
▪ It relies only on the relative ordering of pixel values, not on their numerical values,
and therefore are especially suited to the processing of binary images.

➢ Used in:
▪ Image enhancement.
▪ Noise reduction.
▪ Curve filling.
▪ Image segmentation.
Fundamentals
➢ Set
▪ In binary images, sets represents
groups of pixels at specific
locations.

▪ Each pixel is represented in the


2D integer space Z2 by vector
(x,y) of white or black.

▪ 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

➢ Structuring Element (SE)


▪ Masks of varying shapes and sizes used to perform
morphology.

▪ Scan the mask across foreground pixels to transform the


binary image.

▪ Put the SE origin on the pixel that you want to compute.

➢ Note
▪ The origin of the SE may not be in its center.
Image and SE Representation

▪ The structuring element is represented by a rectangular


array. This is accomplished by appending the smallest
possible number of background elements (necessary to
form a rectangular array.

▪ The set representing the image also needs to be a


rectangular array.
Basic Morphological Operations

1. Dilation.
2. Erosion.
1. Dilation

The dilation of A by B is defined as:


ˆ )  A  }
A  B = {z | ( B z

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.

▪ The second SE is not symmetric. The increase


in the vertical direction is more than the
horizontal direction.
➢ Notes
▪ Don’t forget to get the reflection of the SE before applying dilation.

▪ Successive application of dilation won’t make all the pixels foreground


except if the SE has at least one foreground pixel in both the horizontal
and vertical directions.
1. Dilation
➢ Used to:
▪ Growing features.

▪ Filling holes and gaps.


2. Erosion

The erosion of A by B is defined as:


A − B = { z | ( B ) z  A}
Or
A − B = { z | [( B ) z  Ac ] = }

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.

▪ The second SE is not symmetric. The decrease


in the vertical direction is more than the
horizontal direction.
➢ Notes
▪ Successive application of erosion won’t make all the pixels background (eg: trivial case
where SE is one foreground pixel in its origin).
▪ The erosion of a shape by itself will result in a single foreground pixel in its origin.
2. Erosion
➢ Used for:
▪ Shrinking features.

▪ Removing bridges, branches and small


protrusions.
Dilation/Erosion Example
Compound Operations
▪ Compound operations are performed by combinations of erosions and dilations.

▪ The most widely used compound operations are:

1. Opening.
2. Closing.
1. Opening

▪ It is performed by erosion then dilation.

▪ Opening can also be defined as:


A B = {( B ) z | ( B) z  A}

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

The result of opening using a circular SE of radius equal to the small


circular holes in the image.
1. Opening
➢ Examples
1. Opening
➢ Used for
▪ Removing small objects.

▪ Breaking narrow bridges and eliminating thin protrusions.

➢ Note
▪ The difference between opening and erosion is that opening
keeps the original shape while erosion shrinks it.
2. Closing

▪ It is performed by dilation then erosion.

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

▪ Fuses narrow breaks.

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

▪ Step 2: Dilation restores the


original edges thickness.

▪ Step 3: Dilation closes the


gaps in the edges but
increases the edge thickness.

▪ Step 4: Erosion restores the


original edge thickness again.
Morphological Algorithms
Using the simple techniques we have looked at so far, we can begin to
consider some more interesting morphological algorithms:

1. Hit or Miss.
2. Boundary Extraction.
3. Region/Hole Filling.
4. Extraction of Connected Components.
1. Hit or Miss

▪ Hit or miss can be defined as:

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

▪ Boundary extraction can be defined as:

It is the difference between the original image and the erosion result.
2. Boundary Extraction
➢ Examples
3. Region/Hole Filling

▪ Region/Hole filling can be defined as:

where Ac is the complement of the original set A.

▪ It is an iterative process
where step k gets its input
from the previous step
output (k-1).

▪ The equation is applied


repeatedly until Xk = X(k-1)
3. Region/Hole Filling
➢ Examples
▪ Given a pixel inside a boundary, region filling
attempts to fill it.

▪ What will happen if we used a SE of all ones


in this example?
The operation fails (the whole set becomes
foreground as the set has diagonal
boundaries.

If all the boundaries where vertical and


horizontal, we can use a SE of all ones.
4. Extraction of Connected Components

▪ Extraction of Connected Components can be defined as:

where A is the original set.

▪ It is an iterative process
where step k gets its input
from the previous step
output (k-1).

▪ The equation is applied


repeatedly until Xk = X(k-1)
4. Extraction of Connected Components
➢ Examples
▪ Given a pixel on the component, we can
extract the whole connected component.
Question 1
Question 1
Question 2
Question 2
Question 2
Question 2
Question 2
Question 3
Question 3

C D

E F
Question 4
Question 4
Question 5
Question 5

▪ A: erosion using rectangular SE.


▪ B: erosion using rectangular SE.
▪ C: erosion using rectangular SE then dilation
using circular SE.
Question 6
Question 6

▪ The full reconstruction is possible as:


▪ The squares were not completely eroded.
▪ The geometry of the objects and structuring element was the same (they
were squares).
Question 7
Question 7

▪ Select a one-pixel border around the SE (sub-image of T). Let the


origin be located at the horizontal/vertical midpoint of this sub-
image.
The result of applying the hit-or-miss would be a single point where
the two Ts were in perfect registration. The location of the point
will be the same as the origin of the SE.

▪ Note: If the origin of SE is inside “T”, character T can be retrieved by


applying the connected component algorithm on the resulting
pixel.
Question 8
Question 8

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

b) Subtract the ((a) + (c)) from the original image.

c) 1. Apply hit and miss using SE of the same size as


the particles and black boundaries.
2. Apply connected components starting from all
the white pixels.
Or: Apply dilation using SE of the same size as
the particles.
Question 10
Question 10
Question 11

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

Sheet 3: Questions 11 and 12


After Midterm

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy