Gamma management using dcraw and the gimp

The following chart shows the imaging characteristics of the Konica-Minolta DiMAGE A2 ZLR at five different gamma settings. It is useful in understanding both camera function and image processing. This analysis uses raw images processed with dcraw in the gimp. The effect of using the in-camera image processing to adjust gamma ("contrast") is discussed on the next page.

Test exposures. A standard test target was exposed under bright cloudy skies at an ambient temperature of 40 degrees F., using an assumed ISO of 64 to calculate exposures. The target was placed on Exposure Zones minus-one (-I) through eleven (XI) in order to ensure that the entire dynamic range was captured. Raw files were recorded and processed using the gimp and the dcraw plugin.

Gamma. In sensitometry, "gamma" is the slope of the straight-line portion of the "characteristic curve" -- the S-shaped graph that relates image luminance to film or print density. (It excludes the "toe" and "shoulder" of the curve.)

Processing.The resulting series of images were processed at the default gamma of 0.6, and at two gamma values above and below this. Arbitrarily, one was the upper limit gamma of dcraw, 1.5. A test at the lower limit, 0.01, is of no interest because the resulting values are flat, light, and noisy; so I arbitrarily picked 0.10 after viewing the effect of setting various values of gamma. Falsely assuming that a low gamma would flatten the whole curve, I adjusted "Shadow" so that the target showed very faintly in the darkest values, at 0.2 (default is 0.5). This did indeed preserve image detail in the shadows, at the cost of noise. I did not have time to find the optimal "Shadow" value for low values of gamma.

Results:

Pixel saturation. Photographic film saturates gradually, causing high values to roll off smoothly (the "shoulder" of the characteristic curve). Digital sensors saturate abruptly. All image luminances that map to intensity values above 255 are displayed as maximum white, 255. This creates a "blocked-out" effect, for which digital images are famous.

The A2 reliably saturates at about 3 1/2 stops above middle gray. That is, you can expect to retain some detail in objects with luminances 3 stops above middle gray, and can expect object with luminances 4 stops above middle gray to be completely blocked out. This is seen in the curves above -- there's a "shelf" at the top right end of each of the curves. In Zone System terminology, Zone VIII is the brightest value that will retain some texture, and Zone IX is pure white, with this camera.

Gamma curve operator. The shape of the curves show that in dcraw, gamma is calculated on the straight part of the curve -- Zones V through VIII -- and the lower values are mapped to a smooth curve down to the lowest values. The gamma = 0.10 curve (red dots) shows this clearly. This results in very high contrast in the shadow values, Zones II - V

Compensation. The middle curve, marked with blue dots, is the dcraw default, but this yields image values that are darker than expected in the mid range. An intensity value of 127 is the mid-value of the sensor response, and corresponds to image Zone V, and is where you'd normally place an 18% gray card.

But the default gamma reaches this value in Zone VI, whereas the curve of green dots, gamma 0.35 crosses the Zone V line at about 125, placing the object value about where you'd want.

Long toe. Notice that all the curves have a long toe. Examining the raw image reveals that subject detail is visible even in the minus-one exposure zone, though it's very noisy. Digital sensors don't "desaturate" pixels abruptly; they record each photon, more or less, and an image is created when the electrical changes induced by photons coming from the subject exceed the changes due to electrical noise. The result is a long, gradual tail. Photographic film is not a lot different, actually; but standard processing creates a definitive "toe" that is more or less sharp depending on the intent of the engineer who created it or the photographer who exposes and soups the film.

"Shadow." The dcraw program uses a parameter called "shadow" to adjust the sensitivity of the low values in the image, over a range of 0 - 1. Low values do not suppress noise and result in lighter dark values in your image -- more texture in the shadows, but at the price of more "grain" or noise. In the graph above, the red and green curves are separated from the others because the "Shadow" parameter was set to 0.2 instead of 0.5.

This chart shows the effect of changing the value of the "Shadow" parameter at two different values of gamma.

Final Word. It would be my guess that the soft shoulder and steeper mid-values contrast of film could be approximated by using a gamma of 0.2 - 0.3 and a "Shadow" constant of about 0.4 - 0.5 and shooting at a slightly higher ISO, 80 or 100 (1/3 or 2/3 stop). This can also be achieved using the curves tool.

Next topic: Contrast management using in-camera adjustment. The in-camera contrast control does not have the manipulative range that's available through the dcraw tool, and it functions differently: it's designed to keep middle values unchanged.