Follow by Email

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

5 comments:

vishal said... Reply to comment

sir,this error is coming....plz help..thnx in advance..


??? Assignment has more non-singleton rhs dimensions than non-singleton
subscripts

Error in ==> dil at 10
D(i,j)=sum(B&C(i:i+6,j));

AMAL IT said... Reply to comment

how can get link explain bwareaopen in same way.

Sam Sung said... Reply to comment

Do you have the c++ code for example 2?

Theo said... Reply to comment

how about for grey level images?

Ali Arslan said... Reply to comment

thanks man. you are number one

Enjoyed Reading? Share Your Views

Previous Post Next Post Home

Link

Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com