calculation of circularity using area and perimeter obtained by regionprops
2 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone, I am currently meeting a problem of "Undefined operator '*' for input arguments of type 'struct'." when I tried to caluclate circularity based on circularity = (4*pi*areas)/(perimeter^2), where areas and perimeter are obtained by regionprops. Could anyone help me to solve this problem? Any answer is welcome. Thanks a lot.
0 件のコメント
回答 (2 件)
KSSV
2017 年 8 月 22 日
The output of regionprops is a structure. You should know what is a structure to extract fields from it...read about structure first. http://www.mathworks.in/help/matlab/ref/struct.html. Check the below example code.
BW = imread('text.png');
s = regionprops(BW,'centroid');
In the above s is a structure array with 88 field values of Centroid. I can extract the i'th value of centroid using
s(i).Centroid
Like wise, check your structures field names and extract the respective filed values.
1 件のコメント
Image Analyst
2017 年 8 月 22 日
編集済み: Image Analyst
2017 年 8 月 22 日
Try this (no for loop needed):
cc = bwconncomp(bw, 4);
props = regionprops(cc, 'Area', 'Perimeter);
allAreas = [props.Area]
allPerimeters = [props.Perimeter];
circularities = (4 * pi * allAreas) ./ allPerimeters .^2;
You probably should look at my Image Processing Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
2 件のコメント
Image Analyst
2017 年 8 月 22 日
No, you don't need to. I think you can do something like
allAreas = stats{'Area'};
or something like that to extract the areas from the table into their own column vector.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!