Gray level mapping

Histogram:

In a typical 8-bit image, there are $L=2^8=256$ discrete gray scale levels from 0 to $2^8-1=255=L-1$. The histogram of an image represents the probability density function (pdf) of the pixel values in the image over the entire gray scale range. The ith entry of the histogram is

$\displaystyle h[i]=\frac{n_i}{M\,N},\;\;\;\;\;\;\;(i=0,\cdots,L-1)$ (1)

where $n_i$ is the number of pixels of gray level $i$ in an image of size $M\times N$. $h[l]$ is an estimate of the probability for a randomly chosen pixel to take the gray level $i$. Given $h[i]$, we can further get the cumulative distribution function:

$\displaystyle H[j]=\sum_{i=0}^j h[i],\;\;\;\;\;\;\;(j=0,\cdots,L-1)$ (2)

We obviously have

$\displaystyle H[L-1]=\sum_{i=0}^{L-1} h[i]=\frac{1}{MN}\sum_{i=0}^{L-1}n_i=1$ (3)

Both the density and cumulative distribution functions $h$ and $H$ can be displayed graphically as an image.

Gray level mapping:

The appearance (brightness, contrast, etc.) of an image represented by its histogram can be modified by a user specified gray level mapping function $y=f(x)$ where $x=x[m,n]$ is a pixel in the input image and $y=y[m,n]$ is the corresponding pixel in the output image. This mapping function can be specified in different ways, such as a piecewise linear function, or based on the histogram of either or both of the input and output images.

Programming issues:

The above mapping functions can be carried out for each pixel in the image. However, this is not an efficient way computationally. A more effieicnt way to carry out this gray scale mapping is to u= use a lookup table, which stores the pre-computed mapping for each of the $L$ gray levels. The gray level of a pixel in the input image is used as the address to the table and the content of the table entry is the gray level of the corresponding pixel of the output image. Based on the lookup table, the mapping function only needs to be carried out $L$ times, instead of $M\times N$ ($>> L$) times (size of the image).

lookup_table.gif

Common mapping functions:

Here are some common gray scale mapping functions $y=f(x)$:

Code Segments: