3
$\begingroup$

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:

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?

$\endgroup$
  • 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 Apr 24 '13 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 Apr 24 '13 at 18:00
  • $\begingroup$ Maybe the images were indeed flipped on Wikipedia. $\endgroup$ – Libor Apr 24 '13 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 Apr 25 '13 at 10:55
1
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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