How Digital Images Are Stored
This 200% crop shows individual pixels |
The human eye can only distinguish between 130 or so different shades of each hue. Any more, and the different shades appear to be a continuous spread. A single byte in a computer contains 8 bits, which can store numbers from 0-255, making it a convenient container for each band of a pixel. Expressing a color using fewer than 8 bits per band causes an effect known as "posterization," where you can clearly see the difference between adjacent shades of a given hue.
A 16-color (4-bit) image easily shows the different shades. The peaks in the histogram indicate which pixel values are present in the image. |
What Is a Histogram?
A "histogram" is a list of numbers containing one entry for each possible value that a pixel can have (256 entries for an 8-bit image). Each list entry counts the number of pixels in the image which contain that value. For example, a monochrome, 10x10 pixel image that is pure black (color value 0) with one white spot (color value 255) will have a histogram containing 99 in the "0" entry and 1 in the "255" entry. The more evenly distributed the color values are throughout the image, the more similar the values will be at each entry in the histogram. A very bright image, like a polar bear in its native environment, will have a histogram containing much higher values in its upper entries (200+). A very dark image, such as the night sky, will contain much higher values in its lower entries (below 50).
To enable quick interpretation, we prefer to display histograms graphically as a vertical bar graph. Dark entries (low pixel values) are on the left; light entries (high pixel values) are on the right. The more pixels in the image that contain each value, the taller the vertical line will be at that entry. When space is limited (as when displaying the histogram for a 14-bit raw image), multiple adjacent entries are summed together and then displayed as a single bar. Peaks in the histogram indicate pixel values (shades) that are very commonplace; valleys indicate uncommon values.
Practical Application of Histograms
This camera LCD shows the histograms for the three individual color bands as well as the combined brightness |
A histogram in which the values at the bright (right) end taper down to zero far below the right end of the scale indicates an image that has no truly bright pixels. Such an image will likely also have a high concentration of dark pixels, and the far left end of the scale will have a peak. There will be no discernible detail in most of these dark areas.
A histogram in which the highest levels are all bunched up against the right end will contain many areas which are very bright and lack any detail.
Click image for a full size 3D animation of a 2-dimensional histogram representing GCxGC gas chromatography data (my thesis research). By contrast, the histograms from digital photos are only 1-dimensional. |
If your histogram indicates that you've blown out your highlights (a large peak at the right side), you can tell your camera to underexpose the next shot. This will pull all the pixel values lower, spreading out those higher values and leaving fewer pixels that are blown out. The result is more discernible detail in the bright areas of your image.
Curves Adjustment
Most photo editing software will allow you to adjust the brightness of an image using what's typically called a "curves adjustment." This tool displays your original histogram and allows you to draw a curve across it that redefines the brightness of each pixel value. The curves tool uses a rectangular window to represent a 2D graph. The bottom (horizontal) edge of the graph represents the original pixel values, and the original histogram is typically shown along this line. The vertical axis represents the new pixel values. The left and lower ends indicate dark values while the right and upper ends represent bright values. In the examples shown below, the newly adjusted histogram is shown above the original one. These screen shots were taken from Digikam, my primary photo management application.
Properly exposed image with no adjustment |
Same image, adjusted darker using curves |
Same image, adjusted brighter using curves |
You can typically make this curve as wiggly as you like in order to change the brightness in only certain circumstances. Examples include making an "S" curve to add an area of high contrast or pulling just the bright pixels down lower in order to add definition to a highlight that's nearly blown out.
Same image, stretched contrast using curves. Note the posterization in the middle of the histogram. |
An 8-bit JPEG image only has 256 different shades available. If your curves adjustment is too dramatic, certain parts of the histogram will get compressed (by a more horizontal curve) and other parts will become more sparse (by a more vertical curve). These sparse areas will result in large jumps between adjacent pixel values in the image, causing posterization. To make sure your original image has plenty of information available to fill in these gaps, set your camera to record raw images whenever you plan to do any curves adjustment (or set it that way all the time, just to be safe). A 12-bit raw image can distinguish 16 discrete shades for every one shade in an 8-bit image, which gives much smoother spreads during dramatic curves adjustments.
Sensor Noise and "Expose to the Right"
Noise levels at low and high ISO settings |
The technique known as "exposing to the right" attempts to reduce the effect of sensor noise in an image and increase the amount of detail available in darker shades. The basic idea is exactly as the name implies: expose your image in the camera such that the histogram is as far to the right as possible without blowing out your highlights. This records your "true" pixel values using the largest numbers possible (255 at the brightest). The noise will still remain at its regular low values (say 5-10). The initial image on the camera may seem far too bright, but that's OK, because your histogram assures you that you haven't lost any detail to blown highlights. You can then use a curves adjustment on your computer to darken the image however you like. The darker you make it, the smaller every pixel value will become, and the lower your noise will become. While this technique can produce very clean images, the down side is that it requires postprocessing to be done on every single image. The JPEG that comes straight off your camera is worthless. As with any histogram modification (via curves or otherwise), you'll get much smoother results if you start off with a 12- or 14-bit raw image than if you start with only an 8-bit JPEG.
Hopefully this has given you a better idea of what a histogram means and how you can effectively use it to improve the images you create. If you've got any questions, please speak up in the comments section below. My Master's degree thesis and several jobs I've held over the years dealt directly with this subject (re: the pretty red & green 3D graphics above), so I'm pretty familiar with how it all works. I've tried to simplify the subject for this article, but I can get as technical as you'd like if you've got more advanced questions.
This article was originally written for Jedi.com in January 2009.
This is great information. It will take me awhile to process it, but I thank you for pointing me in this direction.
ReplyDelete