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:
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 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 :
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.
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 .
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.
Assume and are fractions such as or .