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

조회 수: 8 (최근 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')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by