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.


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:

enter image description here enter image description here enter image description here

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:

enter image description here

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?

  • 1
    $\begingroup$ I think that if you switch the two inputs, you'll get the opposite result. Maybe it wasn't clear which one was treated as input1 and input2 on the Wikipedia example. $\endgroup$
    – Jason R
    Commented Apr 24, 2013 at 17:49
  • $\begingroup$ Is the pixel offset of the two pictures (20, 21)? That looks to me to be about correct just going by the naked eye. $\endgroup$
    – Jim Clay
    Commented Apr 24, 2013 at 18:00
  • $\begingroup$ Maybe the images were indeed flipped on Wikipedia. $\endgroup$
    – Libor
    Commented Apr 24, 2013 at 18:02
  • 1
    $\begingroup$ Also, I think that if you conjugate fp1 instead of fp2, you should get that image as well. Haven't tried it myself. $\endgroup$
    – Phonon
    Commented Apr 25, 2013 at 10:55

2 Answers 2


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.


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

The result can be interpreted with quadrants as you suggest, since it follows periodic boundary conditions.

In pseudo code, where xtrans,ytrans is the location of the peak value:

if xtrans > imgwidth/2: xtrans = -(imgwidth-xtrans)
if ytrans > imgheight/2: ytrans = -(imgheight-ytrans)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.