Histograms in Digital Photography
How Computers See Pictures
A digital image is composed of millions of pixels. A pixel specifies color using three numbers, each indicating the amount of color in each of the three primary color bands: red, green, and blue. Every color in an image is represented by combining appropriate levels of red, green and blue for each pixel. Lower numbers indicate darker colors and higher numbers indicate lighter colors.
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 JPEG image (like most image formats and most monitors) stores colors as three 8-bit values for each pixel. Many DSLR's and some advanced point & shoots can also record images in a "raw" format, which is a dump straight off the camera's sensor. Like the sensors themselves, raw images typically have a higher bit depth, meaning they store colors using more than 8 bits. DSLR's currently use either 12 or 14 bits for each RGB band. Some digital medium format cameras record 16 bits per band. Each added bit doubles the number of shades recorded for each hue. A 12-bit image provides 4096 different shades per hue. A 14-bit image provides 16,384 different shades. While the extra shades don't matter when printing or displaying an image on screen (the human eye can't appreciate the increase), they do allow you the flexibility to adjust the spread of these shades without causing posterization in ranges that have been stretched. More on that later.
What Is a Histogram?
Proper exposure typically means that you maintain detail in both the bright and dark areas of the image. A good way to see the distribution of shades from dark to light is by using a "histogram." A histogram is a list 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 10x10 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 this histogram for a 14-bit raw image), multiple adjacent entries are summed together than 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
Enough theory. Now for some real world application. The LCD screen on your camera can't be trusted to provide an accurate representation of the exposure for the image you just captured, especially in bright sunlight. In order to see how bright or dim the exposure really is, you must consult the histogram. Most digital cameras -- even point & shoots -- have an option to display the histogram for a photo that's been taken. Many allow you to view the histogram for all three bands (red, green, blue) individually. With a quick glance at the histogram, you can immediately tell whether your highlights (high pixel values) are too dim or whether they're blown out, eliminating any detail.
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 discernable 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.
A histogram with a perfect spread will have relatively even levels throughout the entire histogram, but then taper off right at both ends. This indicates no blown out highlighs or empty shadows. Of course, the desired look for a given photo may require large amounts of dark or light areas, so the perfect histogram may not indicate a perfect looking photo. The histogram is merely a tool to show you how your pixel values are distributed and whether you're likely to have lost detail at one end or the other.
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.
The curve that you draw runs from the lower left to the upper right. To determine the new value for an old pixel value, draw an imaginary line straight up from the old pixel's location on the horizontal axis until it hits the curve, then draw another line straight over to the left edge. The location at which the line hits the left edge indicates the new pixel value. A straight line between the two corners indicates a direct mapping between the new and old values, so the image is unchanged. If your imaginary line hits the left edge at a point that's lower than its original position (meaning the curve was drawn below the original diagonal), then that pixel value will become darker in the new image. If the line hits the left edge higher than its original location, then that pixel value will get brighter.
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.
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.
Excited about what you've learned?|
Shop for Adobe photo editing software at
Sensor Noise and "Expose to the Right"
One popular application for histogram modification is to increase the signal to noise ratio or decrease the amount of sensor noise present in an image in order to create the cleanest image possible. Digital noise manifests itself as a random amount (positive or negative) that's added onto each pixel value recorded by the camera's sensor. The higher your ISO, the larger this noise value may be, and the larger variety of pixel values you'd get if you were to photograph an object of a single, solid color. Because digital noise is additive rather than mulplicative, it has a much more significant effect on darker pixels (those which have smaller values) than it does on brighter pixels (those which have larger values). Noise shows up as speckling in shadow areas, especially in high-ISO photos. If you increase these dark pixel values using a curves adjustment (a mulplicative operation), the noise will become more exaggerated as it gets remapped higher up toward the medium tonal range. If you decrease a noisy pixel value, the percentage of noise in the original pixel value will remain constant, but the total amount of the noise will be decreased because the pixel value itself is being decreased.
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.
Do you like this site?
Help me keep it going by throwing a few pennies my direction.
last updated 19 Jan 2009 Obi-Wan (firstname.lastname@example.org)
Links on this page to Amazon are part of an affiliate program that helps keep Jedi.com operational. Thank you for your support!