how to find distance between two points in an image

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 日

4 投票

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 件のコメント

sindhu c
sindhu c 2016 年 1 月 16 日
thank you a lot sir ! it works as expected.
Meghashree G
Meghashree G 2016 年 1 月 18 日
sir,if at all i want to find the position of dot of i in the above image(i.e whether the dot is towards the left/right/straight),how to find it?
Image Analyst
Image Analyst 2016 年 1 月 18 日
One way is to call regionprops() to get the centroids of the two blobs. The dot of the i will have a lower y value of its centroid than the body of the i.
Meghashree G
Meghashree G 2016 年 1 月 18 日
sir,this is what i did to get the centroids,
clc;
BW = imread('i1.png');
s = regionprops(BW,'centroid');
centroids = cat(1, s.Centroid); imshow(BW)
hold on
plot(centroids(:,1),centroids(:,2), 'b*')
hold off
Now what to do?Please help me.. i dint get the last part of your answer
Image Analyst
Image Analyst 2016 年 1 月 18 日
Isn't centroids a 1-D vector?
if centroids(2) < centroids(4)
% Blob #1 is the dot, so do something.
else
% Blob #2 is the dot, so do something.
end
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 投票

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?

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by