Question

I've been looking to the OpenCV's magnificent source code to understand the score calculation. As you may have noticed the library can find a template in an image with a confidence score. cvMatchTemplate function gives the probability and location of the template in image.

Since DFT is slow, I decided to use FFTW library for phase correlation. I get the image, expanded to a size which is a power of 2, then did the same to the template, first calculated the FFT for both, multiplied the two array, calculated the inverse FFT, finally normalized the result.

If I show this result on a bitmap it clearly shows the location of template, however, I have difficulties calculating the correlation score. I tried to run cvMatchTemplate method line by line under debugger, it didn't help since the library uses DFT and arbitrary image sizes. All the tables used in that method (sum, sqsum etc) created for corresponding arbitrary sizes and FFT uses powers of two.

I would be grateful for any information on how to calculate the score from that result of phase correlation. There are many sources describing "take this, take that, multiply them, you see the white point on the image, yeah you find it" way. I need a score just like cvMatchTemplate did.

I'm kindly asking you to point me to a site or to a paper containing the logic of that calculation or to a book. Source code would be perfect but I have no hope on that anyway.

Was it helpful?

Solution

First, make sure you are not "expanding the image to a power of 2". I'm sure you didn't mean this, but anyway with FFTW you can calculate an arbitrary size FT.

I don't understand what you are using OpenCV for. If you have the FFT then it is quite easy to calculate the normalised cross power spectrum by yourself, in other words the "phase correlation formula".

Get the largest size FFT of the images that you can, not forgetting to window. Calculate the CPS. Once you have the correlation surface look for the peak.

I don't know what OpenCV offers for Phase Correlation apart from FT, but the paper you want is

G.A. Thomas, Television Motion Measurement for DATV and Other Applications, 1987, BBC Research Department.

OTHER TIPS

1) FFTW can work with non-power-of-2 size arrays.

2) The subject area you might to search/study in is the FFT cross-correlation theorem:

"the Fourier transform of the cross-correlation of two functions is equivalent to the product of the individual Fourier transforms, where one of them has been complex conjugated"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top