Plz help me to find euclidean distance between two pixels within same image without using direct matlab command

2 件のコメント

Walter Roberson
Walter Roberson 2014 年 1 月 20 日
What is a "direct MATLAB command"? Even
3 + 5
is considered a command and invokes a MATLAB function ("plus")
Fahim Ahmed
Fahim Ahmed 2020 年 2 月 23 日
i guess he meant a matlab in-built command

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

 採用された回答

David Sanchez
David Sanchez 2014 年 1 月 20 日

0 投票

pix_1 = [p11,p12];
pix_2 = [p21,p22];
distance = sqrt( (p21-p11)^2 + (p22-p12)^2 );

10 件のコメント

aarti sawant
aarti sawant 2014 年 1 月 20 日
thanku David for that answer but can you please elaborate how to write complete for loop for the same??
Walter Roberson
Walter Roberson 2014 年 1 月 20 日
What complete for loop? You asked for euclidean distance between two pixels. That is a single distance.
If you want euclidean distance between groups of pixels, the method might be different.
aarti sawant
aarti sawant 2014 年 1 月 20 日
i just want alternative to bwdist in matlab
Walter Roberson
Walter Roberson 2014 年 1 月 20 日
編集済み: Walter Roberson 2014 年 1 月 20 日
For Euclidean distance transforms, bwdist uses the fast algorithm described in
[1] Maurer, Calvin, Rensheng Qi, and Vijay Raghavan, "A Linear Time Algorithm for Computing Exact Euclidean Distance Transforms of Binary Images in Arbitrary Dimensions," IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 25, No. 2, February 2003, pp. 265-270.
You can retrieve the paper and implement the algorithm.
Image Analyst
Image Analyst 2014 年 1 月 20 日
bwdist() does not really compute the distance between two pixels, like you asked initially. Not exactly. It computes the distance of all pixels in the background to the nearest object . It also produces an image where the pixel values are the distances of that pixel to the nearest foreground pixel. It does not produce a single number like imdistline().
aarti sawant
aarti sawant 2014 年 1 月 21 日
so if i want to replace bwdist() by some commands then what it should be??
Image Analyst
Image Analyst 2014 年 1 月 21 日
Like we've been telling you, use sqrt(). Period. In your initial question you said "two points" so you would not use bwdist which computes the distance between millions of points. There is no bwdist to replace because you are not using it.
aarti sawant
aarti sawant 2014 年 1 月 21 日
but if i want to compute distance between millions of points without using bwdist then how to implement it??
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
bwdist() does not compute distance between millions of points. bwdist() finds the points that are not part of objects, and calculates the distance from each point to the closest point that is part of some object.
If you want to operate on multiple points, then the small change to the formula already given is
distance = sqrt( (p21-p11).^2 + (p22-p12).^2 );
where the variables given there are all vectors.
If you want to calculate the distance of each point to every other point then you can use pdist() from the Stats toolbox.
William
William 2023 年 5 月 19 日
Doesn't the dist(W,P) function also help with this?

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

その他の回答 (1 件)

Geetika
Geetika 2014 年 1 月 21 日

2 投票

if you have two vectors with any number of point, for instance, x1=[1 2 3 4 5] and x2=[2 3 4 5 6], then Euc_dist = norm( x1 - x2 ) ;

Community Treasure Hunt

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

Start Hunting!

Translated by