Calculate histogram

Naverick
Naverick used Ask the Experts™
on
Hi

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.
Comment
Watch Question

Do more with

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

Commented:
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):  http://www.nunosantos.net/?p=114
Here is RGB->HSV: http://www.deadbeef.com/index.php/converting_rgb_to_hsv_in_c
or here: http://www.programmersheaven.com/download/15218/download.aspx
Here is the theory:  http://en.wikipedia.org/wiki/HSL_and_HSV
 
Top Expert 2009
Commented:
>> 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