Matlab code to calculate horizontal and vertical offset amount of two images

Viewed 47

Here is my code. What should I do next? How can I calculate horizontal and vertical offset amount of two images? (I3 and I4 are shifted images)

I1 = imread('cameraman.tif');
I3 = I1(65:196, 65:196); 
I4 = I1(75:206,65:196);

F3 = fft2(I3);
F4 = fft2(I4);

FF = conj(F3).* F4;
Is = ifft2(FF);

figure, mesh(fftshift(Is))

and here is my output enter image description here

1 Answers

While you tried to implement cross correlation efficiently using fft, to gain some intuition it would be better to do it in spatial domain.

Basically the location of the peak of the cross correlation relatively to the origin of the 2D support is the shift between the 2 images.

Related