Image Histogram

Image histogram is a type of histogram that represent the lightness distribution in digital image. In order to clarify the idea, I am going to give an example.

Suppose we have an image, say depth is 2 bits (2 bpp). Therefore, the possibility value 0 – 3.

Sample Image

As I mentioned, histogram is going to represent the distribution of pixel value. You can see, there are 5 pixels with value 0, 7 pixels with value 1, 9 pixels with value 2 and 4 pixels with value 3. These information is tabulated as follows.

Pixel distribution

As you know, like histogram in math, histogram is presented using graph. The following graph represent the distribution in image above.

Image Histogram

Here is the simple implementation that i wrote in C++.

int* calculate_histogram(char* image, int width, int height){
	long i;
	int k;
	static int histogram[256];
	for (i = 0; i<width * height; i++){
		k = (int)image[i];
		histogram[k] = histogram[k] + 1;
	return histogram;

Char * image, is the image pixel in 1D array and I think width and height are clear. :)
So, what is the advantage after we got histogram of an image? Actually, lots of advantages. But I am going to give one of them.

I guess you have already known about negative image. If you enough “mature” or you experienced with the technology before digital image you must know. Here is my experiment about negative image.



I used C++ to produce lena-negative from lena color image. Here is my code.

int * histo;
	histo = new int[256];
	histo = calculate_histogram(buffer, w, h);
	int max = get_max_intensity(histo);
	char * buffer2;
	buffer2 = new char[w * h * 3 ];
	long t = 0;
	while (t < w * h * 3){
		buffer2[t] = max - buffer[t];
		t += 1;

The algorithm is for each of pixel subtract with the maximal intensity. you can modify the algorithm and you will get the different results. Here some example of modified algorithm.




Okay, hope you enjoy with these images. See you. :D

References :

Leave a Reply

Your email address will not be published. Required fields are marked *