Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Image Dilation without using 'imdilate' function


           In MATLAB, ‘imdilate’is the function that dilates the image using a structuring element. Let’s learn how this function works using some examples and codes.


MATLAB CODE:


Example 1:

A=[1 0 0 0 1; 1 0 1 0 0; 1 1 1 0 0;0 0 1 1 1];
%Structuring element
B=[1 0 0; 0 1 0; 0 0 1];
%Pad zeros on all the sides
C=padarray(A,[1 1]);
%Intialize a matrix of matrix size A with zeros
D=false(size(A));
for i=1:size(C,1)-2
    for j=1:size(C,2)-2
        %Perform logical AND operation
        D(i,j)=sum(sum(B&C(i:i+2,j:j+2)));
    end
end

display(D);

Example 2:
A=imread('text.png');
Original Image



A=im2bw(A);
%Structuring element
B2=getnhood(strel('line',7,90));
m=floor(size(B2,1)/2);
n=floor(size(B2,2)/2);
%Pad array on all the sides
C=padarray(A,[m n]);
D=false(size(A));
for i=1:size(C,1)-(2*m)
    for j=1:size(C,2)-(2*n)
        Temp=C(i:i+(2*m),j:j+(2*n));
        D(i,j)=max(max(Temp&B2));
    end
end

figure,imshow(D);

Dilated Image



Example 3:(Method 2)

A=imread('text.png');
A=im2bw(A);
%Structuring element
B=[1 1 1 1 1 1 1;];
C=padarray(A,[0 3]);
D=false(size(A));
for i=1:size(C,1)
    for j=1:size(C,2)-6
        D(i,j)=sum(B&C(i,j:j+6));
    end
end
figure,imshow(D);



Dilated image



























like button Like "IMAGE PROCESSING" page
Previous Post Next Post Home
Google ping Hypersmash.com