IMAGE ENHANCEMENT USING CONTRAST STRETCHING ON RGB AND IHS DIGITAL IMAGE

Low contrast image has relatively bad quality since its information can not be directly interpreted by human eyes. It’s quality can be improved using contrast stretching operation. The objective of this paper is to design software for enhancement using contrast stretching on RGB and IHS digital image models. The operation is a point operation, that each pixel on the image is processed individually, by darkening dark pixels and brightening bright pixels. The development of the software was done using TBitmap class in Borland Delphi 6.0. Tests have been performed on BMP and PEG grayscale as well as color images. The test result shows that the developed software is capable to enhance the contrast of the sample images, which are shown by the expansion of the histograms of the images.


INTRODUCTION
Some color models are used in digital image processing to represent an image, e.g.RGB, IHS, YIQ, CIE, and CMY models.RGB model is frequently used since it is good to provide color information, although this model is not proper for some image processing operation.Some image processing operations force the use of a model other than RGB model, i.e.IHS model.Some of image processing operations for this model are pattern recognition and image compression.
An image can be analyzed by examining its histogram.Image histogram is a graph showing the frequency of every color contained in it.The horizontal axis of a histogram represents the value of the color (0-255), while the vertical axis shows the number of pixels of each color [4].Not all image can be easily analyzed, for example, image with low contrast.This kind of image is produced under low or uneven lighting.Low contrast image can be enhanced by contrast stretching.This operation is a point operation, where gray level of a pixel is mapped to another gray level depends on certain function.Point operation is an image operation in which each pixel of the image is processed independently to other pixels [1].By performing contrast enhancement, the image can be clearly obeserved and analyzed.
Recently, many image file formats exist, e.g.BMP, JPEG, GIF, ICO, and WMF.The way an image is saved depends on the need.For image transfer via internet, data compression and compatibility are needed.This paper used 2 image formats, i.e.BMP and JPEG.

MATERIAL AND METHOD
This paper processed 2-dimension still image which is represented in M x N matrix form, where M and N are the width and height of the image.The matrix can be treated as 2dimension array, representing x and y coordinates.
Contrast stretching can be done by employing GST (Gray Scale Transform) function as shown in Equation 1 [1].
K 0 is the pixel value of output image, K i is the pixel value of input image, G is the contrast strength coefficient, and P is the grayscale value that is used as center of contrast.
The design phase was divided into 2 steps, i.e. algorithm design in flowchart form and algorithm implementation.Figure 1 shows the flowchart of the developed system.The input can be either grayscale or true color image.If the input is a grayscale image, the program continues to the next process, i.e. contrast enhancement.But, if it is a true color image, the program proceeds to choose whether the user wants to do image conversion.If so, the RGB color image input will be converted to IHS model.This conversion process is to produce grayscale image.Else, the RGB image will be directly applied to contrast enhancement.The next step is to save the resulted image to either BMP or JPEG file.

Figure 1. Flowchart of the system
Following is the algorithm to implement improvement of image quality using contrast enhancement.

Algorithm to calculate intensity frequency
This algorithm is used to calculate the number of pixels that contains certain color intensity to determine the intensity frequencies.The algorithm for grayscale is as follow a).Take the information of bit per pixel of the image After all pixels are analyzed, the maximum count of all grayscale is calculated using the following algorithm.

f). Set maximum count
Max <> 0 then cMax=max; Max = 0 then cMax=0; g).Repeat for all pixels in the image For i:= 0 then 255; For 24 bit true color image, the algorithm is similar to the above.However, since each pixel has three color elements, the analysis was done for the three elements.

Algorithm for contrast enhancement
This algorithm is used to control the contrast of the image, which needs a tranformation using certain constants.The operation is done separately for each image format.Before saved into an array variable, the maximum and minimum value for the resulted image are determined.Folowing is the algoruthm for contrast ehnacement for grayscale image: a).Take the information of bit per pixel of the image FProses.Image1.Picture.Bitmap.PixelFormat = pf8bit; b).Repeat for all pixels in the image For i:= 0 to FProses.Image1.Picture.Height-1;For j:= 0 to FProses.Image1.Picture.Width-1; c).Take the value of the pixel being processed PC:= FProses.Image1.Picture.Bitmap.Scanline[i]; PH:= FProses.Image2.Picture.Bitmap.Scanline[i]; d).Calculate the value of the result temp:= Round(K*(PC[j]-P)+P); e).Apply value limiter, i.e. if the value of a pixel is greater than 255, then the pixel value is set to 255; and if the value of taht pixel is less than 0, then the pixel value is set to 0. If (temp > 255) then temp:= 255; If (temp < 0 then) temp:= 0; f).Put the pixel value in the image bitmap memory PH[i]:= temp; The algorithm for true color image is similar to the above, however the algorithm is applied for the three color elements (R, G and B).

RESULT AND DISCUSSION
The implementation of the program into a program was done using Delphi 6.0 Integrated Development Environment.The program was tested using several test images that have low contrast, with various tendency of brightness, i.e. dark color image, bright color image, as well as grayscale image.

Dark Color Image
Test image has low contrast and dark appearance.The quality of images possessing this kind of characteristic can be improved increasing by its contrast strength (G). Figure 2 shows an example of the result of applying the program on low contrast Bird.bmp.The result image was then represented in RGB color model can saved in a JPEG file.
Figure 2.a shows that the original image appears dark, with contrast strength coefficient (G) = 1 and center of contrast (P) = 0. Its original histogram for each color element (R,G,B) is narrow and located on the left part of its absica (Figure 2.b).This tells us that the image has low contrast.Figure 2.c is the result image of the contrast enhancement program using contrast strength coefficient (G) = 3 and center of contrast (P) = 0.The result image appears sharper compare to the original image.The histograms of all color elements are widened apart and cover all gray scale range, i.e. 0-255 (Figure 2.d).

Bright Image
Image that has low contrast and its histogram is mostly located to the right of the gray scale range is difficult to analyze, since the image appears too bright.To improve its quality can be done by adjusting the contrast strength coefficient (G) as well as the contrast center (P). Figure 3 is an example of light image.The result image was saved in to a BMP file.

Gray scale image
Gray scale image has the same values for all color elements (R,G,B).The original image was converted into IHS color model, after then be applied by contrast strecthing.

CONCLUSION
Based on the test result on the image samples, the developed software can be used to enhance the contrast of the images.The improvement of image quality can be seen by the expansion of its histogram by adjusting the contrast strength coefficient and the center of contrast.

Figure 2 .
Figure 2. Contrast Stretching on Bird.bmp,(a) original image (b) histogram of original image (R, G, B), (c) result image (d) histogram of result image

Figure 3 .
a shows the original 8 bit color image.The image is too bright, because its histograms for each elements are mostly at right side (high color value) as shown by Figure 3.b. Figure 3.c is the enhanced image using contrast strength coefficient (G) = 6 and contrast center (P) = 255.The result image is obviously easier to analyze.The histograms are widened to the left after the enhancement (Figure 3.d).

Figure 3 .
Figure 3. Contrast Stretching on Elephant.bmp,(a) original image (b) histogram of original image (R, G, B), (c) result image (d) histogram of result image

Figure 4 .
a shows an example of 8 bit color image before conversion, with original histograms for each color elements are shown in Figure4.b.The image was then converted from RGB color model to IHS.The intensity element of this color model was then processed using contrast enhancement algorithm.

Figure 4 .
c shows the intensity element of the IHS image, with its histogram shown in Figure 4.d.After applying contrast enhancement algorithm for gray scale image, the result image and its histogram can be shown in Figure 4.e and Figure 4.f, respectifully.It can be seen that the histogram of the result image is stretched for the whole gray scale values (0-255).