필터 지우기
필터 지우기

calculation of circularity using area and perimeter obtained by regionprops

조회 수: 1 (최근 30일)
Tian Tian
Tian Tian 2017년 8월 21일
댓글: Image Analyst 2017년 8월 22일
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.

답변 (2개)

KSSV
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
Tian Tian
Tian Tian 2017년 8월 22일
편집: Image Analyst 2017년 8월 22일
Thank you very much. Now I write my code as:
cc = bwconncomp(bw, 4);
area = regionprops(cc,'area');
perimeter = regionprops(cc,'perimeter');
for i = 1: cc.NumObjects
circularity (i) = (4*pi*aggre_areas (i))/((aggre_perimeter (i))^2);
end
And the error is: Undefined operator '*' for input arguments of type 'struct'. Do you know how to multiple values in struct field? Or am I wrong to understand it?
Many thanks.

댓글을 달려면 로그인하십시오.


Image Analyst
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;
  댓글 수: 2
Tian Tian
Tian Tian 2017년 8월 22일
Many thanks! It works well! Just have one quick question, if I want to output circularities in the table using: stats = regionprops('table')
should I convert it to struct array? E.g. structArray = cell2struct(circularities, Circularity)? Thank you.
Image Analyst
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by