PNG (Portable Network Graphics) Specification, Version 1.2

Previous page
Next page
Table of contents

13. Appendix: Gamma Tutorial


13.1. Nonlinear transfer functions



   output = input ^ exponent

The exponent is often called "gamma" and denoted by the Greek letter gamma.

By convention, input and output are both scaled to the range 0 to 1, with 0 representing black and 1 representing maximum white (or red, etc). Normalized in this way, the power function is completely described by the exponent.

So, given a particular device, we can measure its output as a function of its input, fit a power function to this measured transfer function, and extract the exponent. People often say "this device has a gamma of 2.2" as a shorthand for "this device has a power-law response with an exponent of 2.2". People also talk about the gamma of a mathematical transform, or of a lookup table in a frame buffer, if its input and output are related by the power-law expression above.

But using the term "gamma" to refer to the exponents of transfer functions of many different stages in imaging pipelines has led to confusion. Therefore, this specification uses "gamma" to refer specifically to the function from display output to image samples, and simply uses "exponent" when referring to other functions.

13.2. Combining exponents

Real imaging systems will have several components, and more than one of these can be nonlinear. If all of the components have transfer characteristics that are power functions, then the transfer function of the entire system is also a power function. The exponent of the whole system's transfer function is just the product of all of the individual exponents of the separate stages in the system.


Thus, as long as our imaging system contains only stages with linear and power-law transfer functions, we can meaningfully talk about the exponent of the entire system. This is indeed the case with most real imaging systems.

13.3. End-to-end exponent


One complication is that the response of the human visual system to low light levels is not a scaled-down version of its response to high light levels. Therefore, if the display device emits less intense light than entered the capture device (as is usually the case for television cameras and television sets, for example), an end-to-end linear response will not produce an image that appears correct. There are also other perceptual factors, like the affect of the ambient light level and the field of view surrounding the display, and physical factors, like reflectance of ambient light off the display.

Good end-to-end exponents are determined from experience. For example, for photographic prints it's about 1.0; for slides intended to be projected in a dark room it's about 1.5; for television it's about 1.14.

13.4. CRT exponent

All CRT displays have a power-law transfer characteristic with an exponent of about 2.2. This is mainly due to the physical processes involved in controlling the electron beam in the electron gun.

An exception to this rule is fancy "calibrated" CRTs that have internal electronics to alter their transfer function. If you have one of these, you probably should believe what the manufacturer tells you its exponent is. But in all other cases, assuming 2.2 is likely to be pretty accurate.



Because of the difficulty of measuring the exponent, using either test images or measuring equipment, you're usually better off just assuming 2.2 rather than trying to measure it.

13.5. Gamma correction

A CRT has an exponent of 2.2, and we can't change that. To get an end-to-end exponent closer to 1, we need to have at least one other component of the "image pipeline" that is nonlinear. If, in fact, there is only one nonlinear stage in addition to the CRT, then it's traditional to say that the other nonlinear stage provides "gamma correction" to compensate for the CRT. However, exactly where the "correction" is done depends on circumstance.

In all broadcast video systems, gamma correction is done in the camera. This choice was made because it was more cost effective to place the expensive processing in the small number of capture devices (studio television cameras) than in the large number of broadcast receivers. The original NTSC video standard required cameras to have a transfer function with an exponent of 1/2.2, or about 0.45. Recently, a more complex two-part transfer function has been adopted [SMPTE-170M], but its behavior can be well approximated by a power function with an exponent of 0.52. When the resulting image is displayed on a CRT with an exponent of 2.2, the end-to-end exponent is about 1.14, which has been found to be appropriate for typical television studio conditions and television viewing conditions.

These days, video signals are often digitized and stored in computer frame buffers. The digital image is intended to be sent through a CRT, which has exponent 2.2, so the image has a gamma of 1/2.2.

Computer rendering programs often produce samples proportional to scene intensity. Suppose the desired end-to-end exponent is near 1, and the program would like to write its samples directly into the frame buffer. For correct display, the CRT output intensity must be nearly proportional to the sample values in the frame buffer. This can be done with a special hardware lookup table between the frame buffer and the CRT hardware. The lookup table (often called LUT) is loaded with a mapping that implements a power function with an exponent near 1/2.2, providing "gamma correction" for the CRT gamma.

Thus, gamma correction sometimes happens before the frame buffer, sometimes after. As long as images created on a particular platform are always displayed on that platform, everything is fine. But when people try to exchange images, differences in gamma correction conventions often result in images that seem far too bright and washed out, or far too dark and contrasty.

13.6. Benefits of gamma encoding


In an ideal world, sample values would be stored as floating-point numbers, there would be lots of precision, and it wouldn't really matter much. But in reality, we're always trying to store images in as few bits as we can.




13.7. General gamma handling


camera exponent
the exponent of the image sensor

encoding exponent
the exponent of any transformation performed by the software writing the image file

decoding exponent
the exponent of any transformation performed by the software reading the image file

LUT exponent
the exponent of the frame buffer LUT, if present

CRT exponent
the exponent of the CRT, generally 2.2

In addition, let's add a few other names:

display exponent
the exponent of the "display system" downstream of the frame buffer
   display_exponent = LUT_exponent * CRT_exponent

the exponent of the function mapping display output intensity to file samples
   gamma = 1.0 / (decoding_exponent * display_exponent)

end-to-end exponent

When displaying an image file, the image decoding program is responsible for making gamma equal to the value specified in the gAMA chunk, by selecting the decoding exponent appropriately:

   decoding_exponent = 1.0 / (gamma * display_exponent)


13.8. Some specific examples

In digital video systems, the camera exponent is about 0.52 by declaration of the various video standards documents. The CRT exponent is 2.2 as usual, while the encoding exponent, decoding exponent, and LUT exponent are all 1.0. As a result, the end-to-end exponent is about 1.14.

On frame buffers that have hardware gamma correction tables, and that are calibrated to display samples that are proportional to display output intensity, the display exponent is 1.0.

Many workstations and X terminals and PC clones lack gamma correction lookup tables. Here, the LUT exponent is always 1.0, so the display exponent is 2.2.

On the Macintosh, there is a LUT. By default, it is loaded with a table whose exponent is 1/1.45, giving a display exponent (LUT and CRT combined) of about 1.52. Some Macs have a "Gamma" control panel with selections labeled 1.0, 1.2, 1.4, 1.8, or 2.2. These settings load alternate LUTs, but beware: the selection labeled with the value g loads a LUT with exponent g/2.61, yielding

   display_exponent = (g/2.61) * 2.2

On recent SGI systems, there is a hardware gamma-correction table whose contents are controlled by the (privileged) gamma program. The exponent of the table is actually the reciprocal of the number g that gamma prints. You can obtain g from the file /etc/config/system.glGammaVal and calculate

   display_exponent = 2.2 / g

You will find SGI systems with g set to 1.0 and 2.2 (or higher), but the default when machines are shipped is 1.7.

On NeXT systems the LUT has exponent 1/2.2 by default, but it can be modified by third-party applications.

In summary, for images designed to need no correction on these platforms:

   Platform    LUT exponent   Default LUT exponent   Default gAMA
   PC clone       1.0                     1.0           45455
   Macintosh     g/2.61        1.8/2.61 = 1/1.45        65909
   SGI            1/g                     1/1.7         77273
   NeXT           1/g                     1/2.2        100000

The default gAMA values assume a CRT display.

13.9. Video camera transfer functions

The original NTSC video standards specified a simple power-law camera transfer function with an exponent of 1/2.2 (about 0.45). This is not possible to implement exactly in analog hardware because the function has infinite slope at x=0, so all cameras deviated to some degree from this ideal. More recently, a new camera transfer function that is physically realizable has been accepted as a standard [SMPTE-170M]. It is

   if (Vin < 0.018)  Vout = 4.5 * Vin
   if (Vin >= 0.018) Vout = 1.099 * (Vin^0.45) - 0.099

where Vin and Vout are measured on a scale of 0 to 1. Although the exponent remains 0.45, the multiplication and subtraction change the shape of the transfer function, so it is no longer a pure power function. It can be well approximated, however, by a power function with exponent 0.52.

The PAL and SECAM video standards specify a power-law camera transfer function with an exponent of 1/2.8 (about 0.36). However, this is too low in practice, so real cameras are likely to have exponents close to NTSC practice.

13.10. Further reading

Charles Poynton's "Gamma FAQ" [GAMMA-FAQ] is a excellent source of information about gamma, although it claims that CRTs have an exponent of 2.5. See also his book [DIGITAL-VIDEO].

Previous page
Next page
Table of contents