How can I store x y coordinates of centroids that are found using region props within a loop?

3 views (last 30 days)
s = regionprops(L, 'Area', 'Centroid', 'BoundingBox'); % code
I have found these properties using region props.
I need to find a way of storing the x and y coordinates from a loop for use later on and if they can be numbered with the iteration number too would be great.

Answers (1)

Christiaan
Christiaan on 11 Mar 2015
Dear Mauricio,
As you stated finds the line (stat = regionprops(I,'centroid');) all the centroids in the image. (here 'I' is the image) Now the values of the centroids are stored in this variable. An example to extract those codes can be:
for i=1:length(stat)
x_centroid(i) = stat(i).Centroid(1);
y_centroid(i) = stat(i).Centroid(2);
end
For more information about plotting the centroids, you coud have a look at a previous post of mine here.
Kind regards, Christiaan

Community Treasure Hunt

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

Start Hunting!