How to display the two biggest blobs in terms of area?
8 views (last 30 days)
I have a binary image 'i' which I have attached here. From this image, I want to find the two biggest blobs in terms of area. When I tried this code, I am able to find the biggest blob which I have attached and the next biggest blob is removed.
I tried to use the bwareafilt() but MATLAB R2013a does not support it. Kindly help me to display the next biggest blob.
David K. on 22 Jul 2019
In the line
you are finding the biggest by looking at the first index in a sorted array. So to get the second biggest you do
Then you can combine them simply by doing
twoBiggest = biggestBlob | secondBlob;
This is because both blobs are binary - 1s and 0s - so by doing an OR operation it makes every white part in both images seen in both images.
More Answers (1)
Image Analyst on 22 Jul 2019
It'w very bad practice to call your image i (the imaginary variable). Call it binaryImage, mask, or BW instead. You might want to call imclearborder() to get rid of that outer blob, unless you want it.
mask = imclearborder(mask);
I don't believe you need to use
because ismember() will return a logical image already.
Other than that, David's solution should work.