Hello, I'm trying to delete the unwanted blobs in an image using their shape as criteria. I have already deleted the blobs that are bigger than the objects that I want to look for using a pixel count. In the example image that I attach you can see 5 blobs, I'd like to keep the 2 that are most similar to a circle and delete the rest. I have tried to do the following but didn't succeed. It is supposed to calculate the ratio of Perimeter/Area and delete the blobs that are above a defined value. Maybe it's a matter of element classes and mixing binary images with RGB, I'm quite a newbie with Matlab.
Daurat is a binary image that I use as mask
[labeledImage numberOfBlobs] = bwlabel(Daurat, 8);blobMeasurements = regionprops(labeledImage, Daurat, 'Area', 'Centroid', 'Perimeter', 'PixelList');areas(:,1) = [blobMeasurements.Area]if max(areas)>1500grans = uint8(bwareaopen(Daurat, 1500)); Daurat = Daurat-grans;[labeledImage numberOfBlobs] = bwlabel(Daurat, 8);blobMeasurements = regionprops(labeledImage, Daurat, 'Area', 'Centroid', 'Perimeter', 'PixelList');clearvars areas;areas(:,1) = [blobMeasurements.Area];subplot(2,2,4);imshow (Daurat,[])endper(:,1) = [blobMeasurements.Perimeter];r(:,1) = zeros(numberOfBlobs,1);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Doesn't work
for i=1:numberOfBlobs; r(i)=per(i)/areas(i) P=[blobMeasurements(i).PixelList]; if r(i)>0.3 Daurat(P)=0; end end clearvars labeledImage numberOfBlobs blobMeasurements;[labeledImage numberOfBlobs] = bwlabel(Daurat, 8);blobMeasurements = regionprops(labeledImage, Daurat, 'Area', 'Centroid', 'Perimeter', 'PixelList');clearvars areas;areas(:,1) = [blobMeasurements.Area];%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I don't know if I explained myself correctly, don't hesitate to ask for more info
Best Answer