- 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?
2 views (last 30 days)
Show older comments
So i have a binary image below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239169/image.png)
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 Comments
Accepted Answer
Walter Roberson
on 22 Sep 2019
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 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!