Histogram and Normalized Histogram in C# by asif

Overview

The histogram in the context of image processing is the operation by which the occurrences of each intensity value in the image is shown. Normally, the histogram is a graph showing the number of pixels in an image at each different intensity value found in that image. For an 8-bit grayscale image there are 256 different possible intensities, and so the histogram will graphically display 256 numbers showing the distribution of pixels amongst those grayscale values.

Normalized Histogram

Normalized histogram is the histogram in which the no. of pixels for each intensity level is divided by the total no. of pixels in the image. Hence, if the whole of the image is of the same color, e.g. a white paper picture, then its normalized histogram contains only one non-zero number, and that is 1 for the 255th intensity level, which is the intensity level for the white color.

Normalized Histogram(i)=(Total Number of Pixels of Intensity i)/(Total Number of Pixels)

General Working
The image is scanned in a single pass and a running count of the number of pixels found at each intensity value is kept. This is then used to construct a suitable histogram. This operation is performed in a single pass algorithm, surfing each pixel once, and increment the no. of occurrences of the specific intensity level depending upon the intensity of that particular pixel.

Guidelines for Use

Following is the histogram:

obtained by the application of the histogram operation of the following image:

The histogram graph is spread over all the intensity levels. But if the image is dark then the histogram graph is denser near the low intensity region. And denser in the high intensity region, when the image is the bright one.

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

In this project the histogram is obtained by calculating the no. of pixels for each gray image intensity level. Then calculate the maximum no. of pixels for one intensity level. Then divide each of the 256 no. of pixels one for each intensity level by the maximum no. of pixels by max and multiply by 300. Thus the maximum length of an intensity level in the image is 300.

Attachments:

Project Files: Histogram.zip