![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172505/image.png)
how to find distance between two points in an image
13 views (last 30 days)
Show older comments
sindhu c
on 16 Jan 2016
Commented: Walter Roberson
on 29 Mar 2018
hello! i have an image something like this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153334/image.png)
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!
<<
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/153335/image.png)
>>
0 Comments
Accepted Answer
harjeet singh
on 16 Jan 2016
try to use this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172505/image.png)
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 Comments
More Answers (1)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!