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

 Risposta accettata

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 Commenti

Thanks Wayne, I will certainly give that a try.
wow, king's answer is wonderful!
Hi wayne,
Could you tell me if either of this method works greatly when images are rotated ?

Accedi per commentare.

Più risposte (0)

Richiesto:

Sam
il 28 Nov 2011

Commentato:

il 15 Ott 2019

Community Treasure Hunt

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

Start Hunting!

Translated by