Friday, October 5, 2007

Understanding Histogram

The word histogram is derived from Greek : histos 'anything set upright' (as the masts of a ship, the bar of a loom, or the vertical bars of a histogram); gramma 'drawing, record, writing'. By definition, in statistics, a histogram is a graphical display of tabulated frequencies. In different words, a histogram is the graphical version of a table that shows what proportion of cases fall into each of several or many specified categories.

Now, why and how is it important in the context of photography ??

Do you care whether a photograph / a part of a photograph is overexposed or underexposed ?? Then the histogram of that photograph is just the right tool for you. You can even check it in the LCD of your digital camera (most of the digital P&S cameras and all DSLR cameras support it), in the field, just after shooting a frame and judge whether it was rightly exposed or not. If not, re-shoot it, exposing properly this time. Or if that moment is gone you don't have any choice left but to touch it up a bit in a photo editing software. For both the cases you need to understand the histogram fully.

Histogram of an image is nothing but a graph displaying the distribution of pixels of that image in different intensity levels. The horizontal axis shows the brightness of the pixels, starting from the lowest intensity value (black point) at the left to the highest intensity value (white point) at the right, and the number of pixels having a particular intensity value is displayed by a vertical line drawn at that intensity value point on the horizontal axis. So the area of the histogram denotes the total number of pixels of the image and should remain constant for all images with same total pixel count.

Here at the left we see a typical histogram. Lets take the black (left most) point as intensity - 0 and the white (right most) point as intensity - 255. Then the distribution is a peaked function with peak at around intensity value - 100. So the histogram says - most number of pixels in that image have values around 100. There is a small peak at the black point indicating that there are finite numbers of pixels in the image with intensity value - 0 i.e. complete black. Either the frame had some real black color or some other color (being underexposed) has been captured as black in the image. By similar argument one can infer that the image does not have any pixel with maximum intensity value - 255 (pure white). You got the hint right - the image can not be an overexposed capture. In typical frames most of the objects fall between zone-IV to zone-VIII and so a properly exposed image histogram in general should not have a peak at the ends. If it has a peak at the left end, the image (or a portion of it) would look too dark and a peak at the right end ensures the image (or a part of it) to be too bright. Given below are the signatures of typical underexposed, rightly exposed and overexposed captures.

Histogram of a typical underexposed frame (or a rightly exposed frame which has a lot of complete dark and shadow regions and absolutely no highlight).

Histogram of a rightly exposed frame. Neither too many pixels of complete dark nor any burnt out highlight. There might be a small dark region in the image as the distribution has a non-zero value at the left end but surely no highlight.

Histogram of a typical overexposed frame (or a rightly exposed frame which has a lot of pure white regions and no dark or shadow regions).

Now, it's needless to say that the middle histogram is the most sought after. We don't like images with to much dark regions without any details or too much of highlights / burnt out portions showing no details. In both the cases we try to re-shoot the frame with proper exposure compensations. Perhaps the best way to understand the histogram is to look at the sample shots and corresponding histograms. First example is an underexposed frame with its histogram. In time of shooting it's difficult to judge whether the captured image is slightly underexposed viewing it in the small LCD display of the camera - so better look at the histogram - it would tell you all.

At a glance, one can see that most of the pixels tend toward the dark (left) side. The histogram also touches the left end. So you know that there are underexposed or "too dark" areas in the image. To obtain the right exposure one needs to program the camera to allow more light either by a positive exposure compensation or by setting a slower shutter speed or wider aperture (smaller value) and if the right exposure is obtained, the image and the histogram should look like this one:
Now if the histogram touches the other end i.e. if most of the pixels tend toward the highlight (right) side - you know that there are overexposed or "too bright" areas in the image.

Just by using the reverse technique(s) one can program the camera to allow less light to capture a rightly exposed frame, as shown in the previous example.

Many a times when the situation is not typical, rather a bit tricky, we do not see single peaked or center-peaked histograms. E.g. for a landscapes with bright sky and some shadow regions, the histogram would show two peaks (there might be some additional peaks too in between) at the left and right for the shadow regions and the bright sky respectively. As long as those peaks do not touch the ends we should not worry. But what if they touch the ends ? The image will have shadow regions as complete black without any detail and the sky will be blown out white showing no detail.... you do not like this type of an image, me too. We can't do here much in a direct manner - if one underexposes to get the details of the sky, the shadow region will be darker and if one wants to take care of the shadow regions by overexposing it a bit, the highlights will get worse. It's a limitation of the recording medium, termed as 'narrow dynamic range'. One needs to manipulate the image either in time of printing (for analog recording) or post-processing (for digital recording). The most important thing to remember here is that one can recover the details of the shadow regions by different manipulation methods but it's not possible to extract the details from the blown out regions. So the thumb rule to tackle these situations is "expose for the highlights" and then use some manipulation technique to get the details back in the shadow regions.

But remember, it's always desirable that the tails of the histogram extend to the ends - if you care to utilize the whole dynamic range of your recording medium. To ensure that the image has the complete tonal variation, just see the histogram and check whether the tails touch the ends. If they do not, you can always make it so using the level tool in any photo editing software - it just renormalizes the tonal range of the image to the complete available tonal range.

To summarize :

  1. The histogram is a handy graph that alerts you to the two extreme cases of underexposure and overexposure in your pictures.
  2. When the histogram touches the left end, you lose details in the shadows and when the histogram touches the right hand - it conveys blown highlights - you lose details in the highlights.
  3. There is no good or bad histogram, per se. As long as the histogram does not have peaks that touch the left or the right end, you are safe - the image will not have any underexposed or overexposed region.
  4. When the tails of the histogram extends to the ends, it ensures that the image has the complete available tonal variation - as desired often.

1 comment:

Vijay Singh said...

that was quite informative....i'll need to check if my cam has the option of looking @ the histogram....