Thursday, October 25, 2012

Histogram Equalization

A histogram is a graphical representation of the tonal values of an image. In a greyscale image, we have only one channel, and its value range from 0 to 255. Based on the number of pixels falling under a particular tonal value we plot the histogram graph. 

Grey histogram Equalization

In Grey histogram equalization we enhance the contrast of images by using usable pixel values in the image to the close contrast values of the display device. This is accomplished by spreading out the most frequent intensity values to the neighboring intensities. First, we compute the cumulative distributive function of the histogram. Then we use the general histogram formula to accomplish this.
The general histogram equalization formula is:

Where cdfmin is the minimum value of the cumulative distribution function, M × N gives the image's number of pixels and L is the number of grey levels used. Some sample results are shown below. Note that equalization is done within the two regions of interest.

(a)   Original Image

(b)   Histogram for ROI 1 before and after equalization ( x = 10, y = 10, sx = 300, sy = 300)



(c)    Histogram for ROI 2 before and after equalization ( x =315, y =315, sx = 400, sy = 400)

(d) Result - equalized image



Color Histogram Generation (RGB)

In color images, we have three channels namely red, green and blue. Therefore in order to generate the histograms, we apply the same principle for greyscale images separately for each channel.

Color Histogram Equalization (RGB)

In color histogram normalization we apply the same method used for grey-scale equalization for each of the three channels separately. The results are shown below.

(a)   Original Image
(b) Histogram for ROI 1 – Before and after equalization - RGB ( x = 10, y = 10, sx = 300, sy = 300)

(c)   Result - equalized image (all channels together)

(d)   Equalization separately - Original and  RGB channels respectively (Clockwise)



               

HSI histogram generation

HSI is a color model which is more intuitive and perceptually relevant to co-ordinate space. It has wide applications in the field of computer graphics and vision. Like RGB it has three channels namely Hue (H), Saturation(S), and Intensity (I). Hue falls from 0 to 360 degrees, and the other two fall from 0 to 1. For the sake of calculations, we make saturation fall between 0 to 99 and Intensity fall from 0 to 255 respectively. For HSI histogram generation we need to convert the RGB color model to HSI. We then generate a histogram for the three channels separately. The formula for HSI to RGB and from RGB to HSI is below from the Gonzales and Woods text.


HSI histogram equalization

After generating HSI histogram we then compute the equalized histogram from it. For that, we make use of the same histogram formula we used before. After equalization, we then convert it back to RGB image for display. The resulted images are shown below.

(a)   HSI histogram for I channel – Before and after equalization (x = 10, y =10, sx = 300, sy = 300)
(b)    HSI equalization (original and I channel respectively)


Program

Some of the functions I used to do the above operations in C++ are in Git here. Note that the custom class Image and ROI are not included here. However, this code is enough for explaining the main logic.



No comments:

Post a Comment