Effacer les filtres
Effacer les filtres

How to calculate euclidean distance between two feature vectors

24 vues (au cours des 30 derniers jours)
Sumit Vaise
Sumit Vaise le 16 Fév 2018
I have a vector vec1 which hold features of two images (For e.g. Img1 features in first row and second image feature in 2nd row) of size 2x2559. Similar to this other vector vec2 holding feature of same size. Now I need to find the euclidean distance between the two vectors so that i can find how similar the two images are, one from vec1 and vec2 are?
i tried:
calculating distance row wise:
Dist = sqrt(sum((vec1-vec2).^2,2));
Dist = pdist2(vec1,vec2,'euclidean')
Is this the right approachto find the euclidean distance?
  1 commentaire
Awais Khan
Awais Khan le 1 Mar 2020
i you known approch of finding eclidean distance, then please share it, i am facing same issue.

Connectez-vous pour commenter.

Réponses (2)

Jos (10584)
Jos (10584) le 16 Fév 2018
Take a look at * norm*
EuclideanDistance = norm(vec2-vec1, 2)

Guillaume le 1 Mar 2020
"Is this the right approachto find the euclidean distance?"
Depends on which euclidean distance you're trying to calculate.
Both of your expressions consider each row of vec1 and vec2 as the coordinates of a point in N-D space (N = 2559) and calculate the euclidean distance between the two points thus defined in vec1 and in vec2. The only difference between the two expressions is that your first one calculate the distance between point 1 (first row) of vec1 and point 1 (first row) of vec2, then between point 2 (2nd row) of vec1 and point 2 of vec2, resulting in a 2x1 distance, whereas your 2nd expressions calculates distance between each combination of points (1-1, 1-2, 2-1, 2-2), resulting in a 2x2 matrix (whose diagonal will be 0).
If that's what you meant to calculate then you're better off using your first expression, it'll be faster.


En savoir plus sur Feature Detection and Extraction dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by