Checking whether two point are on same object
조회 수: 3 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Image Analyst
2015년 12월 22일
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
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!