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일
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.
wow, king's answer is wonderful!
Hi wayne,
Could you tell me if either of this method works greatly when images are rotated ?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

질문:

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