Why bwlabel and regionprops use different index scheme?

Assuming a gray image im, and there are 7 connected regions:
label_map = bwlabel(im);
stats = regionprops(im, 'Area', 'BoundingBox', 'Image');
It is very odd that the region labeled by index of i in label_map is different from stats(i).Image. Can anyone explain why Matlab chooses such odd behavior?
Or is there any easy to get the Label (Index) map of regionprops? in stead of looping through all the regions to create such map?

Answers (1)

It doesn't. Anyway, you're not using either function correctly.
You're supposed to pass a binary image into bwlabel(), NOT a gray scale image.
You're supposed to pass the labeled image, or a binary image wrapped in logical() into regionprops() as the first argument, NOT the gray scale image.
Here is how you should call the two functions:
labeledImage = bwlabel(im);
stats = regionprops(labeledImage, 'Area', 'BoundingBox', 'Image');

Asked:

T C
on 9 Jul 2017

Answered:

on 9 Jul 2017

Community Treasure Hunt

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

Start Hunting!