- use bwlabel() or bwconncomp() or regionprops() to find out how many blobs there are, and then pass 1 less as the number to keep with 'smallest'
- or you could do binimg - bwareafilt(binimg, 1, 'largest')
How do I measure the area of objects in a binary image, to be passed into the function bwareafilt?
6 次查看(过去 30 天)
显示 更早的评论
So i have a binary image below:

and what I want to do is to extract the two smaller rectangle-like object from the binary image using bwareafilt(). However, I'm required to input a certain range as required for bwareafilt() and i would like to know how to calculate the area of each object in the binary image before specifiying a range for bwareafilt(). In other words, I want to know if there is any built in function that returns the area of each object in the image. For now, i had to experiment with different range via hardcode where:
bw3 = bwareafilt(binimg, [100 30000]);
The range value of 100 to 30000 allows me to extract the two rectangles from the image, without the large one above. I'm looking for a method where i wouldn't have to exhaustively type in ranges, hoping to extract the wanted object from the image.
0 个评论
采纳的回答
Walter Roberson
2019-9-22
regionprops() with the 'Area' option.
However, there is another approach:
bwareafilt(binimg, 2, 'smallest')
If what you want to do is get rid of the 1 largest when you do not know how many blobs there are, then there are several approaches:
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!