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.
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 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:
The Math:
The interpolation between green and magenta is taken
as an example. If we interpolate the gamma corrected rgb-pixels, we obtain
which is quite dark.
Working with linear data, we get
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