Sei sulla pagina 1di 11

FAKULTI TEKNOLOGI KEJURUTERAAN

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

EMBEDDED SYSTEMS

BETC 4473 SEMESTER 1 SESI 2017/2018

LAB 5: IMAGE MORPHOLOGY USING DILATION AND EROSION

1. MUHAMMAD AMIRUL HAFIZ BIN SHAMSUL


NAME OF GROUP B071410600
ARIFFIN
MEMBER(S) & MATRIX
NUMBER(S) 2. MUHAMMAD AMIRUL FARHAN BIN AZILAN B071410093

COURSE 4 BETC 1/1

DATE 8 December 2017

1. DR SUHAILA MOHD NAJIB


NAME OF INSTRUCTOR(S)
2. ROSTAM AFFENDI BIN HAMZAH

EXAMINERS COMMENT(S) VERIFICATION STAMP

TOTAL MARKS
1.0 TITLE: Image Morphology using Dilation and Erosion

2.0 OBJECTIVES

At the end of this lab session, student should be able:


1. To use the basic morphological operations: dilation and erosion.
2. To apply dilation and erosion for certain applications such filling the holes contained
in an object.

3.0 EQUIPMENT & COMPONENTS

1. Personal Computer
2. MATLAB.
3. Image Files: IMAGE_A.

4.0 RESULT

Section 1: Erosion

a. Upload the file leaves.png and show the result. Report the command and the result.

Img = imread('leaves.png');
imshow(Img);

Figure 1: Display of leaves.png


b. Now, try to convert it into a binary image with the threshold value of 0.1. Report the command
and the result

Img = imread ('leaves.png');


BW = im2bw (Img,0.1);
imshow (BW);

Figure 2: Display leaves.png in binary image with threshold value = 0.1

c. Now, all leaves will be separated by using erosion

Img = imread('leaves.png');
BW = im2bw(Img,0.1);
H = ones(4);
G = imerode(BW,);
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(G,[]);title('output');

Figure 3: Display leaves.png been erosion in binary image with ones (4)
Img = imread('leaves.png');
BW = im2bw(Img,0.1);
H = ones(6);
G = imerode(BW, H);
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(G,[]);title('output');

Figure 4: Display leaves.png been erosion in binary image with ones (6)

In section 1 (c) using the H = ones (6) do erosion is better in splitting the leaves compare to the
figure 3 using H = ones (4) do erosion

d. How to get the RGB image so all leaves are spitted?

img = imread ('leaves.png');


H = ones(6);
G = imerode (img, H)
imshow (G);

Figure 5: Output using RGB image


Section 2: Dilation

a. Upload the file smile.png and show the result

Img = imread('smile.png');
imshow(Img);

Figure 6: Display the image smile.png

b. Now, try to convert it into a binary image with the threshold value of 0.2

Img = imread('smile.png');
BW = im2bw(Img,0.2);
imshow(BW);

Figure 7: Display image smile.png in binary image with threshold = 0.2

c. Apply dilation to the image by using a kernel 4x4 that all coefficients are 1

Img = imread('smile.png');
BW = im2bw(Img,0.2);
H = ones(4);
G = imdilate(BW, H);
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(G,[]);title('output');
Figure 8: Display image smile.png with applying dilation and ones(4)

d. Try also for a kernel 7x7 that all coefficients are 1.

Img = imread('smile.png');
BW = im2bw(Img,0.2);
H = ones(7);
G = imdilate(BW, H);
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(G,[]);title('output');

Figure 9: Display image smile.png with applying dilation and ones (7)

Section 3: Appliction

a. Erosion can be used to get the object edge

Img = imread('croton.png');
BW = im2bw(Img);
BW = not (BW);
H = ones(5);
G = imerode(BW, H);
T = BW-G;
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(T,[]);title('output');
Figure 10: Display image croton.png in binary image

b. Apply to simba.png by using the threshold value of 0.3. Get the object edge. Be
careful, the background of simba.png is black

Img = imread('simba.png');
BW = im2bw(Img,0.3);
BW = not (BW);
H = ones(5);
G = imerode(BW, H);
T = BW-G;
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(T,[]);title('output');

Figure 11: Display edge of image simba.png in inverse binary image with threshold =0.3
c. Write a script named getedge. Its argument is a grayscale image. You can call it as
follow: getedge(ipomoea.png);

function getedge (filename);


Img = imread('ipomoea.png');
BW = im2bw(Img,0.3);
BW = not (BW);
H = ones(5);
G = imerode(BW, H);
T = BW-G;
imshow(T);

Figure 12: getedge output

d. By using the closing operation, small holes in an object can be removed.

Img = imread('croton.png');
BW = im2bw(Img);
imshow(BW);
BW = not (BW);
imshow(BW);
H= ones(8);
G=imdilate(BW, H);
M=imerode(G,H);
imshow(M);
Figure 13: Display image croton.png in imdilate and imerode image

e. Implement the commands in (d) in a script by using imclose( )

Img = imread('croton.png');
BW = im2bw(Img);
imshow(BW);
BW = not (BW);
imshow(BW);
H= ones(8);
G=imdilate(BW, H);
M=imerode(G,H);
M=imclose(G,H);
subplot(1,2,1);imshow(Img,[]);title('original');
subplot(1,2,2);imshow(M,[]);title('output');

Figure 13: Output display image using imclose( )


5.0 DISCUSSION

In this lab session, it contain 3 section which is erosion, dilation, and combination erosion
with dilation. In the first section erosion, erosion mean it will erode the image until all the object
is separate differently. The image erode was based on structure element. There are many structure
element in this world, but the most frequent using is square, ball, diamond and disk. The image
erosion with different structure element will give out the different result, so the structure element
have to select it wisely if not, the image will erode become null. In this lab, image leaves.png was
used for erosion. Every image do the erosion, have to convert it into black and white image before
it erode. This is because to make the process more accurate to separate the object in the image.
After the image was convert into black and white, ones (4) and ones (6) act as square of structure
element for erode the image to get every object. The square of structure element was selected
because based on the black and image, the object was display was big, so if the object is erode a
little the shape still can show clearly. One (6) square of structure element was clearly erode the
image or separate the object individually while the one (4) square of structure element was show
some of the object still link together. To get a RGB erosion, combine the erosion image by one (6)
and the original image.

For second section is learn about dilation. Dilation produces an image that is same shape
as the original but in a different size. It also mean that, dilation is stretches or shrinks the original
figure or it can be say that bold the object. The structure element was used too, for the system to
know the way to bold the object. Figure 8 the word smile was bold using ones (4). If the structure
element was used too big, the object might bold over like Figure 9.

In the section 3, both erosion and dilation was used to get the perfect shape of the object.
If the structure element was not used perfectly used or use either one dilation or erosion, the object
might get with a little bit of noise or white dot here and there, but, the biggest object still the shape
of the object. For example: Figure 12, which the croton.png showing shape with other objects
shape too. If this was happen, region props was used to check the object then ignore all the object
except the biggest one. Hence, the actual shape of the object can be obtained. Figure 14 was
showed perfect shape of the object, because the pattern of the object was low. This mean the pattern
is almost same color convert into black and white image. Figure 17 was one of nice the example
for combine erosion and dilation together. Whether the image was a little bit noise, but does not
show very clearly compare to Figure 15. This process called imclose( ), in this process imdilate
was used first, because to shrinks the object. This to prevent the pattern of the object affect the
results. Then erosion was used for constrict back to the original size. The structure element was
used in this 2 process was same. This is because the main point is maintain the original shape while
fill the pattern of the object.

6.0 CONCLUSION

After completing this lab session, our group is more familiar to the basic morphological
operation especially dilation and erosion. It is typically applied to binary images, but there are
versions that work on grayscale images. The basic effect of the operator on a binary image is to
gradually enlarge the boundaries of regions of foreground pixels. Thus areas of foreground pixels
grow in size while holes within those regions become smaller. While the erosion is one of the two
basic operators in the area of mathematical morphology, the other being dilation. It is typically
applied to binary images, but there are versions that work on grayscale images. The basic effect of
the operator on a binary image is to erode away the boundaries of regions of foreground pixels.
Thus areas of foreground pixels shrink in size, and holes within those areas become larger. After
that, we successfully applying dilation and erosion method for certain applications such filling the
holes contained in an object to complete the task given in the lab sheet.

Potrebbero piacerti anche