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.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

2-D correlation coefficient

`R = corr2(A,B)`

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

`corr2`

computes the correlation coefficient using

$$r=\frac{{\displaystyle \sum _{m}{\displaystyle \sum _{n}({A}_{mn}-\overline{A})({B}_{mn}-\overline{B})}}}{\sqrt{\left({\displaystyle \sum _{m}{\displaystyle \sum _{n}{\left({A}_{mn}-\overline{A}\right)}^{2}}}\right)\left({\displaystyle \sum _{m}{\displaystyle \sum _{n}{\left({B}_{mn}-\overline{B}\right)}^{2}}}\right)}}$$

where $$\overline{A}$$
`=`

`mean2(A)`

, and $$\overline{B}$$
`=`

`mean2(B)`

.