Speed up a image alignment function using FFT

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
CNX
Messages
26
Reaction score
0

Homework Statement



I need to speed up a image alignment function using FFT

Homework Equations



FFT, correlation coefficient (for deciding best alignment)

The Attempt at a Solution



This function works but a fail to see how it is any better that a naive evaluation of the correlation coefficient.

Code:
function [a, b] = Align(f, g)

    [h, w] = size(f);
    
    a = 0;
    b = 0;
    cmax = 0;
    
    G = fft2(g);
    G = conj(G);
    
    for j=1:h-1
        for k=1:w-1
            fs = circshift(f, [j,k]);
            F = fft2(fs);

            c = sum(F(:).*G(:));
            
            if c > cmax
                cmax = c;
                a = j;
                b = k;
            end
        end
    end
    
    return
 
Physics news on Phys.org


i thought fft was fast Fourier transform