Area measurement of image objects using regionprops

17 views (last 30 days)
I have 10 similar images where all the image have 5 objects. I need to find areas of objects.
I have converted grayscale image to binary and found 5 objects. Then I have used regionprops function to find areas of 5 objects.
Issue: while using regionprops, the order of objects are changing image to image.
How to fix this? Please suggest me any ideas.
Thanks in advance.
  4 Comments
Walter Roberson
Walter Roberson on 3 Jan 2020
What factors do you look at in order to determine which object is which? For example are they different shapes that are fairly consistent between the images? If so then you might be able to use properties such as ecentricity or object orientation. Do they differ by grayscale intensity? If so then if you label the binary image and pass that label image in along with the grayscale image, you can ask regionprops for values such as the average intensity for each blob.
Yuvaraj Venkataswamy
Yuvaraj Venkataswamy on 3 Jan 2020
Edited: Yuvaraj Venkataswamy on 3 Jan 2020
I have attached one image for example.
I need the areas of object in that order (attached image).
But regionprops gives areas value of random object in the image. I mean the order is random.
Thank you so much for your help in advance.

Sign in to comment.

Accepted Answer

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy on 3 Jan 2020
@Walter Roberson I got it. Thank you so much!.

More Answers (1)

Walter Roberson
Walter Roberson on 3 Jan 2020
regionprops does not return the centroids in a random order.
img = imread('Screenshot_2020-01-03-14-02-07-279_com.android.chrome.png');
bw = imclearborder(img(:,:,1) > 5);
props = regionprops(bw,'centroid');
cents = vertcat(props.Centroid);
imshow(bw)
text(cents(:,1), cents(:,2), string(1:size(cents,1)).');
You will see that the order starts from the top left and goes down and to the right.
It is not difficult to get close to the ordering you expect:
props = regionprops(bw.', 'centroid');
cents = fliplr(vertcat(props.Centroid));
imshow(bw)
text(cents(:,1), cents(:,2), string(1:size(cents,1)).');
You will find that the numbering of 5 and 6 is reversed. If you look carefully, you will notice that the centroid for the 5th one (labeled 6 by the algorithm) is just slightly below the others in the same row. The objects are generally labeled according to the left-most edge of them, and because the transpose of that object is just slightly further in than the next object, the ordering is not exactly what you would expect.
Remember that you can take the array of centroid locations and sort it according to any criteria you feel is appropriate, and use the indexing from that to re-order the struct array returned by regionprops.
For example you could construct an array of seed locations, of nominal centroids for the objects. Then you can use pdist2() between the nominal centroids and the reported centroids, and min() to find the closest in each case.

Community Treasure Hunt

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

Start Hunting!