Calculate the distance between matched points

Hello,
I have two sets of matched points (matchedPoints1 and matchedPoints2, the size is 142x1 and the type is SURFPoints) and I want to calculate the distance between them. I tried the function pdist2() like this :
dist_matchedPoints=pdist2(matchedPoints1,matchedPoints2,'euclidean');
But I got the following error :
Error using cast
Unsupported data type for conversion: 'double'.
Error in pdist2 (line 250)
X = cast(X,outClass);
I don't really understand the meaning of this error message so can somebody help me to solve this problem ?
Thanks a lot.

5 comentarios

Adam Danz
Adam Danz el 16 de Jul. de 2019
Do you want to calculate the distance between matchedPoints1(n) and matchedPoints2(n) to create a vector of distances or do you want to calculate the distance between every point in matchedPoints1 and every point in matchedPoints2 to create a matrix of distances?
Théodore Keller
Théodore Keller el 16 de Jul. de 2019
I want to calculate the between every point in matchedPoints1 and every point in matchedPoints2 yes, so to create a matrix.
Adam Danz
Adam Danz el 16 de Jul. de 2019
Cool. See the last line of code in my answer using pdist2().
Théodore Keller
Théodore Keller el 16 de Jul. de 2019
Thank you Adam. Just one last thing, I got a 172 x 172 matrix, is that mean that there are 172 matched points and for example the 10 x 20 value is the distance between the 10th matchedpoints1 and 20th matchedpoints2 ? Is the distance in pixel ?
Adam Danz
Adam Danz el 16 de Jul. de 2019
Editada: Adam Danz el 15 de En. de 2020
Glad I could help!
From the documentation,
The output 'd' (in my example) is the pairwise distances,
returned as a numeric matrix.
If you do not specify either 'Smallest' or 'Largest', then
D is an mx-by-my matrix, where mx and my are the number of
observations in X and Y, respectively. D(i,j) is the distance
between observation i in X and observation j in Y. If
observation i in X or observation j in Y contains NaN, then
D(i,j) is NaN for the built-in distance functions.
If you specify either 'Smallest' or 'Largest' as K, then
D is a K-by-my matrix. D contains either the K smallest
or K largest pairwise distances to observations in X for
each observation in Y. For each observation in Y, pdist2
inds the K smallest or largest distances by computing and
comparing the distance values to all the observations in X.
If K is greater than mx, pdist2 returns an mx-by-my matrix.

Iniciar sesión para comentar.

 Respuesta aceptada

Adam Danz
Adam Danz el 16 de Jul. de 2019
Editada: Adam Danz el 16 de Jul. de 2019
The (x,y) point locations are stored in the "Locations" property of a SURFpoints object. If you are calculating the distance between matchedPoints1(n) and matchedPoints2(n), follow this example
%matchedPoints1 & matchedPoints2 are SURFpoints objects
distanceFcn = @(x1,x2,y1,y2)sqrt((x2-x1).^2 + (y2-y1).^2); %distance function
d = distanceFcn( ...
matchedPoints1.Location(:,1),...
matchedPoints2.Location(:,1),...
matchedPoints1.Location(:,2),...
matchedPoints2.Location(:,2));
% d(n) is the distance between matchPoints1.Location(n) and matchPoints2.Location(n)
To calculate the pairwise distance,
d = pdist2(matchedPoints1.Location,matchedPoints2.Location,'euclidean')

Más respuestas (0)

Categorías

Preguntada:

el 16 de Jul. de 2019

Editada:

el 15 de En. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by