This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

corr2

2-D correlation coefficient

Syntax

R = corr2(A,B)

Description

example

R = corr2(A,B) returns the 2-D correlation coefficient R between arrays A and B.

You optionally can compute the correlation coefficient using a GPU (requires Parallel Computing Toolbox™). For more information, see Image Processing on a GPU.

Examples

Compute the correlation coefficient

Compute the correlation coefficient between an image and the same image processed with a median filter.

I = imread('pout.tif');
J = medfilt2(I);
R = corr2(I,J)
R = 0.9959

Compute the Correlation Coefficient on a GPU

Compute the correlation coefficient on a GPU between an image and the same image processed using standard deviation filtering.

I = gpuArray(imread('pout.tif'));
J = stdfilt(I);
R = corr2(I,J)
R =

    0.2762

Input Arguments

collapse all

First input array, specified as a numeric or logical array.

To perform the computation using a GPU, specify A as a gpuArray that contains a numeric or logical array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Second input array, specified as a numeric or logical array. B has the same size as the first input array, A.

To perform the computation using a GPU, specify B as a gpuArray that contains a numeric or logical array.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Output Arguments

collapse all

Correlation coefficient, returned as a numeric scalar.

If the correlation coefficient is computed using a GPU, then R is returned as a gpuArray containing a numeric scalar.

Data Types: double

Algorithms

corr2 computes the correlation coefficient using

r=mn(AmnA¯)(BmnB¯)(mn(AmnA¯)2)(mn(BmnB¯)2)

where A¯ = mean2(A), and B¯ = mean2(B).

Extended Capabilities

See Also

|

Introduced before R2006a