Contrast stretching (often called normalization) is a simple image enhancement technique that attempts to improve the contrast in an image by `stretching’ the range of intensity values it contains to span a desired range of values, e.g. the the full range of pixel values that the image type concerned allows. Low contrast images can be due to the poor illumination, lack of dynamic range in the imaging sensor, or due to the wrong setting of the lens. The idea behind the contrast stretching is to increase the dynamic range of intensity level in the processed image.
The general working of the contrast stretching operation on grayscale image is to apply the following equation on each of the pixels in the input image to form the corresponding output image pixel:
where, I( x,y ) represents the images, on the left side it represents the output image, while on the right side it represents the xth pixel in the yth column in the input image. In this equation the “min” and “max” are the minimum intensity value and the minimum intensity value in the current image. Here “no. of intensity levels” shows the total number of intensity values that can be assigned to a pixel. For example, normally in the gray-level images, the lowest possible intensity is 0, and the highest intensity value is 255. Thus “no. of intensity levels” is equal to 255.
The contrast stretching operation is applied on the grayscale images in two passes. In the first pass the algorithm calculates the minimum and the maximum intensity values in the image, and in the second pass through the image, the above formula is applied on the pixels.
Guidelines for Use
The visual effects can be improved by using contrast stretching. For example take the following image:
After applying the contrast stretching operation on the image the following image is obtained:
The algorithm is coded in C# using unsafe so the quality and speed of the program may not be affected. The class BitmapData is used to read and process the pixels in the image. This is the specialty of C# to provide such a speed even on image processing applications. There is a set of modules that are designed to implement the algorithm. The interface designed for the sample project as:
If you have the low contrast image, by choosing in the browser opened when you click File>Open, then click Operation>Contrast Stretch, the stretched image will be displayed in the imagebox.
Project Files: Contrast_Stretching.zip