Checking whether two point are on same object

3 visualizaciones (últimos 30 días)
jack
jack el 22 de Dic. de 2015
Respondida: Image Analyst el 22 de Dic. de 2015
Hello guys,
I need your help in solving the following problem:
Given A binary image and two points p1,p2 on objects (object is a patch of 0's) and assume that the shape of there objects are polygons, check if p1 and p1 lies on the same object.
Thanks in advance.

Respuesta aceptada

Image Analyst
Image Analyst el 22 de Dic. de 2015
I'll assume you have a binary image called binaryImage, that uses a non standard definition of objects being black (0), and I'll assume you have two points p1 and p2 defined by coordinates (row1, col1), and (row2, col2). First you need to invert your image so that you have a standard image where the objects are white/true/1 and the background is black/false/0.
binaryImage = ~binaryImage;
Then you need to label the image so that each connected component will have it's own label ID number
labeledImage = bwlabel(binaryImage);
Now, to see if the two points are in the same region, simply get the value from the labeled image and compare them for equality
if labeledImage(row1, col1) == labeledImage(row2, col2)
% Point 1 and point 2 are in the same region.
else
% Point 1 and point 2 are in the different regions.
end

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by