MATLAB Answers

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

2 views (last 30 days)
Maura Monville
Maura Monville on 18 Jul 2019
Commented: Maura Monville on 19 Jul 2019
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,


Matt J
Matt J on 18 Jul 2019
The code you've attached returns an error. Since the only important line is,
stats = regionprops('table',BW,'Area','FilledArea','ConvexArea','Centroid',...
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.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 19 Jul 2019
Because I don't have R2019b, I had to run a somewhat modified version of the code
% Get Area Features
stats = regionprops('table',BW,'Area','FilledArea','ConvexArea','Centroid',...
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

  1 Comment

Maura Monville
Maura Monville on 19 Jul 2019
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,

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by