MATLAB Answers


How to clear objects connected to the lower borederof the image?

There are 10 objects in my picture of varying sizes. two of them are connected to (contain) the lower boreder of an 80x80 image. The image is binary. I do not want to use bwareaopen.Plzzzzzzzz help. Thank You


Log in to comment.

2 Answers

Answer by Steve Eddins on 29 Mar 2013
 Accepted Answer

% Start by padding the image with 0s on the left, top, and right.
bw2 = padarray(bw,[1 0],0,'pre');
bw3 = padarray(bw2,[0 1],0,'both');
% Remove objects touching the border of the padded image.
bw4 = imclearborder(bw3);
% Remove the padded columns and padded row.
bw5 = bw4(2:end,2:end-1);

See my 18-Dec-2012 blog post.


will it remove all the objects connected to lower border only? coz imclearborder removes all the objects connected to all the borders! I want the ones which are connected to upper boreder to remain in the image.

Yes, it will remove only the objects connected to the lower border. That's the reason for the first two lines (padding the image) and the last line (removing the padded columns and row). Follow the link to my blog post for more explanation about this technique.

Log in to comment.

Answer by Anand
on 29 Mar 2013

You could use the imclearborder function.

There's a blog article by Steve Eddins about this topic too:

  1 Comment

thanks but it removes all the border connected objects. i wanna remove oly lower border connected ones

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!