CS6825: Computer Vision

Histogram Equalization

Original Constrast Stretched
Original Histogram Equalized

Histogram equalization is a common technique for enhancing the appearance of images. Suppose we have an image which is predominantly dark. Then its histogram would be skewed towards the lower end of the grey scale and all the image detail is compressed into the dark end of the histogram. If we could `stretch out' the grey levels at the dark end to produce a more uniformly distributed histogram then the image would become much clearer.

Figure: The original image and its histogram, and the equalized versions. Both images are quantized to 64 grey levels.
Histogram equalization involves finding a grey scale transformation function that creates an output image with a uniform histogram (or nearly so).

How do we determine this grey scale transformation function? Assume our grey levels are continuous and have been normalized to lie between 0 and 1.

We must find a transformation T that maps grey values r in the input image F to grey values s = T(r) in the transformed image $\hat{F}$.

It is assumed that

  • T is single valued and monotonically increasing, and
  • $0 \leq T(r) \leq 1$ for $ 0 \leq r \leq 1$.
The inverse transformation from s to r is given by

r = T-1(s).

If one takes the histogram for the input image and normalizes it so that the area under the histogram is 1, we have a probability distribution for grey levels in the input image Pr(r).

If we transform the input image to get s = T(r) what is the probability distribution Ps(s) ?

From probability theory it turns out that

\begin{displaymath}

P_{s}(s) = P_{r}(r)\frac{dr}{ds}, \end{displaymath}

where r = T-1(s).

Consider the transformation

\begin{displaymath}

s = T(r) = \int_{0}^{r}P_{r}(w)dw. \end{displaymath}

This is the cumulative distribution function of r. Using this definition of T we see that the derivative of s with respect to r is

Substituting this back into the expression for Ps, we get

\begin{displaymath}

P_{s}(s) = P_{r}(r) \frac{1}{P_{r}(r)} = 1 \end{displaymath}

for all $s,
where 0 \leq s \leq 1$.Thus, Ps(s) is now a uniform distribution function, which is what we want.

Discrete Formulation

We first need to determine the probability distribution of grey levels in the input image. Now

where nk is the number of pixels having grey level k, and N is the total number of pixels in the image.

The transformation now becomes

Note that $0 \leq r_{k} \leq 1$, the index $ k = 0,1,2,\ldots ,255$,and $0 \leq s_{k} \leq 1$.

The values of sk will have to be scaled up by 255 and rounded to the nearest integer so that the output values of this transformation will range from 0 to 255. Thus the discretization and rounding of sk to the nearest integer will mean that the transformed image will not have a perfectly uniform histogram.

© Lynne Grewe