GrayLevel Image Contras Stretching in C#

Overview
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.
General Working
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:
The erosion can also be applied on the graylevel images also in a single pass. During the passing through the image, the structuring element is applied on each pixel of the image, such that the origin of the structuring element is applied on that particular pixel. In this case the corresponding pixel of the output image contains the minimum of the pixels surrounding it. In this case, only those pixels are compared with each other, where the structuring element contains.
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:
Sample Project:
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 speicality 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.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Basic Image Processing in Csharp

The C# provides a good support for processing on the image, and the purpose of this article...

Implementation Of Branch And Bound Algorithm

What is Branch and Bound Algorithm? These notes follow the discussion of branch and...

Implementation of Calculating the RTS Invariant Moments Of Area

Why Using Moments of Area? It is seen that the usage of moments of area highly...

Conversion of a Color Image to a Grayscale Image

What is a Color Image? It is possible to construct (almost) all visible colors by...

Conversion of a Color Image to a Binary Image

What is a Binary Image? Binary images are images whose pixels have only two possible...