I’m trying to detect chars from a text in white and black. At the moment, the text is a white background with only a few chars in black. Also I’ve created some little images containing only a char each one. I want to use phase correlation to detect the chars in the initial text. For this I’ve done:
image = im2double(imread("text.png"));
si = size(image);
trans = fft2(image);
ch = im2double(imread("a.bmp"));
chtrans = fft2(ch,si(1),si(2));
outt = angle(trans).*conj(angle(chtrans));
outt = abs(ifft2(outt)).^2;
When I normalize my outt variable I detect for example all “a” in my text but the image is double: there’s the correct result but there’s also the correct result flipped, both on the same final image. What’s wrong with this?
Feeding the angle back into the IFFT does not isolate the phase. You want a complex number with the same angle, but with a magnitude of 1. You don’t want a real number that represents the angle. One way to express phase correlation is to normalize the result of the conjugate multiplication:
There are other ways to express it, but in any case, the mirror image goes away. One thing to keep in mind is that your result should ideally be pure real. Any imaginary components are due to round-off error. If you find you need to do abs() on the result, you probably did something wrong.