MATLAB: Deleting objects from a binary image.

digital image processingimage processingImage Processing Toolbox

Hello everyone. I have a binary image with different objects. In the image I want to remove 5th, 13th, and 20th objects. How can I remove it. Thnks.

Best Answer

L = bwlabel(bw); %where bw is your binary image
bw2 = bw; %copy of binary image
bw2(L==5) = 0; %deletes the 5th object