Jalal
Jalal

Reputation: 6846

Fourier Based Character Recognition in Matlab

I have a source code that could recognize a character's position in an image. but there is a line of code that i can't figure it out WHY?

[r c]=size(mainImage);

% Why rotate 90 degree? why multyply? why??? :-??
splash = real(ifft2(fft2(mainImage) .* fft2(rot90(object, 2), r, c)));

thresh = max(splash(:))-10;
for i=1:r
    for j=1:c
        if splash(i,j)>=thresh 
            splash(i,j)=1;
        else
           splash(i,j)=0;
        end
    end
end

Upvotes: 3

Views: 1374

Answers (1)

walkytalky
walkytalky

Reputation: 9543

My FFT knowledge is a bit rusty, but I think this is essentially calculating the cross-correlation.

Multiplication in the frequency domain is equivalent to convolution in the space/time domain. And cross-correlation is equivalent to convolution with the inverted signal -- which is what the 180° rotation is trying to do. Off the top of my slightly-drunk head I can't say whether this specific implementation should be expected to work.

Matlab has functions to calculate cross-correlations directly, but they may reside in toolboxes that weren't available to the author (or expected users) of this code.

Upvotes: 5

Related Questions