Finding neighbors of an object from labeled image

Asked by Philip on 1 Apr 2011
Latest activity Answered by David Young on 1 Apr 2011

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 Comments

Philip

Products

No products are associated with this question.

1 Answer

Answer by David Young on 1 Apr 2011

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);

0 Comments

David Young

Contact us