Finding neighbors of an object from labeled image
3 次查看(过去 30 天)
显示 更早的评论
I have used segmentation and labelling techniques to assign each object within an image a unigue number. For example, the sky will be given label 1, a tree may be given label 2, a person label 3, the ground label 4, and so on...
What I would like to do now is grab all the labels directly neighboring a specific object. For example, if I select the object of interest as label 3 (the person), I want to end up with a list of all the objects that the person directly neighbors. This would be the sky, and the ground (labels 1 and 4), but not the tree (label 2) as this is separated from the person.
Does anyone know of any good efficient methods for achieving this?
Thanks in advance!
0 个评论
回答(1 个)
David Young
2011-4-1
One possibility:
% assume labelled array is called "labelled"
label = 8; % label of object to find neighbours of
object = labelled == label;
se = ones(3); % 8-connectivity for neighbours - could be changed
neighbours = imdilate(object, se) & ~object;
neighbourLabels = unique(labelled(neighbours));
disp(neighbourLabels);
1 个评论
Alaa
2016-3-1
please,How can improve this to find each cell the number of neighbours cells of corneal cells to calculate hexagonality coefficient (pleomorphism) of cells. thanks in advance.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!