Phase Correlation and Negative Shifts I am implementing phase correlation algorithm to determine shift between two images.

It generally works, but I am not sure how to interpret the resulting shift.

Pseudocode:

ft1 = FT(input1)
ft2 = FT(input2)

for each pixel p
  product = ft1[p] * conj(ft2[p])
  cross_power[p] = product / abs(product)

cross_correlation = IFT(cross_power)


where FT and IFT are Discrete Fourier Transform and its inverse, respectively.

Here are input images and resulting phase correlation taken from Wikipedia:

  

The peak is located at (20, 21) which corresponds to shifting of the second image.

I have obtained similar result, but it comes out flipped:



When I flip the input images the peak appears at the top left corner of the phase correlation image but how to interpret this as a negative shift (-20, -21)? Based on image quadrants?

I am using Fourier transform routine from Math.NET Numerics package. It provides only 1D FT, so I am doing transforms of rows and then columns to obtain 2D FT.

How to extract shift from the peak position allowing for negative shifts as well?

Why is the peak located differently in my result?
the matter is due to this one:

product = ft1[p] * conj(ft2[p])


You can change to:

product = ft2[p] * conj(ft1[p])


I guess input1 is the reference image.