OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Fri, 24 Oct 2014 02:56:16 -0500Template matching with the CV_TM_CCOEFF algorithmhttp://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/
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.Mon, 14 Jan 2013 15:20:19 -0600http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/Comment by rolly for <p>I can't figure out the CV_TM_CCOEFF algorithm. (I get the CCORR & Least squares)</p>
<p>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.</p>
http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?comment=34620#post-id-34620i 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.Thu, 05 Jun 2014 07:59:18 -0500http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?comment=34620#post-id-34620Answer by brotherofken for <p>I can't figure out the CV_TM_CCOEFF algorithm. (I get the CCORR & Least squares)</p>
<p>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.</p>
http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?answer=45416#post-id-45416This 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.](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.21.6062)
2. [M. Arif and K. Sohaib, “Early Termination Algorithms for Correlation Coefficient Based Block Matching.”](http://cvlab.lums.edu.pk/mahmood2007early/)Fri, 24 Oct 2014 02:56:16 -0500http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?answer=45416#post-id-45416Answer by Guanta for <p>I can't figure out the CV_TM_CCOEFF algorithm. (I get the CCORR & Least squares)</p>
<p>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.</p>
http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?answer=6142#post-id-6142According 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.
Wed, 16 Jan 2013 08:42:22 -0600http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?answer=6142#post-id-6142Comment by rolly for <p>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.</p>
http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?comment=34619#post-id-34619what do x'' & y'' refers to ? i know x&y are coordinates for source image, x' & y' are coordinates for template. Thu, 05 Jun 2014 07:50:53 -0500http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?comment=34619#post-id-34619Comment by Guanta for <p>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.</p>
http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?comment=34659#post-id-34659x'' 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.Fri, 06 Jun 2014 05:37:13 -0500http://answers.opencv.org/question/6060/template-matching-with-the-cv_tm_ccoeff-algorithm/?comment=34659#post-id-34659