Matlab 两个矩阵而非两个向量之间的循环互相关

Matlab 两个矩阵而非两个向量之间的循环互相关,matlab,image-processing,Matlab,Image Processing,以下matlab函数计算两个向量之间的循环互相关: function [ h ] = cxcorr_fft( a,b ) %CXCORR_FFT Calculates the circular cross correlation of the two input vectors using the fft based method % calculate cross correlation e = fft(a); f = fft(b); g = f.*conj(e); h = ffts

以下matlab函数计算两个向量之间的循环互相关:

function [ h ] = cxcorr_fft( a,b )
%CXCORR_FFT Calculates the circular cross correlation of the two input vectors using the fft based method
% calculate cross correlation
e = fft(a);
f = fft(b);

 
g = f.*conj(e);
 
h = fftshift(ifft(g));
 
end
 
我已使用此函数计算两幅图像之间的循环互相关,方法是将fft替换为fft2,如下所示:

function [ h ] = cxcorr_fft( a,b )
%CXCORR_FFT Calculates the circular cross correlation of the two input vectors using the fft based method
% calculate cross correlation
e = fft2(a);
f = fft2(b);
 
g = f.*conj(e);
 
h = fftshift(ifft2(g));
 
end

结果是不合理的。图像与自身之间的相关性值与图像与不同图像之间的相关性值大致相同。您能帮我找到代码中的错误吗?

为什么结果不合理?相关性的最大值(在
h
的中间)似乎与预期一致。对于奇数大小的
a
正方形和
b=a
,值
h((end+1)/2)
sum(abs(a(:).^2)
一致,为什么结果不合理?相关性的最大值(在
h
的中间)似乎与预期一致。对于奇数大小的
a
正方形和
b=a
,值
h((end+1)/2)
sum(abs(a(:).^2)
重合