MATLAB: How to clear objects connected to the lower borederof the image

binaryimage analysisimage objectsimage processingImage Processing Toolboximage segmentationimclearborderpadarray

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

Best 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);