0

I need to implement cross-correlation of 2 images in C++. The process is unclear to me since i do not seem to find a definite formula for it.

What i thought this means:

  1. FFT2 on both images
  2. multiply them: FFT2(IMG1)*conj(FFT2(IMG2))
  3. IFFT2 on the output

I seem to get another version each time, thus confusing me, and i need to know which is the correct method so that i can proceed with the implementation.

  • As written, this is a duplicate. If existing answers are unsatisfactory, please explain why. In this case it means trying the answers and showing that they don't work as you expect. Note we don't provide finished code here, but I pretty much did that in Python. – OverLordGoldDragon Jan 02 '23 at 10:28
  • Thank you, i have long considered your answer to that question. It seems simple enough but my problem lays with the ifftshift method. It seems very complicated (prone to errors) to implement it in c++, it would probably take me weeks.

    Unfortunately i can not use libs that could help me with that either. So i am a bit at a loss here.

    – user3253067 Jan 02 '23 at 10:50
  • It's very simple to implement, I suggest looking up the definition of ifftshift and its open-source implementations. For even-length 1D sequences it's just swapping left and right halves. For 2D, first apply on every row (or col) of the 2D input, then col (or row). – OverLordGoldDragon Jan 02 '23 at 10:54
  • yes, i have checked the implementations and i got thrown off by the usage of the "roll" method which seems way over my head and complicated for nothing since it is as easy as you say. I will try to implement it for the 2D then, as per your advice. Thank you for making it clearer for me. I have one more question though, i do have a fftshift method already implemented in my code, which is doing exactly what you said for ifftshift, and to be honest i don't see where is the difference between ifftshift and ffshift. – user3253067 Jan 02 '23 at 11:16
  • 1
    i think i get it now, there is a difference in the case of odd length sequences – user3253067 Jan 02 '23 at 11:24

0 Answers0