Ask Your Question
1

Template matching with the CV_TM_CCOEFF algorithm

asked 2013-01-14 15:20:19 -0600

matt.hammer gravatar image

I can't figure out the CV_TM_CCOEFF algorithm. (I get the CCORR & Least squares)

The O'Reilly book explains that "These methods match a template relative to its mean against the image relative to its mean, so a perfect match will be 1 and a perfect mismatch will be -1; a value of 0 simply means that there is no correlation". However, the equation given for CV_TM_CCOEFF doesn't subtract the mean from each pixel value but instead subtracts the reciprocal of the pixel value sum TIMES the number of pixels (shouldn't it be a division?). Plus, all the simple examples I work out on paper (with small, one dimensional signals) usually don't give me 1, 0, or -1. I also Googled Correlation Coefficient and found variations of this: Pearson Correlation Coefficient, which has all kinds of covariant and squared terms I can't reconcile with the OpenCV equation.

edit retag flag offensive close merge delete

Comments

i have question like u about CCOEFF algorithm in theory. do u know, what do x'' & y'' refers to ? i know x&y are coordinates for source image, x' & y' are coordinates for template.

rolly gravatar imagerolly ( 2014-06-05 07:59:18 -0600 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2013-01-16 08:42:22 -0600

Guanta gravatar image

According to the documentation CV_TM_CCOEFF and CV_TM_CCOEFF_NORMED both subtract the mean from the window and the template, and yes, '1' shoud denote a perfect match.

edit flag offensive delete link more

Comments

what do x'' & y'' refers to ? i know x&y are coordinates for source image, x' & y' are coordinates for template.

rolly gravatar imagerolly ( 2014-06-05 07:50:53 -0600 )edit

x'' and y'' are just indices like x' and y', they were only needed since x' and y' already existed. For CV_TM_CCOEFF and for CV_TM_CCOEFF_NORMED the template and the window in the image at position x,y are made zero-mean. Therefore you need to go through all locations of the template and the window.

Guanta gravatar imageGuanta ( 2014-06-06 05:37:13 -0600 )edit
2

answered 2014-10-24 02:56:16 -0600

brotherofken gravatar image

updated 2014-10-24 03:04:12 -0600

This method is called Normalized Correlation Coefficient or Normalized Cross-Correlation (NCC). I looked through OpenCV source code, and then found paper [1] which contains clear description and probably was used in CV_TM_CCOEFF and CV_TM_CCOEFF_NORMED implementation.

Also I found paper [2] which shows promising NCC computation efficiency, but there is no implementation available.

  1. J. P. Lewis, Fast Normalized Cross-Correlation. 1995.
  2. M. Arif and K. Sohaib, “Early Termination Algorithms for Correlation Coefficient Based Block Matching.”
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-01-14 15:20:19 -0600

Seen: 7,702 times

Last updated: Oct 24 '14