# In-Depth Discussion

NI Vision 2019 for LabVIEW Help

Edition Date: March 2019

Part Number: 370281AG-01

»View Product Info Download Help (Windows Only)

This section provides additional information you may need for building successful searching applications.

## Normalized Cross-Correlation

The following is the basic concept of correlation: Consider a subimage w(xy) of size K × L within an image f(xy) of size M × N, where K ≤ M and L ≤ M. The correlation between w(xy) and f(xy) at a point (ij) is given by

 C(i,j) = L – 1 ∑ x = 0 K – 1 ∑ y = 0 w(x, y)f(x + i, y + j)
 where i = 0, 1, . . . M – 1, i = 0, 1, . . . N – 1, and the summation is taken over the region in the image where w and f overlap.

The following figure illustrates the correlation procedure. Assume that the origin of the image f is at the top left corner. Correlation is the process of moving the template or subimage w around the image area and computing the value C in that area. This involves multiplying each pixel in the template by the image pixel that it overlaps and then summing the results over all the pixels of the template. The maximum value of C indicates the position where w best matches f. Correlation values are not accurate at the borders of the image. Basic correlation is very sensitive to amplitude changes in the image, such as intensity, and in the template. For example, if the intensity of the image f is doubled, so are the values of c. You can overcome sensitivity by computing the normalized correlation coefficient, which is defined as

R(ij) =

 L – 1 ∑ x = 0 K – 1 ∑ y = 0 (w(x,y) – w)(f(x + i,y + j) – f(i, j))
 12 L – 1 ∑ x = 0 K – 1 ∑ y = 0 (w(x,y) – w)2 L – 1 ∑ x = 0 K – 1 ∑ y = 0 (f(x + i,y + j) – f(i, j))2

where w (calculated only once) is the average intensity value of the pixels in the template w. The variable f is the average value of f in the region coincident with the current location of w. The value of R lies in the range –1 to  1 and is independent of scale changes in the intensity values of f and w.