Matlab code:- Dilation and erosion example:-
%input image given below in code save it as "finger.tif"
original=imread('finger.tif');
figure(1);
subplot(2,3,1);
imshow(original);
title('Original image');
%SE element B
se=strel('square',3);
%A erode B
A=imerode(original,se);
subplot(2,3,2);
imshow(A);
title('image after erode original with se');
%dilate with (A-B) and then B
A1=imdilate(A,se);
subplot(2,3,3);
imshow(A1);
title('result of (A-B)+B');
% Above result again dialed
A2=imdilate(A1,se);
subplot(2,3,4);
imshow(A2);
title('above image dilated again to fill gaps');
%Eroded with B
final=imerode(A2,se);
subplot(2,3,5);
imshow(final);
title('Final proceed image');
Input:- image :-
finger.tif
OUUPUT:-