How do I calculate a Histogram equalization?

· by

Contents

Let's say you have the following greyscale image:

Before and after: low-contrast gray image with a bunched histogram and a high-contrast version with an evenly spread histogram
Histogram equalization spreads the gray values.

\(A = \begin{pmatrix} 255 & 50 & 255\\ 0 & 50 & 50 \end{pmatrix}\)

Histogram

Now the histogram is a function \(H: [0,255] \rightarrow \mathbb{N}_0\).

The histogram of \(A\) is

\(H(x) := \begin{cases} 1 &\text{, if } x = 0\\ 3 &\text{, if } x = 50\\ 2 &\text{, if } x = 255 \end{cases}\)

Accumulated histogram

The accumulated histogram \(H_\alpha: [0,255] \rightarrow \mathbb{N}_0\) is defined as

\(H_\alpha(x) := \sum_{i=0}^x H(i)\)

This means, in the given example you get

\(H_\alpha(x) := \begin{cases} 1 &\text{, if } x < 50\\ 4 &\text{, if } 50 \leq x < 255\\ 6 &\text{, if } x = 255 \end{cases}\)

Normalized histogram

The normalized histogram is defined as \(H_n(x) := \mathrm{round}(\frac{255}{w \cdot h} \cdot H_\alpha(x))\) where \(w\) is the width of the image and \(h\) is the height of the image.

In our example it's:

\(H_n(x) := \begin{cases} 43 &\text{, if } x < 50\\ 170 &\text{, if } 50 \leq x < 255\\ 255 &\text{, if } x = 255 \end{cases}\)

So the resulting image is

\(A = \begin{pmatrix} 255 & 170 & 255\\ 43 & 170 & 170 \end{pmatrix}\)

See also