How do I measure the area of objects in a binary image, to be passed into the function bwareafilt?

4 ビュー (過去 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.

採用された回答

Walter Roberson
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:
  • 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')
  2 件のコメント
Stewart Tan
Stewart Tan 2019 年 9 月 22 日
編集済み: Stewart Tan 2019 年 9 月 22 日
@Walter Roberson thank you! regionprops() does the job!
darova
darova 2019 年 9 月 22 日
Please accept the answer
Walter will lose his reputation without your help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by