normxcorr2 function - spatial / frequency domain selection

Hi,
I am currently performing cross correlation between various images and know that MATLAB decides whether to use spatial or frequency algorithms based on the image size. I would like to know how large an image has to be for the frequency domain to be used over the spatial domain? I would also like to know if I can force MATLAB to use either the spatial or frequency domain by myself?
Thanks in advance for any answers or insights.
Sam

 採用された回答

Wayne King
Wayne King 2011 年 11 月 28 日

2 投票

Hi Sam, normxcorr2 computes an estimate of the computation time for spatial domain correlation vs. frequency domain. Whichever is the smallest wins.
You could save normxcorr2.m as a different name and then modify the code so that it always did one or the other. For example, to always use spatial domain, you can modify the xcorr2_fast function inside of normxcorr2 as follows
function cross_corr = xcorr2_fast(T,A)
T_size = size(T);
A_size = size(A);
outsize = A_size + T_size - 1;
% figure out when to use spatial domain vs. freq domain
%conv_time = time_conv2(T_size,A_size); % 1 conv2
%fft_time = 3*time_fft2(outsize); % 2 fft2 + 1 ifft2
%if (conv_time < fft_time)
cross_corr = conv2(rot90(T,2),A);
%else
% cross_corr = freqxcorr(T,A,outsize);
%end
To only use the Fourier transform:
function cross_corr = xcorr2_fast(T,A)
T_size = size(T);
A_size = size(A);
outsize = A_size + T_size - 1;
% figure out when to use spatial domain vs. freq domain
%conv_time = time_conv2(T_size,A_size); % 1 conv2
%fft_time = 3*time_fft2(outsize); % 2 fft2 + 1 ifft2
%if (conv_time < fft_time)
% cross_corr = conv2(rot90(T,2),A);
%else
cross_corr = freqxcorr(T,A,outsize);
%end

3 件のコメント

Sam
Sam 2011 年 11 月 28 日
Thanks Wayne, I will certainly give that a try.
yang wang
yang wang 2013 年 3 月 30 日
wow, king's answer is wonderful!
Ravi Singh
Ravi Singh 2019 年 10 月 15 日
Hi wayne,
Could you tell me if either of this method works greatly when images are rotated ?

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

その他の回答 (0 件)

質問済み:

Sam
2011 年 11 月 28 日

コメント済み:

2019 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by