• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

How do I calculate a Histogram equalization?

Contents

  • Histogram
  • Accumulated histogram
  • Normalized histogram
  • See also

Let's say you have the following greyscale image:

$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

  • Some code
  • Code and examples

Published

Sep 11, 2013
by Martin Thoma

Category

My bits and bytes

Tags

  • KogSys 5

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor