#### Previous topic

medpy.metric.histogram.chi_square

#### Next topic

medpy.metric.histogram.correlate_1

# medpy.metric.histogram.correlate¶

medpy.metric.histogram.correlate(h1, h2)[source]

Correlation between two histograms.

The histogram correlation between two histograms $$H$$ and $$H'$$ of size $$m$$ is defined as:

$d_{corr}(H, H') = \frac{ \sum_{m=1}^M (H_m-\bar{H}) \cdot (H'_m-\bar{H'}) }{ \sqrt{\sum_{m=1}^M (H_m-\bar{H})^2 \cdot \sum_{m=1}^M (H'_m-\bar{H'})^2} }$

with $$\bar{H}$$ and $$\bar{H'}$$ being the mean values of $$H$$ resp. $$H'$$

Attributes:

• not a metric, a similarity

Attributes for normalized histograms:

• $$d(H, H')\in[-1, 1]$$
• $$d(H, H) = 1$$
• $$d(H, H') = d(H', H)$$

Attributes for not-normalized histograms:

• $$d(H, H')\in[-1, 1]$$
• $$d(H, H) = 1$$
• $$d(H, H') = d(H', H)$$

Attributes for not-equal histograms:

• not applicable
Parameters: h1 : sequence The first histogram. h2 : sequence The second histogram, same bins as h1. correlate : float Correlation between the histograms.

Notes

Returns 0 if one of h1 or h2 contain only zeros.