Signal Processing Toolbox Previous page   Next Page
xcorr2

Two-dimensional cross-correlation

Syntax

Description

C = xcorr2(A,B) returns the cross-correlation of matrices A and B with no scaling. xcorr2 is the two-dimensional version of xcorr. It has its maximum value when the two matrices are aligned so that they are shaped as similarly as possible.

If matrix A has dimensions (Ma, Na) and matrix B has dimensions (Mb, Nb), the equation for the two-dimensional discrete cross-correlation is

where and .

xcorr2(A) is the autocorrelation matrix of input matrix A. It is identical to xco

Examples

Output Matrix Size

If matrix I1 has dimensions (4,3) and matrix I2 has dimensions (2,2), the following equations determine the number of rows and columns of the output matrix:

The resulting matrix is



Computing a Specific Element

In cross-correlation, the value of an output element is computed as a weighted sum of neighboring elements. For example, suppose the first input matrix represents an image and is defined as

The second input matrix also represents an image and is defined as

The following figure shows how to compute the (2,4) output element (zero-based indexing) using these steps:

  1. Slide the center element of I2 so that lies on top of the (1,3) element of I1.
  2. Multiply each weight in I2 by the element of I1 underneath.
  3. Sum the individual products from step 2.

The (2,4) output element from the cross-correlation is

The normalized cross-correlation of the (2,4) output element is

where I1p = [1 8 15; 7 14 16; 13 20 22].

See Also

conv2, filter2, xcorr


Previous page  xcorr xcov Next page

© 1994-2005 The MathWorks, Inc.