因此,当我尝试在大图像 A 中找到模板 B 时,我可以通过找到互相关的最大值来做到这一点,就像在空间域中这样:
% Finding maximum of correlation:
phi = normxcorr2(B,A);
[ymax, xmax] = find(phi == max(phi(:)));
% Find position in original image:
ypeak = ymax - size(B,1);
xpeak = xmax - size(B,2);
但是当我想在频域中这样做时,我得到了错误的结果:
% Calculate correlation in frequency domain:
Af = fft2(A);
Bf = fft2(B, size(A,1), size(A,2));
phi2f = conj(Af)'*Bf;
% Inverse fft to get back to spatial domain:
phi2 = real(ifft(fftshift(phi2f)));
% Now we have correlation matrix, excatly the same as calculated in
% the spatial domain.
[ymax2, xmax2] = find(phi2 == max(phi2(:)));
我不明白我在频域做错了什么。我已经在没有 fftshift 的情况下尝试过,它给出了不同的结果,尽管仍然是错误的。我怎样才能正确地做到这一点?