Intensity Histogram using C++ and OpenCV: Image Processing



The histogram of a digital image with gray levels in the range [0, L-1] is a discrete function h(rk) = nk, where rk is the kth gray level and nk is the number of pixels in the image having gray level rk.

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 among those grayscale values.


1. Assign zero values to all elements of the array hf;
2. For all pixel (x, y) of the image f, increment hf [f(x, y)] by 1.

Source Code


Input Image

Output Histogram


SHARE Intensity Histogram using C++ and OpenCV: Image Processing

You may also like...

6 Responses

  1. mrter2000 says:

    1>main.cpp(46): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data

  2. Anonymous says:

    histogram[i] = floor(((double)histogram[i]/max)*histImage.rows);

  3. How to plot continuous histogram? Here,this code generates discrete one.

  4. Anonymous says:

    can we add vales of x and y like a graph

  5. Unknown says:

    can you give me color histogram code

Leave a Reply

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