Euclidean distance of adjacent pairs of matrix

조회 수: 7 (최근 30일)
Stewart Tan
Stewart Tan 2019년 8월 16일
편집: Bruno Luong 2019년 8월 17일
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
Guillaume
Guillaume 2019년 8월 16일
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
Bruno Luong 2019년 8월 16일
편집: Bruno Luong 2019년 8월 16일
In graph theory "adjadcent" usually mean topology connected, you don't need necessary to have order defined on the set.

댓글을 달려면 로그인하십시오.

채택된 답변

Bruno Luong
Bruno Luong 2019년 8월 16일
편집: Bruno Luong 2019년 8월 17일
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
Stewart Tan
Stewart Tan 2019년 8월 17일
@Bruno Luong I don't quite get the "windowing adjacent pair" part. Do you mind explaining a little bit? As in words like row1 with row2 etc, so i could get the idea.
Bruno Luong
Bruno Luong 2019년 8월 17일
편집: Bruno Luong 2019년 8월 17일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2019년 8월 16일
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).
  댓글 수: 1
Stewart Tan
Stewart Tan 2019년 8월 16일
@Guillaume very sorry for the confusion, could you refer to my reply to @Image Analyst above?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by