Compute normalized cross-correlation.
Returns the cross-correlation coefficient of matrices template and img, a matrix of (roughly) the same size as img with values ranging between -1 and 1.
Normalized correlation is mostly used for template matching, finding an object or pattern, template, withing an image img. Higher values on the output show their locations, even in the presence of noise.
img = randi (255, 600, 400); template = imnoise (img(100:150, 300:320), "gaussian"); cc = normxcorr2 (template, img); [r, c] = find (cc == max (cc(:))) ⇒ 150 ⇒ 320
Despite the function name, this function will accept input with an arbitrary number of dimensions.
Note that the size of the cross-correlation array is slightly bigger than img because the input image is padded during the calculation.
See also: conv2, convn, corr2, xcorr, xcorr2.
Package: image