Why bwlabel and regionprops use different index scheme?
Show older comments
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)
Image Analyst
on 9 Jul 2017
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');
Categories
Find more on Region and Image Properties in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!