I am trying to find circularity for my shape feature requirement in MRI image classification. I have used the matlab function REGIONPROPS to find area and perimeter and the circularity formula: 4*pi*area/(perimeter)^2.
My problem is i am getting perimeter as 0 value for many regions in an image. Then circularity will become infinite. I have attached a screenshot of perimeter values i am getting for a single image. Someone please suggest me how to calculate circularity in such case???

 Accepted Answer

Mohammad Abouali
Mohammad Abouali on 2 Dec 2014
Edited: Mohammad Abouali on 2 Dec 2014

0 votes

does it have to be circularity?
Can you replace circularity with the ratio between major/minor axis length?

5 Comments

The research paper i am following considered area, perimeter, circularity as shape features.
Is major/minor axis length is also a shape feature??
Yes they are and they are calculated by regionprops. the ratio of that can tell you if the object is elongated or not. However this is not exactly the same as circularity. Because circularity is affected by how jaggedy the permitters are.
So if you have a very circular looking island but with a lot of Jaggedy permitter, actually the circularity goes down; since the length of permitter is increasing. Although it looks circular enough. In that case minor/major axis ratio is better.
Having said this, it means that they are not exactly the same. So that's why I asked if you can change circularity to minor/major ratio.
Thank you...
Why this function is giving so many zeros for perimeter?? also the size of area and perimeter array is different for different images. This will create problem in creating train and test feature matrix for various images as the size will be different.(according to the area and perimeter array for the image)
The sizes are in pixels. So if your images don;t have the same spatial pixel size then 1pixel in first image could refer to 1meter, in the second image one pixel refers to 10meter (well the numbers are just examples).
So the sizes never come out exactly the same.
But why it is giving too many zeros. I don't know. I have to check the image and then perhaps I may find out.
This is one of the image for which i am calculating perimeter.
And permiter(97x1) matrix is likewise

Sign in to comment.

More Answers (1)

What is the area of the blobs that have zero perimeter? Is it 1? Like 1 pixel? If so, maybe you just don't want to consider those. You can use bwareaopen() to filter out tiny things. By the way, I use the inverse of your equation.
allAreas = [measurements.Area];
allPerimeters = [measurements.Perimeter];
circularities = allPerimeters .^ 2 ./ (4 * pi * allAreas);
Of course zero perimeter is not a problem there.

11 Comments

By the way, you shouldn't call regionprops() twice. Just get everything all in one shot:
measurements = regionprops(logical(BW), 'Area', 'Perimeter');
yes u r right i am getting the same thing.
wherever perimeter is 0 its corresponding area values is 1.
OK, so like I thought, the solution is to call bwareaopen(binaryImage, 1) to get rid of pixels that are of size 1 or less. Personally I'd use a min blob size of a few hundred.
Attach your script if you want me to try it. Also, im2bw() is usually not good at picking thresholds in my experience. Anyway, you probably need to call imfill(binaryImage, 'holes') after you call im2bw().
thank you so much..
I have used bwareaopen(binaryimage,2), now it is not showing all the regions whose area is 1 and perimeter is 0 earlier. This is right??
Where's your script so I can try it?
BW = im2bw(Im, map, 0.5);
BW2=bwareaopen(BW,2);
% Calculating area feature of the image
ar = regionprops(BW2, 'area');
area = cat(1, ar.Area);
area = area(1:18);
area=reshape(area,1,18);
% Calculating perimeter feature of the image
pm = regionprops(BW2, 'perimeter');
perimeter = cat(1, pm.Perimeter);
perimeter = perimeter(1:18);
perimeter = reshape(perimeter,1,18);
% Calculating circularity feature of the image
for i = 1:18
circ(i) = ( 4 * 3.14 * area(i) / ( perimeter(i) ^2));
end
circ = reshape(circ,1,18);
Feature_Vec = [area,perimeter,circ];
i have considered only 18 elements because different images are giving different sized area arrays and feature vector dimension should be same for all images.
That's a poor decision.
And why didn't you take my advice on how to calculate things:
measurements = regionprops(labeledImage, 'Area', 'Perimeter');
allAreas = [measurements.Area];
allPerimeters = [measurements.Perimeter];
circularities = allPerimeters .^ 2 ./ (4 * pi * allAreas);
Thank you very much... This labelled image is a grayscale image??
It's an integer valued image. You can display it as a grayscale image if you want
imshow(labeledImage, []);
Or you can pseudocolor the blobs and show that:
% Assign labeled blobs rainbow colors.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
imshow(coloredLabels);

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!