I would be grateful to receive some example of usage of builtin function 'regionprops'

1 次查看(过去 30 天)
Dear MatLab Experts,
I would greatly appreciate your help at understanding how to use the output of builtin function 'regionprops'
My understanding is that it would output a scalar value for each selected property for each connected component.
I have a set of closed curves that I convert to binary masks. The attached zipped archive contains some of such curves.
Each closed curve is descrived by the ordered coordinates in a text file.
Each curve contain only one connected component.
However, when i call 'regionprops' I get a vector of values for each feature I selected.
For instance, how can I have 255 'Area' values and 255 centroid coordinate pairs?
I have attached my script 'Get-Collimator_Features.m' that calls builtin function 'regionprops'.
How can I reduce a vector to a single scalar value, for instance for the Area, etc...?
Some correct usage examples of 'regionprops' would be very appreciated.
Thank you very much.
Best regards,
maura
  2 个评论
Matt J
Matt J 2019-7-18
The code you've attached returns an error. Since the only important line is,
stats = regionprops('table',BW,'Area','FilledArea','ConvexArea','Centroid',...
'Circularity','Eccentricity','EquivDiameter',...
'MaxFeretProperties','MinFeretProperties','Orientation');
it would be better/simpler if you just attach BW in a .mat file so that we can test just that specific line of code.

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2019-7-19
Because I don't have R2019b, I had to run a somewhat modified version of the code
S=load('BWCurve.mat','CBW');
BW=S.CBW;
% Get Area Features
stats = regionprops('table',BW,'Area','FilledArea','ConvexArea','Centroid',...
'Eccentricity','EquivDiameter',...
'Orientation');
The result is
stats =
1×7 table
Area Centroid Eccentricity Orientation ConvexArea FilledArea EquivDiameter
__________ ________________ ____________ ___________ __________ __________ _____________
6.6497e+05 558.43 433.81 0.68914 -3.9677 1.0211e+06 1.0211e+06 920.15
This looks fine to me. I'm not sure what "vectors" you are referring to. Nevertheless, if you want to extract the 'Area" data from the table and put it in a separate numeric variable, you would do
Area=stats{:,'Area'}
  1 个评论
Maura E. Monville
Maura E. Monville 2019-7-19
You are right. I input the wrong variable to 'regionprops'.
After fixing my error I get the same answer as you did.
Thank you.
Kind regards,
Maura

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by