# 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™).```

## Examples

collapse all

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 ```

## Input Arguments

collapse all

First input array, specified as 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`.

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

## Output Arguments

collapse all

Correlation coefficient, returned as 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)`.