How to detect the circle-ish shape in an image

I have this image:
And I wanted to detect the circle shape from it. So simple enough I used regionprops and area
CC = im2bw(temp);
L = bwlabel(CC);
props = regionprops(L, 'Area');
idx = find( [props.Area] == max([props.Area]));
BW2 = ismember(L,idx);
The above produced image BW2 singled out the circle perfectly, but it does not work every time.
When I applied the same code to this image(which is another sample in my dataset):
It picked up not the circle but the big blob connected component in the middle. Which makes sense as it has the biggest area.
Judging by this I found that area is not the best option.
How can I single out the circle type shape in my images?
Thank you

 Accepted Answer

Compute the circularities:
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area', 'Perimeter');
allAreas = [measurements.Area];
allPerims = [measurements.Perimeter];
circularities = allPerims .^ 2 ./ (4*pi*allAreas);
Look at my Image Segmentation Tutorial to find out how to use ismember() to extract out round blobs. Round blobs will have a circularity less than about 2 or 3 or so.

4 Comments

Thanks for the reply and for the link to your tutorial. Great stuff there.
you mentioned looking at your tutorial to get an idea on how to extract the blobs using ismember. There you used:
% Now let's get the nickels (the larger coin type)
keeperIndexes = find(allBlobAreas > 2000); % Take the larger objects.
% Note how we use ismember to select the blobs that meet our criteria.
nickelBinaryImage = ismember(labeledImage, keeperIndexes);
Here KeeperIndexes is using find on a variable that exists within regionprops and the data is populated already for all the labeled items in the image.
The same is not true for circularities that I compute using perimeters and areas.
But still can using this work even though regionprops does not know what circularities is
keeperIndexes = find(cicularities < 2);
% Note how we use ismember to select the blobs that meet our criteria.
blobs= ismember(labeledImage, keeperIndexes);
Thank you
Try circularities instead of cicularities.
Yes sorry that was a stupid typo. But circularities does not seem to solve this. It is also detecting small circles. I only want to single out the large circle ish shape.
For example from this:
..
I am given this with circularities < 2 (even with < 3 does not work) .. ..
..
You need to combine both criteria:
keeperIndexes = find(cicularities < 2 & allBlobAreas > 2000);

Sign in to comment.

More Answers (0)

Categories

Find more on Particle & Nuclear Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!