Matlab – Dilation and Erosion

In digital image processing, you must understand on dilation and erosion. Dilation adds pixels to the boundaries of objects in an image. On the other hand 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. In the morphological dilation and erosion operations, the state of any given pixel in the output image is determined by applying a rule to the corresponding pixel and its neighbors in the input image. The rule used to process the pixels defines the operation
as a dilation or an erosion.

Now take a look at the example Matlab code for dilation and erosion. The Matlab code is very simple since dilation and erosion has their own special command. We use imdilate and imerode.

 

a=[0 0 0 0 0 0 0 0 ;…
0 0 0 1 1 1 1 0;…
0 0 0 1 1 1 1 0;…
0 1 1 1 1 1 1 0;…
0 1 1 1 1 1 1 0;…
0 1 1 1 1 0 0 0;…
0 1 1 1 1 0 0 0;…
0 0 0 0 0 0 0 0];

 

b=[ 1 1 1;…
1 1 1;…
1 1 1];

 

c=imerode(a,b);
d=imdilate(a,b)

 

figure(1),imshow (a);
figure(2),imshow (c);
figure(3),imshow (d);

 

That’s all. Very simple. Thank You

 

Leave a Reply

Your email address will not be published. Required fields are marked *