Calculating the distance between two matrices Matlab

I want to calculate the distance between two different DFT results after i performed this code:
I1 = imread('sample1');%read the images
I2 = imread('sample2');
GI1 = rgb2gray(I1) %change it to grayscale
GI2 = rgb2gray(I2)
DftR1 = DFT(GI1) %perform the 2-dimensional DFT(a function that i built it myself)
DftR2 = DFT(GI2)
so far it all worked; however when i want to compare the results of the DFT using this code:
Distance = pdist2(DftR1, DftR2)
I get this particular error: Error using pdist2 (line 224) PDIST2 does not accept complex data for built-in distances.

 採用された回答

Star Strider
Star Strider 2014 年 12 月 2 日

2 投票

The DFT that the code you posted previously returns will be complex.
If pdist2 wants only real values,
Distance = pdist2(abs(DftR1), abs(DftR2));
will likely work.

3 件のコメント

alladin
alladin 2014 年 12 月 2 日
Thank you, it worked, but the issue that the result was a matrix, i thought by calculating the distance i will get only one value so that i can tell whether the results match or not.
If you have an idea on how to do it please let me know. I appreciate your help
Star Strider
Star Strider 2014 年 12 月 2 日
編集済み: Star Strider 2014 年 12 月 2 日
My pleasure.
The pdist2 function returns a matrix by definition. You can force the matrix to become only value by creating a vector out of it and then performing the operation you believe best suits your application. The mean or standard deviation might be most appropriate:
Dmean = mean(Distance(:));
Dstdv = std(Distance(:));
alladin
alladin 2014 年 12 月 2 日
I appreciate your help thank you

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

その他の回答 (1 件)

Deepesh B
Deepesh B 2014 年 12 月 2 日

1 投票

Hi U have to use
abs
before applying
pdist2
because after fft it will have complex numbers

質問済み:

2014 年 12 月 2 日

コメント済み:

2014 年 12 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by