Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the 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=\frac{\sum _{m}\sum _{n}\left({A}_{mn}-\overline{A}\right)\left({B}_{mn}-\overline{B}\right)}{\sqrt{\left(\sum _{m}\sum _{n}{\left({A}_{mn}-\overline{A}\right)}^{2}\right)\left(\sum _{m}\sum _{n}{\left({B}_{mn}-\overline{B}\right)}^{2}\right)}}$`

where $\overline{A}$ `=` `mean2(A)`, and $\overline{B}$ `=` `mean2(B)`.