0% found this document useful (0 votes)
10 views138 pages

MSC DIP 5th 6th Lecture

Chapter 9 discusses morphological processing, which focuses on removing imperfections in binary images through non-linear operations that consider the shape and structure of features. Key operations include dilation and erosion, which modify object boundaries based on a structuring element—a small binary matrix that defines the neighborhood for processing. The chapter explains how the choice of structuring element's shape and size affects the outcome of these operations.

Uploaded by

rababrongon
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)
10 views138 pages

MSC DIP 5th 6th Lecture

Chapter 9 discusses morphological processing, which focuses on removing imperfections in binary images through non-linear operations that consider the shape and structure of features. Key operations include dilation and erosion, which modify object boundaries based on a structuring element—a small binary matrix that defines the neighborhood for processing. The chapter explains how the choice of structuring element's shape and size affects the outcome of these operations.

Uploaded by

rababrongon
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/ 138

Chapter 9

Morphological Processing

1
Remember?

2
Morphological Processing

 Binary images may contain numerous


imperfections.

 Morphological image processing pursues the


goals of removing these imperfections by
accounting for the form and structure of the
image.
Morphological Processing

 Binary images may contain numerous


imperfections. In particular, the binary regions
produced by simple thresholding are distorted by
noise and texture.
Basic concepts

Morphological image processing is a collection


of non-linear (non-sequential) operations related to
the shape or morphology of features in an image.

Morphological operations rely only on the relative


ordering of pixel values and therefore are especially
suited to the processing of binary images.

Morphological techniques probe an image with a


small shape or template called a structuring
element.
Basic concepts

The structuring element is positioned at all possible


locations in the image and it is compared with the
corresponding neighborhood of pixels.

Some operations test whether the element "fits"


within the neighborhood, while

others test whether it "hits" or intersects the


neighborhood:
Morphological Operations

The most basic morphological operations are


dilation and erosion.
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.
By choosing the size and shape of the
neighborhood, you can construct a morphological
operation that is sensitive to specific shapes in the
input image
Basic concepts
Basic concepts

Structuring elements can be seen in 3 different


ways in the test input image which are as follows:

1) Structuring element fits the image region


2) Structuring element hits (intersects) the image
region
3) Structuring element neither fits nor hits the image
region
Structuring Element

Morphological techniques probe an image with a


small shape or template called a structuring
element.

The structuring element is a small binary image,


i.e. a small matrix of pixels, each with a value of zero
or one:
Structuring Element

What is matrix of pixels???

The matrix dimensions specify the size of the


structuring element.

The pattern of ones and zeros specifies the shape of


the structuring element.
Structuring Element

An essential part of the dilation and erosion


operations is the structuring element used to probe
the input image.

A structuring element is a matrix consisting of


only 0's and 1's that can have any arbitrary shape
and size.

The pixels with values of 1 define the


neighborhood.
Structuring Element
Structuring Element

How to Calculate the Origin of a Structuring Element

Equation can be written as:


origin = floor((size+1)/2)

Lets say structuring element mask size is 3 x 3

Base on the equation;


Origin = floor((3+1)/2) = 2

The position will be (2,2) if initial


Position is considered as (1,1)
Structuring Element

There are two main characteristics that are directly


related to structuring elements:

Shape and

Size
Structuring Element
Shape

For example, the structuring element can be a


circle, square, diamond etc.
By choosing a particular structuring element, one
sets a way of differentiating some objects (or parts
of objects) from others, according to their shape or
spatial orientation.
Structuring Element
Size

For example, one structuring element can be a 3 x 3


square or a 21 x 21 square.
Setting the size of the structuring element is similar
to setting the observation scale, and setting the
criterion to differentiate image objects or features
according to size.
Structuring Element

Structuring elements contains different shapes…

1) Square
Structuring Element

2) Diamond
Structuring Element

3) Disk
Structuring Element

4) Cross
Structuring Element

5) Rectangle
Structuring Element

6) Irregular
Morphological Operation

Dilation and Erosion

Dilation and erosion are two fundamental


morphological operations.

Dilation adds pixels to the boundaries of objects in


an image, while
Erosion removes pixels on object boundaries.

The number of pixels added or removed from the


objects in an image depends on the size and shape of
the structuring element used to process the image.
Morphological Operation

Characteristics of Erosion

Erosion generally decreases the sizes of objects and


removes small anomalies by subtracting objects with
a radius smaller than the structuring element.

With grayscale images, erosion reduces the


brightness (and therefore the size) of bright objects
on a dark background by taking the neighborhood
minimum when passing the structuring element over
the image.
Morphological Operation

Characteristics of Erosion

With binary images, erosion completely removes


objects smaller than the structuring element and
removes perimeter pixels from larger image objects
(the continuous line forming the boundary of a closed
geometrical figure.)
Morphological Operation

Characteristics of Dilation

Dilation generally increases the sizes of objects,


filling in holes and broken areas, and connecting
areas that are separated by spaces smaller than the
size of the structuring element.
Morphological Operation

Characteristics of Dilation

With grayscale images, dilation increases the


brightness of objects by taking the neighborhood
maximum when passing the structuring element over
the image.

With binary images, dilation connects areas that are


separated by spaces smaller than the structuring
element and adds pixels to the perimeter of each
image object.
Erosion

The erosion of a binary image f by a structuring


element s (denoted f Ɵ s) produces a new binary
image g = f Ɵ s with ones in all locations (x,y) of a
structuring element's origin at which that structuring
element s fits the input image f,

i.e. g(x,y) = 1 if s fits f


and
0 otherwise,

repeating for all pixel coordinates (x,y).


Erosion
Erosion

Erosion with small (e.g. 2×2 - 5×5) square


structuring elements shrinks an image by stripping
away a layer of pixels from both the inner and outer
boundaries of regions.

The holes and gaps between different regions


become larger, and small details are eliminated.
Erosion

The value of the output pixel is the minimum value


of all the pixels in the input pixel's neighborhood.

In a binary image, if any of the pixels is set to 0,


the output pixel is set to 0.
Erosion

Morphological Erosion of a Binary Image

Rules to follow:

1) Fully match  1
2) Some match  0
3) No match  0
Let’s solve this for Erosion using 3 x 3 square Structuring element

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1
0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0
1 1 1
0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0
1 1 1
0 0 1 1 1 1 1 0 0 0 0 1 1 1 0 0
0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0
0 0 0 1 1 0 0 0 0 1 1 1 1 1 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0
0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0
0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0
0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Red 0’s are used as zero padding

1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
001111 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
001111 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000111 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
001111 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
001111 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
001111 1 0 0 0 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
001111 0 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
001111 0 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000110 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 1 1 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000001 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000000 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000011 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000000 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000000 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000000 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000000 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000001 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000011 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000000 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000000 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000001 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000000 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000001 1 1 1 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000000 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000000 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000001 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000000 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Red 0’s are used as zero padding

0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 00 0 0
000010 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 00 0 0
000110 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 1 11 0 0
000000 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 11 0 0
000000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 11 0 0
000000 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 10 0 0
000000 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 00 0 0
000000 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 00 0 0
000000 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 00 0 0
000000 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 00 0 0
000001 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000000 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 00 0 0
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0
Erosion
Let’s check the result

000000 0 0 0 0 0 0 0 0 0 0
000000 0 0 0 0 0 0 0 0 0 0
000000 0 0 0 0 0 0 0 0 0 0
000010 0 0 0 0 0 0 0 0 0 0
000110 0 0 0 0 0 0 0 0 0 0
000000 0 0 0 0 0 0 1 0 0 0
000000 0 0 0 0 0 1 0 0 0 0
000000 0 0 0 0 1 0 0 0 0 0
000000 0 0 0 1 0 0 0 0 0 0
000000 0 0 1 0 0 0 0 0 0 0
000000 0 1 0 0 0 0 0 0 0 0
000000 1 1 0 0 0 0 0 0 0 0
000001 1 1 0 0 0 0 0 0 0 0
000000 1 1 1 1 0 0 0 0 0 0
000000 0 0 0 0 0 0 0 0 0 0
000000 0 0 0 0 0 0 0 0 0 0
Erosion

Try this example and solve if you can

0 0 0 0 0 0
1
0 0 1 1 0 0
1
0 1 1 1 1 0
1
0 0 1 1 0 0
Structuring Element
0 0 0 0 0 0

Test Image
Erosion
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 0 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 0 1 1 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 0 0 0 0
0 0 1 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Erosion

0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0
0 1 1 1 1 0 0 0 1 1 0 0
0 0 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
Erosion
Simple and easy way to solve
Rules:
1) Use zero ( 0 ) padding for each side.
2) Place the Structuring element and get the result straightway
Using the neighbors and erosion rule.
3) Make sure you only update values for origin only.
1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0

1 0 0 0 1 1 0 0 0 0 0 0 0 0 0
0 0 1 1 1 1 0 0 0 0 1 1 0 0
0 0 0 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Red 0’s are used as zero padding

1 1 1 000000000000000000
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 000000000000000000
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 000000000000000000
000111 0 0 0 0 0 0 0 0 0 0 000011100000000000
001111 1 0 0 0 0 0 0 0 0 0 000111110000000000
001111 1 0 0 0 0 1 1 1 0 0 000111110000111000
001111 0 0 0 0 1 1 1 1 0 0 000111100001111000
000110 0 0 0 1 1 1 1 1 0 0 000011000011111000
000000 0 0 1 1 1 1 1 0 0 0 000000000111110000
000000 0 1 1 1 1 1 0 0 0 0 000000001111100000
000000 1 1 1 1 1 0 0 0 0 0 000000011111000000
000001 1 1 1 1 0 0 0 0 0 0 000000111110000000
000011 1 1 1 0 0 0 0 0 0 0 000001111100000000
000011 1 1 1 1 1 1 0 0 0 0 000001111111100000
000011 1 1 1 1 1 1 0 0 0 0 000001111111100000
000001 1 1 1 1 1 0 0 0 0 0 000000111111000000
000000 0 0 0 0 0 0 0 0 0 0 000000000000000000
000000000000000000
Red 0’s are used as zero padding

1 1 1 000000000000000000
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 000000000000000000
000000 0 0 0 0 0 0 0 0 0 0 1 1 1 000000000000000000
000000 0 0 0 0 0 0 0 0 0 0 000011100000000000
000010 0 0 0 0 0 0 0 0 0 0 000111110000000000
000110 0 0 0 0 0 0 0 0 0 0 000111110000111000
000000 0 0 0 0 0 0 1 0 0 0 000111100001111000
000000 0 0 0 0 0 1 0 0 0 0 000011000011111000
000000 0 0 0 0 1 0 0 0 0 0 000000000111110000
000000 0 0 0 1 0 0 0 0 0 0 000000001111100000
000000 0 0 1 0 0 0 0 0 0 0 000000011111000000
000000 0 1 0 0 0 0 0 0 0 0 000000111110000000
000000 1 1 0 0 0 0 0 0 0 0 000001111100000000
000001 1 1 0 0 0 0 0 0 0 0 000001111111100000
000000 1 1 1 1 0 0 0 0 0 0 000001111111100000
000000 0 0 0 0 0 0 0 0 0 0 000000111111000000
000000 0 0 0 0 0 0 0 0 0 0 000000000000000000
000000000000000000
Erosion

1) clc,
2) close all;
3) clear all;
4)
5) I = imread('D:\matlab_folder\week_9.png');
6) figure, imshow(I);
7) SE = strel('square',5);
8)
9) J = imerode(I,SE);
10) figure, imshow(J);
Erosion
Erosion

Just change line number 7 for the previous slide and play with
different shapes of structuring element

-> SE = strel(‘diamond’,5);
OR -> SE = strel(‘disk’,5);
OR -> SE = strel(‘octagon’,5);
OR -> SE = strel(‘line’,len,deg); %len =lenth , deg = degree
OR -> SE = strel(‘rectangle’,[m n]);
OR -> SE = strel(‘cube’,5);
OR -> SE = strel('square',5);
Erosion

Larger structuring elements have a more pronounced


effect, the result of erosion with a large structuring
element being similar to the result obtained by
iterated erosion using a smaller structuring element of
the same shape.

If s1 and s2 are a pair of structuring elements identical


in shape, with s2 twice the size of s1,
then
f Ɵ s2 ≈ (f Ɵ s1) Ɵ s1.
Erosion

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('rectangle',[4 8]);
J = imerode(I,SE);
%J = imerode(J,SE);
figure, imshow(J);
Erosion
Erosion

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('rectangle',[4 4]);
J = imerode(I,SE);
J = imerode(J,SE);
figure, imshow(J);
Erosion
Erosion

Erosion removes small-scale details from a binary


image but simultaneously reduces the size of regions
of interest, too.

By subtracting the eroded image from the original


image, boundaries of each region can be found:
b = f − (f Ɵ s )
where f is an image of the regions, s is a 3×3
structuring element, and b is an image of the region
boundaries.
Erosion

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('rectangle',[4 4]);
J = imerode(I,SE);
figure, imshow(J);
K = I - J;
figure, imshow(K);
Erosion
Dilation
The dilation of an image f by a structuring
element s (denoted f s) produces a new binary
image g = f s with ones in all locations (x,y) of a
structuring element's origin at which that structuring
element s hits the input image f,
i.e. g(x,y) = 1 if s hits f
and
0 otherwise, repeating for all pixel
coordinates (x,y).

Dilation has the opposite effect to erosion as it adds a


layer of pixels to both the inner and outer boundaries
of regions.
Dilation
Dilation

The value of the output pixel is the maximum value


of all the pixels in the input pixel's neighborhood. In
a binary image, if any of the pixels is set to the
value 1, the output pixel is set to 1.
Dilation

The holes enclosed by a single region and gaps


between different regions become smaller, and small
intrusions into boundaries of a region are filled in:
Dilation and Erosion relation

Results of dilation or erosion are influenced both by


the size and shape of a structuring element. Dilation
and erosion are dual operations in that they have
opposite effects. Let f c denote the complement of an
image f, i.e., the image produced by replacing 1 with
0 and vice versa. Formally, the duality is written as

f s = f c Ɵ srot
Dilation and Erosion relation

where srot is the structuring element s rotated by 180.


If a structuring element is symmetrical with respect
to rotation, then srot does not differ from s.
If a binary image is considered to be a collection of
connected regions of pixels set to 1 on a background
of pixels set to 0, then erosion is the fitting of a
structuring element to these regions and dilation is
the fitting of a structuring element (rotated if
necessary) into the background, followed by
inversion of the result.
Dilation and Erosion relation

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('square',7);
J = imdilate(I,SE);
figure, imshow(J);
Dilation and Erosion relation
Dilation and Erosion relation

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
I1 = imcomplement(I);
figure, imshow(I);
SE = strel('square',7);
J = imerode(I1,SE);
J = imcomplement(J);
figure, imshow(J);
Dilation and Erosion relation
Dilation

Morphological Dilation of a Binary Image

1) Fully match  1
2) Some match  1
3) No match  0
Let’s try this with 3 x 3 matrix for Dilation

0000000000000000
0000000000000000
0001110000000000 1 1 1
0011111000000000 1 1 1
0011111000011100 1 1 1
0011110000111100
0001100001111100
0000000011111000
1 1 1
0000000000000000
1 1 1 0000000000000000
0000000000000000 1 1 1 0000000000000000
0001110000000000 0001110000000000
0011111000000000 0011111000000000
0011111000011100 0011111000011100
0011110000111100 0011110000111100
0001100001111100 0001100001111100
0000000011111000 0000000011111000
0000000000000000
1 1 1 0000000000000000
0000000000000000
1 1 1 0011111000000000
0001110000000000
1 1 1 0001110000000000
0011111000000000 0011111000000000
0011111000011100 0011111000011100
0011110000111100 0011110000111100
0001100001111100 0001100001111100
0000000011111000 0000000011111000
0000000000000000 0000000000000000
0000000000000000
1 1 1 0011111000000000
0001110000000000 1 1 1 0111111100000000
0011111000000000 1 1 1 0011111000000000
0011111000011100 0011111000011100
0011110000111100 0011110000111100
0001100001111100 0001100001111100
0000000011111000 0000000011111000
0000000000000000 0000000000000000
0000000000000000 0011111000000000
0001110000000000
1 1 1 0111111100000000
0011111000000000
1 1 1 0111111100111100
0011111000011100
1 1 1 0011111000011100
0011110000111100 0011110000111100
0001100001111100 0001100001111100
0000000011111000 0000000011111000
0000000000000000 0000000000000000
0000000000000000 0011111000000000
0001110000000000 0111111100000000
0011111000000000 1 1 1 0111111100111100
0011111000011100 1 1 1 0111111101111110
0011110000111100 1 1 1 0011110000111100
0001100001111100 0001100001111100
0000000011111000 0000000011111000
0000000000000000 0000000000000000
0000000000000000 0011111000000000
0001110000000000 0111111100000000
0011111000000000 0111111100111100
0011111000011100 1 1 1 0111111101111110
0011110000111100 1 1 1 0111111111111110
0001100001111100 1 1 1 0001100001111100
0000000011111000 0000000011111000
0000000000000000 0000000000000000
0000000000000000 0011111000000000
0001110000000000 0111111100000000
0011111000000000 0111111100111100
0011111000011100 0111111101111110
0011110000111100 1 1 1 0111111111111110
0001100001111100 1 1 1 0111111111111110
0000000011111000 1 1 1 0000000011111000
0000000000000000 0000000000000000
0000000000000000 0011111000000000
0001110000000000 0111111100000000
0011111000000000 0111111100111110
0011111000011100 0111111101111110
0011110000111100 0111111111111110
0001100001111100 1 1 1 0111111111111110
0000000011111000 1 1 1 0011110111111110
1 1 1
0000000000000000 0000000000000000
0000000000000000 0011111000000000
0001110000000000 0111111100000000
0011111000000000 0111111100111110
0011111000011100 0111111101111110
0011110000111100 0111111111111110
0001100001111100 0111111111111110
0000000011111000 0011110111111110
Dilation

Try this and check your result

0 0 0 0 0 0
1
0 0 1 1 0 0
1
0 1 1 1 1 0
1
0 0 1 1 0 0
0 0 0 0 0 0
Dilation
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 1 1 0 0
Dilation

0 0 0 0 0 0
0 0 1 1 0 0
0 1 1 1 1 0
0 0 1 1 0 0
0 0 0 0 0 0

0 0 1 1 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
Dilation

0 0 0 0 0 0 0 0 1 1 0 0
0 0 1 1 0 0 0 1 1 1 1 0
0 1 1 1 1 0 0 1 1 1 1 0
0 0 1 1 0 0 0 1 1 1 1 0
0 0 0 0 0 0 0 0 1 1 0 0
Dilation
Simple and easy way to solve
Rules:
1) Use zero ( 0 ) padding for each side.
2) Place the Structuring element and get the result straightway
Using the neighbors and dilation rule.
3) Make sure you only update values for origin only.
1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 1 1 0 0 0 0 0 1 1 0 0
0 0 1 1 1 1 0 0 0 1 1 1 1 0
0 0 0 1 1 0 0 0 0 0 1 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 000000000000000000
0000000000000000 1 1 1 000000000000000000
0011111000000000 1 1 1 000000000000000000
0111111100000000 000011100000000000
0111111100111110 000111110000000000
0111111101111110 000111110000111000
0111111111111110 000111100001111000
0111111111111110 000011000011111000
0011110111111110 000000000111110000
000000000000000000
0000000000000000
0011111000000000
0111111100000000
0111111100111110
0111111101111110 1 1 1 000000000000000000
0111111111111110 1 1 1 000000000000000000
1 1 1 000000000000000000
0111111111111110
0011110111111110 000011100000000000
000111110000000000
0000000000000000 000111110000111000
0011111000000000 000111100001111000
0111111100000000 000011000011111000
0111111100111110 000000000111110000
0111111101111110 000000000000000000
0111111111111110
0111111111111110
0011110111111110
Morphological Opening

The opening of an image f by a structuring


element s (denoted by f s) is an erosion followed by
a dilation:

f s = ( f s) s
Morphological Opening

Opening is so called because it can open up a gap between


objects connected by a thin bridge of pixels. Any regions that
have survived the erosion are restored to their original size by
the dilation:
Morphological Opening

Opening is an idempotent operation: once an image has been


opened, subsequent openings with the same structuring
element have no further effect on that image:
Morphological Opening

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('square',5);
J = imopen(I,SE);
figure, imshow(J);
Morphological Opening
Morphological Opening

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('square',5);
J = imerode(I,SE);
J = imdilate(J,SE);
figure, imshow(J);
Morphological Opening
Morphological Closing

The closing of an image f by a structuring element s (denoted


by f • s) is a dilation followed by an erosion:

f • s = ( f srot) srot
Morphological Closing

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('square',5);
J = imclose(I,SE);
figure, imshow(J);
Morphological Closing
Morphological Closing

clc,
%close all;
clear all;
I = imread('D:\matlab_folder\2.jpg');
figure, imshow(I);
SE = strel('square',11);
J= imdilate(I,SE);
J = imerode(J,SE);
figure, imshow(J);
Morphological Closing
Morphological Filtering

There can be two types of morphological filtering


possible which are:

1) Top-hat filtering

2) Bottom-hat filtering
Morphological Filtering

Top-hat filtering:

Morphological top-hat filtering performs on the grayscale or


binary image and returns a filtered image. Top-hat filtering
computes the morphological opening of the image and then
subtracts the result from the original image.
Morphological Filtering

clc,
close all;
clear all;
I = imread('D:\matlab_folder\Dip1.png');
figure, imshow(I);
SE = strel('square',11);
J = imtophat(I,SE);
figure, imshow(J);
Morphological Filtering
Morphological Filtering

Bottom-hat filtering:

morphological bottom-hat filtering performs on the


grayscale or binary image and returns a filtered image,
Bottom-hat filtering computes the morphological closing of
the image and then subtracts the original image from the
result.
Morphological Filtering

clc,
close all;
clear all;
I = imread('D:\matlab_folder\Dip1.png');
figure, imshow(I);
SE = strel('square',5);
J = imbothat(I,SE);
figure, imshow(J);
Morphological Filtering
Thanks !!!

You might also like