How to find euclidean distances between cell entries of two RGB matrices?

1 回表示 (過去 30 日間)
Borys Bulka
Borys Bulka 2020 年 11 月 16 日
コメント済み: Jan 2020 年 11 月 18 日
I have two RGB images A and B. Image A is 47x47x3 and image B is 1x456x3. I need to find the euclidean distances between all the entries of image A and all entries of image B. Then as a second goal I need to find for each cell in image A which cell in image B its closest to in euclidean distance. Does anyone has any suggestions? The things I tried have unfortunately failed.
  3 件のコメント
Borys Bulka
Borys Bulka 2020 年 11 月 16 日
編集済み: Borys Bulka 2020 年 11 月 16 日
I am a bit confused myself how to exactly state what my goal is. What I try to say is that for each cell in RGB image A, I want to know what the euclidean distance is with each cell in RGB image B. Does that make any sense?
Borys Bulka
Borys Bulka 2020 年 11 月 16 日
A is a 47x47x3 RGB matrix. For each cell I want to know which cell in RGB matrix it is closest to in euclidean space. I am stuck on this problem for a whole week and I constantly cannot solve or find a way to do so. I am bit clueless on how to tackle it.

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

回答 (1 件)

Jan
Jan 2020 年 11 月 16 日
A = rand(47, 47, 3);
B = rand(1, 456 3);
AB = reshape(A, 47*47, 1, 3) - B;
Dist = vecnom(AB, 2, 3);
And now you want to find the minimal values in each column. Afterwards you can use ind2sub to convert the linear indices back to the indices of A.
Another option is a simple loop:
Result = zeros(size(A));
for row = 1:47
for col = 1:47
dist = vecnorm(A(col, row, :) - B, 2, 3);
[~, index] = min(dist);
Result(col, row) = index;
end
end
  2 件のコメント
Borys Bulka
Borys Bulka 2020 年 11 月 16 日
Thank you a lot for your answer and effort, but somehow I fail to incorporate it and interpret the results correctly. I don't think any more answers will help since I have tried this in multiple directions ways with multiple answers and keep failing it.
Jan
Jan 2020 年 11 月 18 日
I cannopt guess, which problem you have. So please post the relevant part of your code and ask a specific question.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by