Calculate histogram

Naverick used Ask the Experts™

Im totally new to image processing. I was hoping if somebody could tell me how to calculate the histogram (HSV nad RGB) of an image in C without using the built in library function of OpenCv... cvCalcHist.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

If you can draw this image - you already have the RGB. The image, if it's ready to be drawn on the screen, it is the DIB section that has the bitarray - this is RGB.  In worst case you can use GetPixel.
But here is another way (HSV->RGB):
Here is RGB->HSV:
or here:
Here is the theory:
Top Expert 2009
>> how to calculate the histogram (HSV nad RGB)

Calculating the histogram is relatively straightforward. For each color component (for example R, G and B), you keep a separate histogram. A histogram consists of a counter for each of the possible values of that color component (for example 256 counters, one for each of the values 0 through 255).

Then you just go through all the pixels in the image, extract the separate components (for example R, G and B), and increment the appropriate counter by 1 for each of the components.

When you've processed the whole image, you have 3 histograms, one for each of the color components.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial