Histogram is a graphical representation of the
tonal values of an image. In 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 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 histogram. Then we use the general histogram formula to
accomplish this.

The general histogram equalization formula is:

Where cdf

_{min}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 region 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)*

**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*

**HSI histogram generation**

HSI is a color model which is more intuitive and
perceptually relevant 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 other two
falls from 0 to 1. For the sake of calculations we make saturation to fall
between 0 to 99 and Intensity to fall from 0 to 255 respectively. For HSI
histogram generation we need to convert the RGB color model to HSI. We then
generate 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)*

**Program**

Some of the functions I used to do 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.