Segmenting objects from a threshold image
2 views (last 30 days)
Show older comments
I have thresholded an image using thresholder app in Matlab and converted the output for an image to black and white. AS a result I got the following output,
Now what I need to do is to isolate the specific type of square in the thresholded image from above image: I want my output to be as follows
I have tried bwareafilt(mask, [minArea maxArea]); command but that dosen't give optimal solution, more on that is here https://www.mathworks.com/matlabcentral/answers/676728-how-to-implement-helping-functions-for-counting-lego-blocks-in-image
Please follow comment section in above link to understand the problem of using bwareafilt command.
Is there anyone who knows solution for how to tackle this problem.
Thank You in anticipation.
3 Comments
Accepted Answer
Image Analyst
on 5 Dec 2020
"Based on the size, I want the smallest blob's count" <== If by count you mean area in pixels of the smallest blob in the segmented image, you can do this:
smallestBlob = bwareafilt(maskBlue, 1, 'smallest');
areaInPixels = nnz(smallestBlob)
3 Comments
Image Analyst
on 5 Dec 2020
With an image that is millions of pixels, it's highly unlikely that you will have two blobs with the same area. If you see that happening, I'd like to see the original image and mask image. However there is a way to do it.
% Measure areas of all blobs:
props = regionprops(mask, 'Area')
% Get all the areas into a double vector
allAreas = [props.Area];
% Find the smallest area, in pixels.
minArea = min(allAreas)
% Count the number of blobs that have the minArea exactly.
blobCount = sum(allAreas == minArea) % Will be 1 in almost every case unless you've synthetically created an image with known areas.
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!