You are on page 1of 23

Lecture 22

Morphological
Operations

in

DIP

1
Chapter 9:
Morphological Image
Processing

2
NEW TOPIC

EROSION

AND

DILATION

3
4
5
Chapter 9:
Morphological Image Processing

6
7
Morphological: Erosion

8
A number of different Shape and size of structuring element
Can be possible

9
Example 9.1: Using erosion to remove image components

Matlab code
I = imread('Fig1005(a)(wirebond_mask).tif');
figure(1), imshow(I)
size = 3;
se = strel('disk', size);
I1 = imerode(I, se);
figure(2), imshow(I1), title('after erosion');
10
11
Eroding with
SE of size
11x11

Eroding with SE of size 15x15 Eroding with SE of size 45x45

12
Morphological: Dilation

13
14
Example 9.2: An illustration of dilation
Bridging the Gap

15
Erosion and dilation in Matlab
strel Create morphological structuring element.

SE = strel(‘shape', parameter)

Where, shape is a string specifying the desired shape, and parameter is a


list of parameters that specify information about the shape, such as its
size.

For example,
SE = strel('diamond',R) creates a flat diamond-shaped structuring
element with the specified size, R. R is the distance from the
structuring element origin to the points of the diamond. R must be a
nonnegative integer scalar.

Strel(‘diamond’, 5)
returns a diamond-shaped structuring element that extends ± 5 pixels
along the horizontal and vertical axes.

Table 9.2 summarizes the various shapes that strel can create in matlab.
16
SE = strel('disk',R,N) creates a flat disk-shaped structuring element with the
specified radius, R.

Examples
--------
se1 = strel('square',11) % 11-by-11 square

se2 = strel('line',10,45) % line, length 10, angle 45 degrees

se3 = strel('disk',15) % disk, radius 15

se4 = strel('ball',15,5) % ball, radius 15, height 5

17
SE = strel('square',5)

1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

SE = strel('diamond',5)

0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 1 1 0 0
0 0 0 1 1 1 1 1 0 0 0
0 0 0 0 1 1 1 0 0 0 0
18
0 0 0 0 0 1 0 0 0 0 0
Opening
Morphological opening is an erosion followed by a dilation.

To carry out morphological opening, use the function:

imopen(input_mask, structuring_element)

19
Opening
Morphological opening is an erosion followed by a dilation.
Hence, Opening operation could be useful for selecting objects of a
certain shape or smoothing the outline of objects in the image.
In the example images below, the input image (left) has both dots and
lines, while the output image (right) after opening has only dots.
You can try removing the lines yourself by downloading the following
image: dotsandlines.png

20
Closing
Morphological closing is a dilation followed by an erosion (i.e. the reverse
of the operations for an opening). As you might be able to guess, the net
effect of the closing operation is to remove background pixels that fit the
structuring element. In other words, closing tends to close gaps in the
image.
The function for morphological closing is:
imclose(input_mask, structuring_element

21
Combining Dilation and Erosion

22
Removing noise using opening followed by closing
morphological functions Example 9.4

Matlab Code

I = imread('Fig0911(a)(noisy_fingerprint).tif');
figure(1), imshow(I), title('Original Image')
size = 3;
se = strel('square', size);
I1 = imopen(I, se);
figure(2), imshow(I1), title('after opening function');
%Note: the noise is removed, but inreases gaps in the
ridges of fingerprint
%Gaps can be filled by following the opening with a
closing function as;
I2 = imclose(I1, se);
figure(3), imshow(I1), title('after closing function'); 23

You might also like