One of the todo items for the road to beta is an automatic image level adjuster. Put simply, it’s the easy button for histogram manipulation. Advanced graphics nerds know how to use curves to modify an image’s histogram. Everyone else just hits “auto adjust” and BOOYA…the image magically looks better (sometimes).
For the uninitiated, histograms are graphs that show how colors are distributed throughout an image. Each element in a color space has 255 possible values. Knowing that, we design our histogram to have 255 possible x-axis values. What we do is inspect each pixel’s color, and whatever value it is (from 0 – 255) we increment that point in the graph by one unit.
In the upper right hand corner you’ll see the newly minted histogram window for PhotoMonkee. The peaks on the left side of the graph show that there are a lot of red, green and blue pixels with values between 0 and 75 with not many in the middle to higher range. RGB values (that’s short for red, green and blue in the nerd circles) are cool to see on a graph but what we’re really after is a completely different color space called HSL or Hue, Saturation and Lightness.
Here’s the histogram in HSL space for the cork image on the left. On the right is the image of just the Lightness parameter.
What we want to do is get the lightness component to use more of its available spectrum. You can see on the very right edge of the graph there are no values being used. That means we can “stretch” the graph out to use the entire spread of values. After “stretching” the graph we then go back and map the lightness value of each pixel to its new spot on the graph. The result looks like so:
If you compare the two images you’ll note that the overall brightness of the resultant image has been increase but the color values have remained relatively unchanged. There is still plenty of tweaking to be done but this is a fantastic start.
To calculate the RGB and HSL histograms for a 1920×1080 image takes roughly 90 milliseconds. Stunning when you consider converting from RGB to HSL color space for every pixel isn’t exactly a cheap conversion. Also, my way of incrementing the ‘buckets’ is ridiculously slow and contentious since I’m using OpenCL’s atomic_inc() extension. I’ll have to revisit this later for further optimization.
Viva Le Histogram!



