Explaining template matching algorithm's formula (opencv2)

352 Views Asked by At

I am struggling to understand OpenCv's formula for the CV_TM_CCOEFF template matching algorithm

enter image description here

Where

enter image description here

Specifically, in R(x,y), what do the x' and y''s mean? I dont imagine they are derivatives, because the values are all integers so its derivative wrt anything would be 0. Then x + 0 = x.

Secondly, what is T'(x',y')?

I found the other topic asking a question exactly on this but the answer is very vague and unhelpful. Thanks

Edit:

After further reading, apparently T(x', y') is the image pixel value for a pixel (x,y) in the template image and I(x+x', y+y') is the image pixel value for the corresponding pixel position in the target image. With that in mind, what is T(x'',y'') and I(x+x'', y+y'')?

1

There are 1 best solutions below

0
On

x' and x'' are just variables distinct from x. It's awkward notation, yes.

T' is a normalized version of T, where the mean of T is subtracted. Likewise for I' (though this one is not used anywhere? I think the equation for R should use I' rather than I).

Then, R is the convolution of the image I with the normalized and mirrored T (cross-correlation is the same as convolution, but without the mirroring of the kernel, note how it uses x+x' rather than x-x' as you would see in a convolution).