Main Content

2-D Correlation

Compute 2-D correlation of two input matrices

  • 2-D Correlation block

Libraries:
Computer Vision Toolbox / Statistics

Description

The 2-D Correlation block computes the two-dimensional cross-correlation between two input matrices.

Examples

Ports

Input

expand all

First input matrix, specified as an M-by-N matrix. The two input matrices must have data types in the same category such as double, single, unsigned integer (uint8,uint16,uint32,uint64), or integer (int8,int16,int32,int64).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Complex Number Support: Yes

Second input matrix, specified as a P-by-Q matrix. The two input matrices must have data types in the same category such as double, single, unsigned integer (uint8,uint16,uint32,uint64), or integer (int8,int16,int32,int64).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Complex Number Support: Yes

Output

expand all

Calculated cross-correlation, returned as a scalar, vector, or matrix. The size of the cross-correlation output depends on the Output size parameter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point
Complex Number Support: Yes

Parameters

expand all

Main

Size of the cross-correlation output.

  • If you choose Full, the output has the dimensions (M+P-1)-by-(N+Q-1).

  • If you choose Same as input port I1, the output has the same dimensions as the input at port I1. The block returns the central part of cross-correlation matrix, which is the same size as the input at port I1.

  • If you choose Valid, the output has the dimensions (M-P+1)-by-(N-Q+1). The block returns only parts of the cross-correlation matrix that are computed without zero-padded edges.

Select this parameter, if the data types of the inputs are floating-point. The values of the cross-correlation output are normalized to [0, 1].

Data Types

For details on the fixed-point block parameters, see Specify Fixed-Point Attributes for Blocks (DSP System Toolbox).

Select this parameter to prevent the fixed-point tools from overriding the data types you specify on this block. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).

Block Characteristics

Data Types

double | fixed point | integer | single

Multidimensional Signals

no

Variable-Size Signals

yes

Algorithms

Given two input matrices, I1 and I2, that are size M-by-N and P-by-Q, the 2-D cross-correlation value at the point (k,l) is given by

C(k,l)=m=0M1n=0N1I1(m,n)I2¯(m+k,n+l).

The normalized cross-correlation value at the point (k,l) is calculated as

CN(k,l)=m=0M1n=0N1I1(m,n)I2¯(m+k,n+l)m=0M1n=0N1I1(m,n)2m=0M1n=0N1I2¯(m+k,n+l)2,where,0k<M+P10l<N+Q1

Suppose I1 and I2 are matrices with dimensions (4,3) and (2,2). The following figure shows how the block computes cross-correlation value for the point I1(1,3), which refers to the second row and fourth column in zero-based indexing.

The cross-correlation value for the point I1(1,3) is computed using these steps:

  1. Slide the center element of I2 so that it 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 cross-correlation value for the point I1(1,3) is 18+81+156+73+145+167+134+209+222=585.

The normalized cross-correlation value for the point I1(1,3) is

585I1p2I22=0.8070.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a