MATLAB: I’ve divided the image into various regions. Now i need to find centroid of each region so that i can calculate RGB components of the centroid i’ve found. Im unable to find the cenroid of each region.

image processing

I've divided my image into various regions. Now i need to find centroid of each region so that i can calculate RGB components of the centroid i've found. Im unable to find the cenroid of each region. I divided my image 'b' into regions and wrote the following to find the centroid of the first region.
This is what i wrote and got as result.
stats=regionprops(b(:,:,1),'centroid')
stats =
182x1 struct array with fields:
Centroid
I am unable to understand how to identify the centroid so that i can further work with it. I am new to matlab.Please help

Best Answer

  • cents(32).Centroid %32nd centroid


    Or you can convert to a cell array (I recommend):
    cents = {stats(:).Centroid}.';
    Now each element in cents will contain the centroid:
    cents{32} %32nd centroid
    You can also concatenate them into a regular array
    cents = cell2mat(cents);
    cents(32,:) %32nd centroid