I have 12 objects and only 10 objects have a yellow dot inside it .How to extract the ids of the objects with only the yellow dot?
3 views (last 30 days)
Show older comments
Joel Nunes
on 16 Mar 2020
Answered: Image Analyst
on 16 Mar 2020
The yellow dot is not at the centeroid of the object. I have created a yellow mask for each of the objects, but i am struggling to create a for loop to extract the ids of the objects with only the yellow dot inside of it
0 Comments
Accepted Answer
Image Analyst
on 16 Mar 2020
Segment the objects. Then segment the yellow dots. Then label the objects and use that labeled image to get a list of blobs that have the dot, and call unique. Then call ismember() to get the mask with only the yellow dots
% Fill yellow holes in the objects.
objectMask(yellowHoleMask) = true;
% Fill the objects in case the yellow was in a "lake" in the blob and didn't actually touch the blob itself.
objectMask = imfill(objectMask, 'holes');
% Label each blob.
[labeledObjects, numBlobs] = bwlabel(objectMask);
% Find labels with yellow dots in them
indexesWithYellow = unique(labeledObjects(yellowHoleMask))
% Extract only those blobs that have a yellow dot in them
objectsWithYellowInside = ismember(labeledObjects, indexesWithYellow); % Creates a binary image
If you want the original blobs without the yellow spot being filled in them (so they'll have a hole in them) then you'll need a slight modification, as this code will give filled blobs where the yellow and containing blob are all one blob. If that's the case, then supply your two binary images.
0 Comments
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!