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!