next up previous
Next: Histogram Equalization Up: contrast_transform Previous: contrast_transform

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 density probability distribution of the pixel values in the image over the entire gray scale range. The ith entry of the histogram is $h[i]=n_i/M/N$ ( $i=0,\cdots, L-1=255$) for the probability of a randomly chosen pixel to have the gray level $i$, where $n_i$ is the number of pixels of gray level $i$ in an image of size $M\times N$. Given $h[i]$, we can also find the cumulative distribution function:

\begin{displaymath}H[j]=\sum_{i=0}^j h[i],\;\;\;\;\;\;\;(j=0,\cdots,L-1)\end{displaymath}

We obviously have

\begin{displaymath}H[L-1]=\sum_{i=0}^{L-1} h[i]=1 \end{displaymath}

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 can be modified according to various needs by a gray level mapping function specified by the user:

\begin{displaymath}y=f(x) \end{displaymath}

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 the input image.

Programming issues:

The above mapping functions can be carried out for each of the pixels in the image. However, this is not the most efficient way computationally. A better way for implementing the function mapping is to 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 used as the gray level of the corresponding pixel of the output image. By using 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:


next up previous
Next: Histogram Equalization Up: contrast_transform Previous: contrast_transform
Ruye Wang 2016-09-29