Info

This question is closed. Reopen it to edit or answer.

which method to choose to discard binary images that do not contain clean/clear shapes

1 view (last 30 days)
for a project i am working i am generating several images but I would like to only keep images that are similar to the ones in the links below
all these images are having a kind of clear shape on them, and i am seeking how to distinguish them from images like the following
I need a way to distinguish the outcome and if it is going to be like the second images then not to save it at all.
which way do you believe is the optimal in that scenario?

Answers (1)

Mark Sherstan
Mark Sherstan on 15 Dec 2018
Edited: Mark Sherstan on 15 Dec 2018
Give this a try :) I based it on perimeter. The jagged shapes will have a very large perimeter compared to the smooth more distinguished shapes.
imgFolder = fullfile('images');
imgs = imageDatastore(imgFolder);
numOfImgs = length(imgs.Files);
figure(1)
for ii = 1:numOfImgs
I = imread(imgs.Files{ii});
stats = regionprops(I,'Perimeter');
subplot(3,2,ii)
imshow(I)
if stats(1).Perimeter < 5000
title('Yes')
else
title('No')
end
end
  1 Comment
Image Analyst
Image Analyst on 15 Dec 2018
Edited: Image Analyst on 15 Dec 2018
The perimeter threshold should be a fraction of the image width. But even then, a smooth object could have a large perimeter. I probably would have tried computing the circularity
circularity = perimeter .^ 2 / (4*pi*Area);
and I'd also measure the solidity, which is the percentage of the convex hull that the blob is. Smooth blobs will have a lower solidity if they are fairly convex (but not for a case like a snake winds up and down the image).
You could also look at the Sørensen–Dice coefficient between a smoothed version of the blob and the actual blob. You could use activecontour() to get a smooth version, or blur then threshold.
There are lots of metrics you could use, and you may well have to use a combination of them, or do voting, or build a model from all of them.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!