Interpolation and Gamma Correction
Helmut Dersch
(der@fh-furtwangen.de)
Technical University Furtwangen
July 14, 1999
 

Digital images are usually gamma-corrected. This is a correction reqired by the video display, which is no linear device. It means that the RGB-data comprising a pixel of a digital image do not directly correspond to the light intensities. When dealing with real images, manipulations like overlaying images, transforming images or filtering images usually affect the light intensity, so doing the same with digitized images should include a reverse gamma correction to first yield these intensities. This is described in many publications on image processing, eg the excellent and free Gamma FAQ maintanied by Charles Poynton. Nevertheless, most Computer graphics programs do not follow this advice, but perform calculations on gamma-corrected data. In many cases the errors introduced seem to be minor, especially when dealing with real world photographs. In some cases, however, significant problems exist.

See the following example image. It exhibits two color areas with complementary colors: green (Green=255) and magenta (Red=255, Blue=255). Steep color contrasts like this are prone to interpolation errors, but usually do not occur in real-world images.

 
On cheap displays you might observe a thin darkened line around the green area, which is due to the (wrong) interpolation in your display.

This image is now rotated by 5 degrees. You can use almost any Graphic program to repeat these results, just be sure to convert the 'GIF'-image to 24bit-RGB first. The following is the result obtained from Photoshop using its bicubic interpolator. It is the lower right part enlarged 4 times to make the interpolated region visible:

 
The interpolated value between Magenta and Green is mathematically this dark, almost black color, but in the real world this is quite different. It is an artefact of working with gamma-corrected data.

The following image has been generated using Panorama Tools, which can be set to reverse gamma correction prior to transformations (see the Readme file about how this is done). The interpolator is set to Spline 36. In this case a gamma value of 2.5 is used. The same 5 degree rotation yields this image:

 
 
It has also been enlarged four times. A smooth and natural transition now appears. Please note that the image is automatically gamma-corrected again after the transformation. If you still see very fine dark lines: these are again introduced by your display.
 

The Math:
The interpolation between green and magenta is taken as an example. If we interpolate the gamma corrected rgb-pixels, we obtain

0.5 * [ (0,255,0) + (255,0,255) ] = (122, 122, 122)

which is quite dark.

Working with linear data, we get

{ 0.5 * [ (0, 2552.5, 0) + (2552.5, 0, 2552.5) ]} 0.4 = (193, 193, 193)

which looks much better.
 
 
 

A similar effect can be achieved by working in Lab-color space instead of RGB. Photoshop offers this possibility, but only few other programs.

Unfortunately, gamma correction and the reverse transformation are not completely lossless. Due to the finite Bitdepth there
are always some quantization errors which might add up if you chain many transformations. In practice it is a trade-off between two evils. For computer rendered images, a degamma/gamma correction is almost always adequate, for real-world photographs it hardly matters.

 
Copyright ©; H. Dersch 1999