# What happen to the Zero Mean Normalized Cross Correlation (ZNCC) if one of the vectors is a Zero Vector?

I am studying the Zero Mean Normalized Cross Correlation (ZNCC) method for pattern matching. I would like to match the pattern of a square region of size $N \times N$ from two different images. Hence I define two vectors $P$ and $Q$, each of size $N \times N$, for storing the pixel intensity inside each of the two regions. The calculation of the ZNCC is then as follows:

(1) $P' = P - \bar{P}$, where $\bar{P} = \sum {P_i} / N$. Similarly, $Q' = Q - \bar{Q}$, where $\bar{Q} = \sum{Q_i} / N$

(2) $P'' = P' / |P'|$ and $Q'' = Q' / |Q'|$

(3) ZNCC = Dot product of $P''$ and $Q''$

The problem is, when one of the selected regions contain pixels all with the same intensity (which can happen occasionally in my image, especially when N is small), $P'$ or $Q'$ become a zero vector and it is impossible to proceed to calculate $P''$ or $Q''$. What should we do in this case?

• Note that you can use LaTeX here to typeset mathematics in a more readable way. See here for a short introduction. – D.W. Oct 23 '15 at 5:17
• If (say) $P' = 0$ then you can define arbitrarily $P'' = 0$, and so the ZNCC equals zero. Don't forget to check whether $P''=Q''=0$, which indicates high correlation even though the dot product is zero. – Yuval Filmus Oct 23 '15 at 7:45