MATLAB Answers

How do I count objects in a binary image without taking into account pixel clusters smaller than a certain number?

조회 수: 5(최근 30일)
Gabriel Levis
Gabriel Levis 2020년 6월 9일
I am getting into image processing and am trying to count the number of fruit loops in an image (as attached). I used the color threshholder app to isolate the fruit loops and convert the image to binary, then I inverted the colors so that the background was white and the loops were black, but there was still a little bit of feedback remaining in the image in the form of small clusters of black dots. I tried using the bwareaopen function to remove them but it didn't affect the image. When I used bwlabel to try to count the number of objects, it returned a number much higher than the amount of fruit loops in the bowl, and seemed to have been counting the black dots as well. Was there any step that I might've missed? Also, would there be a more conventional/easier was to go about counting the fruit loops?
  댓글 수: 2
Mohammad Sami
Mohammad Sami 2020년 6월 10일
You can use the function bwpropfilt to remove the objects that are smaller then a certain threshold.
https://www.mathworks.com/help/images/ref/bwpropfilt.html

댓글을 달려면 로그인하십시오.

답변(1개)

Harikrishnan Balachandran Nair
Harikrishnan Balachandran Nair 2021년 8월 16일
편집: Harikrishnan Balachandran Nair 2021년 8월 16일
From my understanding, you are having an issue with counting the number of objects in a binary image. Connected components in a binary image is calculated by finding the pixels of value one, which are connected according to the specified connectivity. Hence the background should be black, and object should be white. Inorder to remove spurious objects from the image , you can use the function 'bwareaopen' as given below :
bw2=bwareaopen(bw,P);
Here, the connected components with less than 'P' pixels are removed from the image.
You can also try extracting objects from the image by specifying the property using the 'bwpropfilt' as given below :
bw2=bwpropfilt(bw,'attrib','range');
Here, the connected components in bw having the property specified in 'attrib' within the specified 'range' are extracted. You can choose the 'attrib' and 'range' according to your application.

Community Treasure Hunt

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

Start Hunting!

Translated by