Euclidean distance of adjacent pairs of matrix
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stewart Tan
el 16 de Ag. de 2019
Editada: Bruno Luong
el 17 de Ag. de 2019
So i have an example matrix
A = [10 20 30 45
32 94 21 15
67 33 22 54
13 27 89 73]
and i want to calculate the Euclidean distance between adjacent pairs of matrix A. In other words, each row in the matrix is a feature vector, hence the calculation is row-wise.
Pardon my english but I'm having issue understanding "adjacent pairs". Does it mean row1 with row2, row2 with row3 and row3 with row4 OR row1 with row2, row1 with row3 and row1 with row4 OR row1,row2,row3 and row4 all together?
4 comentarios
Guillaume
el 16 de Ag. de 2019
As I said in my answer, in order to have an adjacency relationship, you need a total ordering definition on your set (the feature vectors set). Now this is not my domain, but my understanding is that feature vectors can represent any property you choose. So, feature vector A(1) could encode the dominant colours of the image, feature vector A(2) could encode the orientation of lines in the image, and feature vector A(3) could encode whether or not there's a circle in the upper right corner of the image. How you create a total ordering on that, and hence define adjacency, I don't know.
I think you need to dig more into that paper to understand what they're doing.
Bruno Luong
el 16 de Ag. de 2019
Editada: Bruno Luong
el 16 de Ag. de 2019
In graph theory "adjadcent" usually mean topology connected, you don't need necessary to have order defined on the set.
Respuesta aceptada
Bruno Luong
el 16 de Ag. de 2019
Editada: Bruno Luong
el 17 de Ag. de 2019
All pairs
If you have the right toolbox, take a look at PDIST2 function. If not
[m,n] = size(A);
D = sqrt(sum((reshape(A, [m,1,n])-reshape(A, [1,m,n])).^2,3))
D(i,j) contains the distance between A(i,:) and A(j,:)
Adjacent pairs
D = sqrt(sum(diff(A,1,1).^2,2))
D(i) contains the distance between A(i,:) and A(i+1,:)
Windowing adjacent pairs
[m,n] = size(A);
Nnum = 2; % N_number
r = (1:m)'+(-Nnum:Nnum);
inan = m+1;
A(inan,:) = NaN;
r(r<1 | r>m) = inan;
B = reshape(A(r,:),[m, 2*Nnum+1, n]);
A(inan,:) = [];
D = sqrt(sum((reshape(A, [m,1,n])-B).^2,3));
D(i,j) = contains the distance between
A(i,:) and A(i+j-Nnum-1,:);
for i=1,...m and j=1,...,2*Nnum+1.
Note: Distance to overflow points contains NaN.
4 comentarios
Bruno Luong
el 17 de Ag. de 2019
Editada: Bruno Luong
el 17 de Ag. de 2019
Sorry, I won't explain with "words". To me it's more confusing. Each person is free to undertand with his/her respective personnal view.
Más respuestas (1)
Guillaume
el 16 de Ag. de 2019
I'm a bit confused by your question. You define something you want to do then ask us to explain your own definition. Isn't the definition whatever you want it to be according to what you want to do?
I guess it all depends on what you call adjacent for feature vectors. Does it even mean anything to spay that two features vectors are adjacent? For that you need to define a total ordering on your feature vector set? Is an ordering meaningful for feature vectors?
Traditionally, you would calculate the euclidean distance between all pairs of the set, something you can do with pdist, or yourself easily:
dist = sqrt(sum(permute(A, [1, 3, 2]).^2 - permute(A, [3, 1, 2]) .^ 2, 3)
dist(i, j) is the euclidean distance between vector A(i) and A(j).
Ver también
Categorías
Más información sobre Computer Vision with Simulink en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!