Quiz: cross-correlation with the FFT

Short questions to test your understanding. Try each on paper first, then open the answer. The cross-correlation is c(t) = \sum_x A(x+t)\,B(x); its spectrum is A_k\overline{B_k}.


Q1. Name the three steps that compute the cross-correlation of two images for every shift at once.

Two transforms in, one out.

FFT of A and FFT of B; multiply, frequency by frequency, A_k by the complex conjugate of B_k; inverse FFT of the product. The result holds c(t) for every shift t.


Q2. Why does the conjugate appear? What would you get with A_k B_k instead?

Correlation vs convolution.

A_kB_k is the spectrum of the convolution of A and B, which flips B. Correlation does not flip, so B must be flipped once more to undo it; for a real image, flipping in space conjugates the spectrum. With A_kB_k you would compare A with B read backwards.


Q3. Two signals of 4 samples give A_k\overline{B_k} = (9, -5i, -1, 5i). Which value of the correlation c(t) does k = 0 alone contribute to every t, and what does it mean?

The inverse DFT divides by N = 4; frequency 0 is the constant wave.

9/4 = 2.25 at every shift: the product of the sums of A and B divided by N. It says “both images are bright on average”, not where they match. That is why the means are usually subtracted first: the constant wave adds the same amount to every shift (circular) or a triangle that grows with the overlap (linear).


Q4. The FFT gives the circular correlation. What does that mean for two tiles that only partly overlap, and how do you get the linear correlation?

What happens to the part of B that is pushed out on the right?

The FFT treats both tiles as periodic: what is pushed out on one side comes back on the other, so the score also compares pixels that never lie on top of each other, and a shift t cannot be told from t - N. Zero-pad both to at least 2N - 1 (in practice 2N) samples per side: the shifted part then falls on zeros, and the result is the linear correlation.


Q5. Roughly how many times fewer operations does the FFT route need than brute force for two 1024 \times 1024 tiles, every shift allowed?

Brute force: 2N^4 operations; FFT: three FFTs of M = 2048^2 samples at 5M\log_2M each.

Brute force \approx 2.2 \cdot 10^{12} operations, the FFT route \approx 1.4 \cdot 10^9: about 1600 times fewer.


Q6. The stage is known to be accurate to \pm 5 pixels. Is the FFT still the better choice for a pair of 1024 \times 1024 tiles?

A window of \pm w costs about 2(2w+1)^2N^2 operations for N \times N images.

Not necessarily: \pm 5 pixels is 11^2 = 121 shifts of about 10^6 pixels, about 2.5 \cdot 10^8 operations, less than the 1.4 \cdot 10^9 of the padded FFT route. Brute force over a small window wins up to about \pm 12 pixels. The FFT wins when the shift is unknown or large.


Q7. (math) Show that if g(x) = f(x + t_0) (circularly), then F_k\overline{G_k} = |F_k|^2 e^{-2\pi i k t_0/N}.

The shift theorem of the Fourier unit.

G_k = \sum_x f(x+t_0)e^{-2\pi i kx/N} = e^{2\pi i kt_0/N}\sum_u f(u)e^{-2\pi i ku/N} = e^{2\pi i kt_0/N}F_k (with u = x + t_0). So \overline{G_k} = e^{-2\pi i kt_0/N}\overline{F_k} and F_k\overline{G_k} = |F_k|^2e^{-2\pi i kt_0/N}: the size of each wave squared, with a phase that turns at a rate set by the shift.


Q8. How can NCC, which divides by the spread of the overlap at every shift, be computed with FFTs?

What sums does NCC need, and how is “the sum of A under B” a correlation?

NCC needs, at every shift, the sum of products of the overlap, the sums of A and B and the sums of their squares over the overlap. The sum of products is the cross-correlation; the sum of A under B is A correlated with a block of ones the shape of B (a box filter); likewise for A^2, B and B^2. Each is one product of FFTs; NCC then follows pixel by pixel.