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?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2020-3-16
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!