Next: Histogram Equalization Up: contrast_transform Previous: contrast_transform

## Gray level mapping

Histogram:

In a typical 8-bit image, there are discrete gray scale levels from 0 to . 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 ( ) for the probability of a randomly chosen pixel to have the gray level , where is the number of pixels of gray level in an image of size . Given , we can also find the cumulative distribution function:

We obviously have

Both the density and cumulative distribution functions and 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:

where is a pixel in the input image and 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 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 times, instead of () times (size of the image).

Common mapping functions:

Here are some common gray scale mapping functions :

• Thresholding:

As a special case of piecewise linear mapping, thresholding is a simple way to do image segmentation, in particular, when the histogram of the image is bimodal with two peaks separated by a valley, typically corresponding to some object in the image and the background. A thresholding mapping maps all pixel values below a specified threshold to zero and all above to 255.

• Negative image:

This mapping is shown below which generates the negative of the input image:

• Min-max linear stretch:

This is a piecewise linear mapping between the input and output images of three linear segments with slopes 0 for , for , and 0 for . The greater than 1 slope in the middle range stretches the dynamic range of the image to use all gray levels available in the display.

• Linear stretch based on histogram:

If in the image there are only a small number of pixels close to minimum gray level 0 and the maximum gray level , and the gray level of most of the pixels are concentrated in the middle range (gray) of the histogram, the above linear stretch method based on the minimum and maximum gray levels has very limited effect (as the slope is very close to 1).

In this case we can push a small percentage (e.g., , ) of gray levels at the two ends of the histogram toward 0 and .

• Piecewise linear mapping:

A mapping function can be specified by a set of break-points , with neighboring points connected by straight lines, such as shown here:

For example, to increase the contrast of the image of Paolina, we can linearly stretch the gray scales of the image so that the darkest and brightest gray levels are mapped to 0 and 255, respectively.

Code Segments:

• Histogram: Here and are the density and cumulative distribution functions.

• Find cut-off levels:

Assume and are fractions such as or .

• Build lookup table:

• Obtain output:

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