I am trying to find the the largest object in an image and remove any other objects in the image that are smaller than it.
This is what I have but I cannot get it to work.
l=bwlabel(BW);
%the area of all objects in the image is calculated
stat = regionprops(l,'Area','PixelIdxList');
[maxValue,index] = max([stat.Area]);
%remove any connected areas smaller than the biggest object
BW2=bwareaopen(BW,[maxValue,index],8);
subplot(5, 5, 4);
imshow(BW2, []);
I am working with digital mammograms such as these. I am trying to remove all objects from the image except for the breast region.