The 2-D cross-correlation of an
M-by-N matrix, X, and a
P-by-Q matrix, H, is a
matrix, C, of size M+P–1 by
N+Q–1. Its elements are given by
where the bar over H denotes complex conjugation.
The output matrix, C(k,l), has negative and
positive row and column indices.
A negative row index corresponds to an upward shift of the rows of
H.
A negative column index corresponds to a leftward shift of the columns
of H.
A positive row index corresponds to a downward shift of the rows of
H.
A positive column index corresponds to a rightward shift of the
columns of H.
To cast the indices in MATLAB® form, add the size of H: the element
C(k,l) corresponds to
C(k+P,l+Q)
in the workspace.
For example, consider this 2-D cross-correlation:
C =
6 11 11 5
10 18 18 8
6 10 10 4
2 3 3 1
The C(1,1)
element in the output corresponds to
C(1–3,1–2) = C(–2,–1) in the
defining equation, which uses zero-based indexing. To compute the
C(1,1)
element, shift H
two rows up and
one column to the left. Accordingly, the only product in the cross-correlation sum
is X(1,1)*H(3,2) = 6
. Using the defining equation, you obtain
with all other terms in the double sum equal to zero.