Cross-correlation in frequency domain and xcorr2 in MATLAB
What are the reasons for the differences between my frequency domain cross-correlation results and those obtained using the xcorr2() function in MATLAB? Is it possible that xcorr2() performs spatial domain cross-correlation, and how might this affect the results?
img1 = imread(‘1.jpg’);
img2 = imread(‘2.jpg’);
img1_gray = rgb2gray(img1);
img2_gray = rgb2gray(img2);
[m, n] = size(img1_gray);
[p, q] = size(img2_gray);
fft_img1 = fft2(img1_gray, m + p – 1, n + q – 1);
fft_img2 = fft2(img2_gray, m + p – 1, n + q – 1);
cross_correlation = (fft_img1 .* conj(fft_img2));
cross_correlation = ifft2(cross_correlation);
cross_correlation = fftshift(cross_correlation);
cross_correlation_xcorr2 = xcorr2(img2_gray, img1_gray);
figure;
subplot(2, 1, 1);
imshow(cross_correlation, []);
title(‘Custom Cross-Correlation’);
subplot(2, 1, 2);
imshow(cross_correlation_xcorr2, []);
title(‘xcorr2’);
Results:What are the reasons for the differences between my frequency domain cross-correlation results and those obtained using the xcorr2() function in MATLAB? Is it possible that xcorr2() performs spatial domain cross-correlation, and how might this affect the results?
img1 = imread(‘1.jpg’);
img2 = imread(‘2.jpg’);
img1_gray = rgb2gray(img1);
img2_gray = rgb2gray(img2);
[m, n] = size(img1_gray);
[p, q] = size(img2_gray);
fft_img1 = fft2(img1_gray, m + p – 1, n + q – 1);
fft_img2 = fft2(img2_gray, m + p – 1, n + q – 1);
cross_correlation = (fft_img1 .* conj(fft_img2));
cross_correlation = ifft2(cross_correlation);
cross_correlation = fftshift(cross_correlation);
cross_correlation_xcorr2 = xcorr2(img2_gray, img1_gray);
figure;
subplot(2, 1, 1);
imshow(cross_correlation, []);
title(‘Custom Cross-Correlation’);
subplot(2, 1, 2);
imshow(cross_correlation_xcorr2, []);
title(‘xcorr2’);
Results: What are the reasons for the differences between my frequency domain cross-correlation results and those obtained using the xcorr2() function in MATLAB? Is it possible that xcorr2() performs spatial domain cross-correlation, and how might this affect the results?
img1 = imread(‘1.jpg’);
img2 = imread(‘2.jpg’);
img1_gray = rgb2gray(img1);
img2_gray = rgb2gray(img2);
[m, n] = size(img1_gray);
[p, q] = size(img2_gray);
fft_img1 = fft2(img1_gray, m + p – 1, n + q – 1);
fft_img2 = fft2(img2_gray, m + p – 1, n + q – 1);
cross_correlation = (fft_img1 .* conj(fft_img2));
cross_correlation = ifft2(cross_correlation);
cross_correlation = fftshift(cross_correlation);
cross_correlation_xcorr2 = xcorr2(img2_gray, img1_gray);
figure;
subplot(2, 1, 1);
imshow(cross_correlation, []);
title(‘Custom Cross-Correlation’);
subplot(2, 1, 2);
imshow(cross_correlation_xcorr2, []);
title(‘xcorr2’);
Results: matlab, digital image processing MATLAB Answers — New Questions