Signal Processing Toolbox |
Two-dimensional cross-correlation
Syntax
Description
returns the cross-correlation of matrices C = xcorr2(A,B)
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
is the autocorrelation matrix of input matrix xcorr2(A)
A
. It is identical to xco
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:
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:
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
xcorr | xcov |
© 1994-2005 The MathWorks, Inc.