how to find distance between two points in an image

조회 수: 12 (최근 30일)
sindhu c
sindhu c 2016년 1월 16일
댓글: Walter Roberson 2018년 3월 29일
hello! i have an image something like this.
how to obtain the distance between the dot above i and the line in i? the image of i is attached below.
please help me with the code... thank you!
<<
>>

채택된 답변

harjeet singh
harjeet singh 2016년 1월 16일
try to use this
img=imread('i2.png');
figure(1)
imshow(img)
hold on
[lab,num]=bwlabel(img);
[r,c]=find(lab==1);
[r1,c1]=find(lab==2);
D = pdist2([r c],[r1 c1],'euclidean'); % euclidean distance
[r2,c2]=find(D==min(D(:)));
point_1=[r(r2) c(r2)];
point_2=[r1(c2) c1(c2)];
plot([point_1(2) point_2(2)],[point_1(1) point_2(1)],'r')
hold off
distance=sqrt( (point_1(1)-point_2(1)).^2 + (point_1(2)-point_2(2)).^2)
distance =
42.1070
  댓글 수: 7
aaditya CHANDEL
aaditya CHANDEL 2018년 3월 29일
distance unit?
Walter Roberson
Walter Roberson 2018년 3월 29일
The distance unit is pixels.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 16일
  댓글 수: 1
sindhu c
sindhu c 2016년 1월 16일
thank you sir! in both of the above links we need to know column and row vectors, how to find the position vectors for dot and line in the above image attached?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Segmentation and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by