Why imerode( ) is not giving intended results ?

6 views (last 30 days)
Kishor
Kishor on 18 Feb 2014
Answered: Jeff E on 18 Feb 2014
% MATLAB Code used by me , the output of this program is appended at the end % see the two unwanted white pixels in the last row of the eroded image
a=[0 0 0 0 0 0 0;0 1 0 1 0 1 0;0 1 0 1 0 1 0;0 1 0 1 0 1 0;0 1 1 1 1 1 0;0 0 0 1 0 0 0;0 0 0 1 0 0 0;];
b=[0 1;1 0 ];
a1=imdilate(a,b); a2=imerode(a,b); a3=imopen(a,b); a4=imclose(a,b);
subplot(2,3,1);imshow(a),title('Original image'); subplot(2,3,2);imshow(a1),title('Dilated image'); subplot(2,3,3);imshow(a2),title('Eroded image'); subplot(2,3,4);imshow(a3),title('Opened Image'); subplot(2,3,5);imshow(a4),title('Closed image');

Answers (2)

Iain
Iain on 18 Feb 2014
Its cause your filter isn't 3x3.

Jeff E
Jeff E on 18 Feb 2014
Some (all?) morphological functions make assumptions about the value of pixels beyond the border of the image in cases where the processing kernel extends outside the image.
For erosion: Pixels beyond the image border are assigned the maximum value afforded by the data type.
So, you can think of your image as having an infinite field of white pixels beyond its border. If you do not want this default behavior, use the PADARRAY function.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!