Explaing Cross Correlation and Normalization for openCV's Match Template

纵然是瞬间 提交于 2019-12-20 09:45:19

问题


My boss and I disagree as to what is going on with the CV_TM_CCORR_NORMED method for matchTemplate(); in openCV.

Can you please explain what is happening here especially the square root aspect of this equation.


回答1:


Correlation is similarity of two signals,vectors etc. Suppose you have vectors

 template=[0 1 0 0 1 0 ]   A=[0 1 1 1 0 0] B =[ 1 0 0 0 0 1]  

if you perform correlation between vectors and template to get which one is more similar ,you will see A is similar to template more than B because 1's are placed in corresponding indexes.This means the more nonzero elements corresponds the more correlation between vectors is.

In grayscale images the values are in the range of 0-255.Let's do that :

template=[10 250 36 30] A=[10 250 36 30] B=[220 251 240 210] .

Here it is clear that A is the same as template but correlation between B and template is bigger than A and template.In normalized cross correlation denumerator part of formula is solving this problem. If you check the formula below you can see that denumerator for B(x)template will be much bigger than A(x)template.

Formula as stated in opencv documentation :

In practice if you use cross correlation,if there is a brightness in a part of image , the correlation between that part and your template will be larger.But if you use normalized cross correlation you will get better result.

Think formula is this :

Before multiplying element by element you are normalizing two matrixes.By dividing root of square sum of all elements in matrix you are removing the gain;if all elements are large then divisor is large.

Think that you are dividing sum of all elements in matrix.If a pixel value is in a brighter area then its neighbours pixel values will be high.By dividing sum of its neighbourhood you are removing illumination effect.This is for image processing where pixel values are always positive.But for 2D matrix there may be some negative values so squaring ignores sign.



来源:https://stackoverflow.com/questions/28506665/explaing-cross-correlation-and-normalization-for-opencvs-match-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!