“Gamma” and its Disguises: The Nonlinear Mappings of Intensity in Perception, CRTs, Film and

By Charles A. Poynton

In photography, video and computer graphics, the gamma symbol γ represents a numerical parameter that describes the nonlinearity of intensity reproduction. The subject of colorimetry concerns the Gamma is a mysterious and confusing subject, because it involves concepts from four relationship between the sensation of disciplines: physics, perception, photography and video. In this note I will explain color and spectral power at different how gamma is related to each of these disciplines. Having a good understanding of wavelengths in the visible band. De- the theory and practice of gamma will enable you to get good results when you create, tailed discussion of colorimetry is be- process and display pictures. yond the scope of this note, except for one fact that is important here. Human This note focuses on electronic reproduction of images, using video and computer vision gives special treatment to lumi- graphics techniques and equipment. However, the discussions of perception and nance, or roughly speaking, . photography may be of general interest as well. This note deals mainly with the Luminance is a weighted mixture of reproduction of intensity, or as a photographer would say, tone scale. This is one spectral energy, where the weights are important step to achieving good color reproduction, but issues specific to color are determined by the characteristics of covered elsewhere. human vision. Luminance comprises roughly 11% power from blue regions of the spectrum, 59% from green and The nonuniform perception of intensity of the channel, and simultaneously cor- 30% from red. The coefficients in this is the subject of the first section of this rects for intensity nonlinearity at the weighted sum are derived from the sen- note. The human perceptual response to CRT display. If gamma correction were sitivity of human vision to the corre- intensity is distinctly nonuniform: the not already necessary for physical rea- sponding wavelengths: a saturated blue sensation of vision is roughly sons at the CRT, we would have to color is quite dark, having a brightness a power function of intensity. This char- invent it for perceptual reasons. of about 0.11 relative to white. A satu- acteristic of vision needs to be accom- The next section of this note switches to rated red is considerably lighter, and modated if an image is to be coded so as a completely different topic: photogra- saturated green is lighter still. to minimize the visibility of noise and phy. Photography also involves make effective perceptual use of a lim- The Commission Internationale de ited number of bits per pixel. nonlinearity of intensity reproduction. L’Éclairage (CIE, or International Com- The nonlinearity of film is character- mission on Illumination) is the interna- The origin of gamma in the physics of a ized by a parameter gamma. As you tional body responsible for standards in cathode-ray tube (CRT) is covered in might suspect, electronics inherited the the area of color perception. The CIE the second section of this note. The term from photography! The effect of has standardized a weighting function, CRTs that are ubiquitous in workstation gamma in film primarily concerns the defined numerically, that relates spec- displays and in sets are inher- appearance of pictures rather than the tral power to luminance. The symbol for ently nonlinear devices: the intensity of accurate reproduction of intensity val- luminance is Y, sometimes emphasized light reproduced at the screen of a CRT ues. Some of the appearance aspects of as being standard by the prefix CIE. monitor is not proportional to its voltage gamma in film also apply to television input. From a strictly physical point of and computer displays. Unfortunately, in video practice, the view, gamma correction can be thought term luminance has come to mean the In the fifth section of this note I will of as the process of compensating for video signal representative of luminance this nonlinearity in order to achieve describe how video draws aspects of its even though that video signal has been handling of gamma from of all of these correct reproduction of intensity. subjected to a nonlinear transfer func- areas: knowledge of the CRT from phys- tion. In the early days of video, the The third section of this note discusses ics, knowledge of the nonuniformity of nonlinear signal was denoted Y’, where how combining these two concepts — vision from perception, and knowledge the prime symbol indicated the nonlin- one from perception , the other from of viewing conditions from photogra- ear treatment. But over the last forty physics— reveals an amazing coinci- phy. I will also discuss additional de- years the prime has been elided in video dence: the nonlinearity of a CRT is tails of the CRT transfer function that usage and now both the term luminance remarkably similar to the inverse of the you will need to know if you wish to and the symbol Y collide with the CIE, lightness sensitivity of human vision. calibrate a CRT or determine its making both ambiguous! This has led to Coding intensity into a gamma-corrected nonlinearity. great confusion, such as the incorrect signal makes maximum perceptual use In the final section of this note I will statement commonly found in computer make some comments about gamma graphics and color textbooks that in the Charles A. Poynton is a Staff Engineer with Sun correction in computer graphics. YIQ or YUV color spaces, the Y com- Microsystems Computer Corp., Mountain View, CA ponent is CIE luminance. I use the term 94043. Copyright © 1993 Society of Motion Picture and luminance according to its standardized Television Engineers, Inc. All rights reserved. SMPTE Journal, December 1993 1099 CIE definition and use the term to refer to the video signal. But my con- vention is not yet widespread, and in the meantime you must be careful to deter- mine whether a linear or nonlinear inter- pretation is being applied to the word and the symbol. Until now I have used the familiar term +∆ intensity — including in the title of this LL L note! — but from now on I will use the technical term luminance to refer to the brightness response of human vision. I will continue to use intensity for linear- light red, green and blue quantities. Luminance is a linear-light quantity, although its spectral composition is de- L0 fined according to human vision. The response of human visual system to luminance is the subject of the next L0: Adaptation (surround) Luminance section. Perception L: Test Luminance Human vision adapts over a remarkably ∆ L: Minimum detectable difference wide range of intensity levels — about seven decades of dynamic range in to- tal. This is illustrated in the sketch be- low. For about two decades at the bot- The adaptation is controlled by total the luminance of blacks, and thereby tom end of the intensity range, the reti- retinal illumination. Dark adaptation to lessen the contrast ratio and impair per- nal photoreceptor cells called rods are a lower intensity is slow: it can take ceived picture quality. employed. Since there is only one type many minutes to adapt from a bright of rod cell, what is loosely called night sunlit day to the dark ambient light of a Within the two decade range of lumi- nance over which vision can distinguish vision cannot discern colors. About one cinema. Light adaptation towards higher luminance levels, human vision has a decade of adaptation is effected by the intensity is more rapid but can be pain- certain discrimination threshold. For a iris; the remainder of the adaptation is ful, as you may have experienced when reason that will become clear in a mo- due to a photochemical process that walking out of the cinema back into ment, it is convenient to express the involves the visual substance daylight. Since adaptation is controlled contained in photoreceptor cells. by total retinal illumination, your adap- discrimination capability in terms of contrast sensitivity, which is the ratio of tation state is closely related to the in- between two adjacent tensity of “white” in your field of view. patches of similar luminance. Absolute At a particular state of adaptation, hu- The diagram above shows the pattern Scene man vision can distinguish different lu- presented to an observer in an experi- Luminance minance levels down to about one per- cent of peak white. In other words, our ment to determine the contrast sensitiv- ity of human vision. Most of the ability to distinguish luminance differ- observer’s field of vision is filled by a 10 k ences extends over a luminance range of surround luminance level L , in order about 100:1. Loosely speaking, intensi- 0 to fix the observer’s state of adaptation. 1 k ties less than about one percent of what In the central area of the field of vision sunlight is sometimes called peak white appear 100 simply “black”: different luminance is placed two adjacent patches having slightly different luminance levels L 100 values below this luminance level can- ∆ 10 and L+ L. The experimenter presents twilight not be distinguished. 10 stimuli having a wide range of test val- Contrast ratio is defined as the ratio of ues with respect to the surround, that is, 1 1 luminance between the lightest and dark- L est elements of a scene. Contrast ratio is a wide range of values. At each test moonlight L 100 m a major determinant of perceived pic- 0 ture quality, so much so that an image luminance, the experimenter presents to 10 m reproduced with a high contrast ratio the observer a range of luminance incre- may be judged sharper than another ments with respect to the test stimulus, starlight 1 m image that has higher measured spatial LL+ ∆ resolution. In a practical imaging sys- that is, a range of values. L 100 µ tem, many factors conspire to increase

1100 SMPTE Journal, December 1993 field. Some are polynomials, others are power functions, still others are loga- rithmic. There is no agreement on a single curve for all applications, but all of the curves have the same basic form. In 1976, the CIE standardized the L* function, which is a power function of luminance, modified slightly by the in- troduction of a linear segment near black. In the following equations, Y is CIE luminance (proportional to intensity), and Yn is the luminance of reference white, usually normalized to either 1.0 or 100: 1  Y  3 Y L*,.=116  − 16 > 0 008856   YnY n  Y  Y L*.,.=903 3  ≤ 0 008856   YnY n This is the standard function that relates physical luminance to perceived light- ness. The CIE refers to L* as the light- The result of conducting the experiment luminance, strict adherence to logarith- ness component of a uniform color is shown in the graph above, Figure 3.4 mic coding is not necessary for percep- space. The term perceptually linear is of W.F. Schreiber’s Fundamentals of tual reasons. Also, the discrimination not appropriate: since we cannot di- Electronic Imaging Systems: plotting capability of vision degrades for very rectly measure the quantity in question, ∆ dark shades of gray, below a few per- L we cannot ascribe to it the properties of log as a function of log L reveals cent of peak white. L mathematical linearity. The graph below is Figure 2(6.3) from an interval of more than two decades of Roughly speaking, perceived lightness Wyszecki and Stiles Color Science. It luminance, between about zero and +2.5 is the cube root of luminance. log millilamberts, over which the dis- shows several lightness scales that have crimination capability of vision is about been used by different workers in the one percent of the test luminance level.

This leads to the conclusion that — for threshold discrimination of two adja- cent patches of nearly identical lumi- nance — the discrimination capability is very nearly logarithmic. The contrast sensitivity function begins to answer the question, what is the mini- mum number of discrete codes required to represent luminance over a particular range? In other words, what intensity codes can be thrown away without the observer noticing? If codes are placed at exactly 1% intervals over a 100:1 range, the number of codes required is log 100 log 1. 01, or 460. About 460 codes are required to cover a dynamic range of 100:1, at a particular adaptation state, at a discrimination threshold of one per- cent. The logarithmic relationship is based on measurements of contrast sensitivity at threshold. That is, we are measuring the ability of the visual system to discrimi- nate between two nearly identical lumi- nance values. Over a wider range of

SMPTE Journal, December 1993 1101 Light represents white. Code value 100 repre- Intensity sents a shade of gray that is approxi- (Out) mately at the perceptual threshold: for 2.5 codes above 100, the ratio between in- Intensity ≈ Signal tensity values of adjacent codes is less than one percent, and for codes below 100, the ratio between intensity values of adjacent code values is greater than one percent. Luminance codes below 100 suffer in- creasing artifacts as the code value de- creases towards black, due to the vis- Black Video Signal (In) White ibility of the luminance difference be- (min) (max) tween adjacent codes: at code 50, the ratio between adjacent codes is 2%, Gamma in Physics Actually, by far the largest source of which is noticeable to most observers. variation in the nonlinearity of a moni- These artifacts are especially objection- The physics of the electron gun of a tor is caused by the black level or bright- able in pictures having large areas of CRT dictates a relationship between ness adjustment of the monitor. Make smoothly-varying shades. voltage input and light output that a sure that your display’s brightness con- Luminance codes above 100 suffer no physicist calls a five-halves power law: trol is adjusted so that black elements in the intensity of light produced at the artifacts due to visibility of the jumps the picture are reproduced correctly be- between codes. However, as the code face of the screen is proportional to the fore you devote any effort to determin- 5⁄ value increases towards white, the codes voltage input raised to the power ␣ 2. In ing or setting gamma. other words, intensity is roughly be- have decreasing perceptual utility. For tween the square and cube of the volt- Users of Apple ™ computers example, at code 200, the ratio between age. The numerical value of the expo- sometimes claim that the color monitors adjacent intensity steps is half a percent, nent of the power function is repre- used with those computers have a gamma well below the threshold of visibility. Codes 200 and 201 are visually indistin- sented by the Greek letter γ (gamma). value considerably lower than 2.2 — say CRT monitors have voltage inputs that 1.4 or 1.8. But these values are a func- guishable: code 201 is perceptually use- reflect this power function, and in prac- tion of the rather poorly documented less, and could be discarded without tice the numerical value of gamma is software interpretation of RGB values being noticed. This example shows that very close to its theoretical value of 2.5. presented to Apple’s QuickDraw soft- a linear-luminance representation is a ware, and have no direct relationship to poor choice for an eight-bit channel. The sketch above shows the power func- the monitors used on Macintosh com- The Perception section of this note drew tion that applies to the single electron puters. gun of a CRT, or to each of the the conclusion that it is sufficient for three red, green and blue electron guns The Amazing Coincidence! perceptual purposes to maintain about a of a color CRT. The functions associ- one percent luminance ratio between The first section of this note described ated with the three guns of a color CRT adjacent codes. This can be achieved by are very similar to each other, but not the nonlinear response of human vision coding the signal nonlinearly, as roughly that relates luminance to perceived light- necessarily identical. The function is the logarithm of luminance. To the ex- ness. The second section described how dictated by the electron gun and has tent that the log function is an accurate the nonlinear transfer function of a CRT nothing to do with the CRT’s phosphor. model of the contrast sensitivity func- relates a voltage signal to intensity. tion, full perceptual use is made of every The process of pre-compensating for Here’s the amazing coincidence: the code. this nonlinearity — by computing a volt- CRT voltage-to-intensity function is As I mentioned in the previous section, age signal from an intensity value — is very nearly the inverse of the lumi- known as gamma correction. The func- nance-to-lightness relationship of vi- logarithmic coding rests on the assump- tion required is approximately a sion. That means that coding a lumi- tion that the threshold function can be 0.45-power function, whose graph is nance signal into voltage, to be turned extended to large luminance ratios. Ex- similar to that of a square root function. back into luminance by a CRT, is very periments have shown that this assump- In video, gamma correction is accom- nearly the optimal coding to minimize tion does not hold very well, and coding plished by analog circuits at the camera. the perceptibility of noise that is intro- according to a power law is found to be In computer graphics, gamma correc- duced into the signal. CRT voltage is a better approximation to lightness re- tion is usually accomplished by incor- remarkably perceptually-uniform. sponse than a logarithmic function. porating the function into a framebuffer’s Suppose you have a luminance value The lightness sensation can be com- lookup table. that is determined quite precisely, but puted as intensity raised to approxi- The actual value of gamma for a particu- you must use a channel having only mately the third power: coding a lumi- lar CRT may range from about 2.3 to eight bits to convey that value to a nance signal to a signal by the use of a power law with an exponent of between 2.6. Practitioners of computer graphics distant observer. Consider a linear light 1⁄ frequently claim that the numerical value representation with eight bits, where ␣ 3 and 0.45 has excellent perceptual of gamma can vary widely from 2.5. code zero represents black and code 255 performance.

1102 SMPTE Journal, December 1993 Power laws in perception rithmic one: in terms of physical quan- percept physical quantity power tities, transmittance is a power function loudness sound pressure level 0.67 of . The slope of the linear saltiness sodium chloride concentration 1.4 segment, in the log-log domain, is the smell concentration of aromatic molecules 0.6 exponent of the power function. The heaviness mass 1.45 numerical value of the exponent of the power function — in the straight-line Incidentally, other senses behave ac- density as a function of the logarithm of region of the film’s response curve — is cording to power laws, according to the exposure. This D-log␣E curve was first known as gamma. table above. introduced by Hurter and Driffield, so it Since development of film forms a nega- is also called an H&D plot. In terms of Gamma in Film tive image, a second application of the the physical quantities of exposure and process is necessary to form a positive This section describes gamma in photo- transmittance, a D-log␣E plot is funda- image. This usually involves making a graphic film. I will give some back- mentally in the log-log domain. positive print on paper or plastic from a ground on the photographic process, The H&D plot of a typical color reversal negative on film. (As an aside, in the then explain why physically accurate film is shown below. It has the charac- reversal film used in 35␣mm slides, de- reproduction of luminance values does teristic S-shaped curve that compresses veloped silver is removed by a bleach- not give subjectively good results. Video blacks and compresses whites, with a ing process, then the originally unex- systems exploit this gem of wisdom reasonably linear segment in the central posed and undeveloped latent silver re- from photography: subjectively better portion of the curve. The ubiquitous use maining in the film is converted to me- images can be obtained if proper ac- of D-log␣E curves in film work — and tallic silver to produce a positive image. count is taken of viewing conditions. the importance of the linear segment of In color film, metallic silver is then converted to colored dyes.) When is exposed to the curve in determining correct expo- sure — leads many people to the incor- light and then developed, light imaged This cascaded process — which is re- from the scene onto the film causes the rect conclusion that film has an inher- peated twice in the processing of most ently logarithmic luminance response development process to produce small motion picture film — makes it impor- grains of metallic silver. This process in terms of physical quantities! But a tant that the individual power functions intrinsically creates a negative image: linear slope on a log-log plot is charac- at each stage are kept under tight con- where light causes silver to be devel- teristic of a power function, not a loga- trol, both in the design and processing of oped, the developed silver absorbs light the film. To a first approximation, the and appears dark. Color film comprises three layers of emulsion sensitized to different wavelength bands, roughly red, green and blue. The development pro- cess converts silver in these three layers into dyes that act as colored filters to absorb red, green and blue light. Film can be characterized by the trans- fer function that relates exposure from the scene to the transmittance of the developed film. The exposure value at any point on the film is proportional to the luminance of the corresponding point in the scene. A higher exposure causes more silver to be developed, hence more absorption of light in the negative. Trans- mittance is defined as unity minus the fraction of light absorbed by the devel- oped film. Density is defined as its the negative of the base␣10 logarithm of transmittance. Clear film has a density of zero; film with a transmittance of 0.1 has a density of 1, and film with a transmittance of 0.01 has a density of 2. It is difficult in practice to achieve a density greater than 3, that is, it is diffi- cult to achieve a dynamic range greater than 1000:1. Film has a somewhat nonlinear rela- tionship between exposure and trans- mittance, usually shown by plotting

SMPTE Journal, December 1993 1103 The effect is demonstrated in the sketch at the left, taken from the article “Color Science for Imaging Systems” by LeRoy E. DeMarsh and Edward J. Giorgianni, in Physics Today, September 1989, pages 44-52. The three gray squares surrounded by white are identical to the corresponding gray squares surrounded Surround Effect. The three gray squares surrounded by white are identical to the by black, but the contrast of the black- three gray squares surrounded by black, but the contrast of the black-surround series surround series appears lower than that appears lower than that of the white-surround series. of the white-surround series. This has implications for the display of images in dark areas, such as projection of movies in a cinema, projection of 35␣mm slides, or viewing of television in your living room. If an image is viewed in a dark or dim surround, and the intensity of the scene is reproduced physically correctly, the image will ap- intent is to obtain roughly unity gamma sion accommodates this huge range is to pear lacking in contrast. through the entire series of cascaded increase its sensitivity to small bright- processes. Individual steps may depart ness variations when the area of interest Film systems are designed to compen- from linearity, as long as approximate is surrounded by bright elements. Intu- sate for viewing surround effects. Film linearity is restored at the end of the itively, light from a bright surround can intended for viewing with a dark sur- chain. be thought of as spilling or scattering round is designed and processed to have into all areas of our vision, including the a gamma considerably greater than unity Now, here’s a surprise. If a film system area of interest, reducing its apparent —about 1.5, in fact—so that the con- is designed and processed to produce contrast. Loosely speaking, the effect is trast range of the scene is expanded exactly linear reproduction of intensity, similar to “flare”, and the visual system upon display. Video signals are coded reflection prints look fine. But projected compensates for it by “stretching” its in a similar manner, taking into account transparencies — slides and movies — contrast range to increase the visibility a dim surround viewing environment as look flat, apparently lacking in contrast! of dark elements in the presence of a I will describe in a moment. The reason for this involves another bright surround. Conversely, when the aspect of human visual perception. The important conclusion to take from region of interest is surrounded by rela- this section is that image coding is not As I explained in the Perception sec- tive darkness, the contrast range of the simply concerned with mathematics, tion, human vision adapts over an ex- vision system decreases: our ability to physics, chemistry and electronics: per- tremely wide range of viewing condi- discern dark elements in the scene de- ceptual considerations play an essential tions. One of the ways that human vi- creases. role in successful image systems.

1104 SMPTE Journal, December 1993 original scene scanner/ transmission camera system

display

reproduced scene

observer

Image Reproduction in Video. To convey a convincing impression of the scene at the left to the observer at the right, intensity from the original scene must be reproduced at the display, possibly with a scale factor to account for an overall intensity change. However, the ability of human vision to detect an intensity difference is not uniform across the range from black to white, but is approximately a constant ratio — about one percent — of the intensity. In order for noise introduced by the transmission system to have minimum perceptual impact, intensity from the scene is transformed by a function similar to a square-root into a nonlinear, perceptually-uniform signal that is transmitted. The nonlinear signal is transformed back to linear intensity at the display. Essentially, the camera is designed to have a signal response that mimics the human visual system, in order to “see” lightness in the scene the same way that a human observer would.

Gamma in Video the front end of a digital system when a power function of the CRT to obtain an signal representing intensity is quan- end-to-end power function with an ex- In a video system, gamma correction is tized to a limited number of bits. Conse- ponent of␣1.1 or␣1.2. This technique pro- applied at the camera for the dual pur- quently, video signals are almost al- duces pictures that are much more sub- poses of coding into perceptually-uni- ways conveyed in gamma-corrected jectively pleasing than those produced form space and precompensating the form. by a mathematically-correct linear sys- nonlinearity of the display’s CRT. The tem. first of these considerations was impor- As I explained on the facing page, when tant in the early days of television, be- viewing an image on a screen in a dim Video standards specify a gamma value cause of the need to minimize the noise surround it is important for perceptual of about 2.2 for purposes of pre-correc- 1⁄ introduced by VHF over-the-air trans- reasons to “stretch” the contrast ratio of tion: the product of the ␣ 2.2␣exponent at mission of broadcast television. How- the reproduced image. The dim sur- the camera and the 2.5␣exponent at the ever, the same considerations of noise round condition is characteristic of tele- display produces the desired end-to-end visibility apply to analog videotape re- vision viewing. In video, the “stretch- exponent of about 1.13. cording, and also to minimization of the ing” is accomplished at the camera, by quantization noise that is introduced at slightly under-compensating the actual

SMPTE Journal, December 1993 1105 Reference White framebuffer digital-to-analog convert- ers that employ 7.5␣percent setup al- most universally have very loose toler- ance on the analog voltage associated with reference black. The tolerance is typically ±5% of full scale. This induces Toe Slope Gamma 0.45 black-level errors, which in turn cause 4.5 serious errors in the intensity repro- VIDEO SIGNAL duced for black. In the absence of a (Voltage or Code) display calibrator, you must compen- sate these framebuffer black-level er- rors by adjusting the Black Level (or Brightness) control. The accuracy of black level reproduc- tion is greatly improved by using newer analog video standards having zero Reference Black setup. The voltage range␣0 to 700␣mV is Toe Break associated with zero-setup standards Toe Intercept including 625/50 video in Europe, and LIGHT INTENSITY -0.099 all HDTV standards and proposals. For the 8-bit digital RGB components that are ubiquitous in computing, refer- The transfer function standardized for monitor. The x-axis of the graph shows ence black corresponds to digital code␣0 high definition television, part of the the input signal level, from reference and reference white corresponds to digi- CCIR␣Recommendation␣709 standard, black to reference white. The input sig- tal code␣255. The standard is illustrated above. CCIR␣Rec.␣709 is nal can be presented as a digital code or CCIR␣Rec.␣601 coding for studio digi- based on a power function of␣0.45. How- an or analog voltage. The y-axis shows tal video places black at code␣16 and ever a true power function requires infi- the resulting intensity. white at code␣235. Either of these digital nite gain near black, which in a practical For analog voltage signals, two stan- coding standards can be used in con- camera or scanner would introduce a dards are in use. The range 54␣mV to junction with an analog interface hav- large amount of noise in dark regions of 714␣mV is used in video systems that ing either 7.5-percent setup or zero setup. the image. CCIR␣Rec.␣709 introduces a Coding of imagery with extended color linear segment near black to minimize have 7.5␣percent setup , including com- posite 525/59.94 systems such as NTSC gamut may place the black and white this effect. The power curve has its and computer video systems that con- codes even further inside the range␣0 y-intercept shifted negative, and its gain form to the levels of the archaic and␣255, for reasons having to do with increased, such that the linear segment EIA-343-A standard. Computer color reproduction that are outside the meets the curve where their values and scope of this note. slopes match. The mapping of unity is undisturbed. (Details of this transfer function will be included in a tutorial article Introduction to Component Video Coding, to appear in a forthcoming is- sue of the SMPTE Journal.) Light CRT Transfer Function Details Intensity (Out) This section provides technical infor- mation concerning the nonlinearity of a ≈ 2.5 CRT that is important if you wish to Light Signal determine the transfer function of your CRT, or to calibrate your monitor, or to understand the electrical voltage inter- face between a computer framebuffer and a monitor. If you are not interested in these details, I encourage you to skip this section! Reference Black Reference White

The graph to the right illustrates the 0 mVanalog video, zero setup 700 mV relationship of the signal input to a moni- 54 mVanalog video, 7.5% setup 714 mV tor to the light luminance produced at 0typ. computer framebuffer 255 the face of the screen. The graph charac- 16CCIR Rec. 601 digital video 235 terizes a grayscale monitor, or each of the red, green and blue signals of a color Video Signal (In)

1106 SMPTE Journal, December 1993 The nonlinearity in the voltage-to-in- as the chromaticity of its white point and can be displayed and geometric objects tensity function of a CRT originates its primaries — that are important for can be rendered smoothly-shaded. A with the electrostatic interaction between accurate color reproduction. truecolor framebuffer almost invariably the cathode and the grid that controls the has three lookup tables, one for each current of the electron beam. Contrary Gamma in Computer Graphics component. to popular opinion, the CRT phosphors Computer graphics software systems The voltage signal between 0 and 1 themselves are quite linear, at least up to generally perform calculations for light- required to display a red, green or blue an intensity of about eight-tenths of ing, shading, depth-cueing and anti- luminance between 0 and 1 can be com- peak white where saturation begins to aliasing using intensity values that model puted as: set in. the physical mixing of light. Intensity  1  Knowing that a CRT is intrinsically values stored in the framebuffer are   gamma-corrected by hardware lookup =  gamma  nonlinear, and that its response is based signal intensity on a power function, many users at- tables “on the fly” on their way to the tempt to summarize the nonlinearity of display. The power function at the CRT In the C␣language this can be repre- a CRT display in a single numerical acts on the gamma-corrected signal volt- sented as follows: parameter using the obvious relation- ages to reproduce the correct intensity signal = pow((double)intensity, ship: values at the face of the screen. Soft- (double)1.0/gamma); γ ware systems usually provide a default intensity = voltage gamma value and some method to In the absence of data regarding the change the default. actual gamma value of your monitor — This model shows wide variability in or for an image intended for interchange the value of gamma, mainly due to black- Since color monitors take red, green, in gamma-corrected form — the recom- 1 level errors that the model cannot ac- and blue voltage inputs, most computer mended value of gamma is ⁄␣ 0.45 (or commodate due to its being “pegged” at software uses the RGB color model. about 2.222). zero: the model forces zero voltage to Each color component (or channel) — You can construct a gamma-correction map to zero intensity for any value of red, green, and blue — is typically repre- gamma. Black-level errors that displace sented in high-level software by a float- lookup table like this: the transfer function upwards can only ing point number in the range 0 to 1. #define SIG_FROM_INTEN(i) Graphics library software typically trans- ((int)( 255.0 * be “fit” by choosing a gamma value that pow((double)(i) / 255.0, is much smaller than␣2.5. Black-level lates these floating point values to 8-bit 0.45))) errors that displace the curve down- integers in the range from 0 to 255 for int sig_from_inten[256], i; wards — saturating at zero over some use by the graphics hardware. In both portion of low voltages — can only get a the floating point and integer represen- for (i=0; i<256; i++) good “fit” by having a value of gamma tations, the minimum value in the red sig_from_inten[i] = that is much larger than␣2.5. In effect, component means “as black as you can SIG_FROM_INTEN(i); the only way the single gamma param- get”. The maximum value in the red Loading this table into the hardware eter can fit a black-level variation is to component means “as red as you can lookup table at the output side of a alter the curvature of the function. The get,” without regard to whether the framebuffer will cause RGB intensity apparent wide variability of gamma monitor displays its reds more red or values with integer components between under this model has given gamma a more or more purple than an- 0 and 255 to be gamma-corrected by the bad reputation. other. The color characterization of monitors outside the scope of this note. hardware as if by the following C␣code: A much better model is obtained by red_signal = sig_from_inten[r]; fixing the exponent of the power func- A truecolor system has separate red, green and blue components for each green_signal = tion at␣2.5, and using the single param- sig_from_inten[g]; eter to accommodate black-level error: pixel of an image or in a framebuffer. In 2.5 most computer systems, each compo- blue_signal = sig_from_inten[b]; intensity = (voltage + ε) nent is represented by a byte of eight bits, so each pixel has 24 bits of color The provision of a lookup table at the This model fits the observed nonlinearity information. It is convenient to build a output of the framebuffer makes it pos- much better than the variable-gamma framebuffer or memory system with sible to use framebuffer signal repre- model. each complete pixel having a number of sentations other than linear-light. For In you want to determine the nonlinearity bits that is a power of two. Consequently, example, it is possible to load gamma- of your monitor, I recommend the ar- a truecolor framebuffer usually has thirty corrected video signals into the ticle “An Inexpensive Scheme for Cali- two bits per pixel, where the eight addi- framebuffer and load a unity ramp into bration of a Colour Monitor in terms of tional bits are used for purposes other the lookup table. than representing color. CIE Standard Coordinates”, by William The availability of a lookup table at the B. Cowan, Computer Graphics, Vol- The RGB components of each pixel in a framebuffer also makes it possible for ume 17, Number 3 (July 1983), pages 24-bit␣system can represent one of software to perform sleazy tricks, such 315-321. In addition to describing how 16.7␣million codes, but the number of as inverting all of the lookup table en- to measure the nonlinearity, the article colors that can be distinguished is tries momentarily to flash the screen also describes how to determine other considerably less than this. With 24-bit without modifying any the data in the characteristics of your monitor — such color, near-photographic quality images framebuffer. Direct access to

SMPTE Journal, December 1993 1107 framebuffer lookup tables by applica- 0.45. Be aware that the perceptual uni- can produce rendered images that are tions makes it difficult or impossible for formity of the gamma-corrected image free from the quantization artifacts of system software to avoid annoyances will be severely compromised by map- eight-bit intensity representations. such as colormap flashing and to pro- ping into the 8-bit intensity domain: vide features such as accurate color re- contouring will be introduced into the The Future of Gamma production. To allow the user to make darker shades. This topic is covered in Correction use of these features, applications should the next section. systems for PCs and access lookup tables in the structured workstations will soon allow device- ways that are provided by the graphics The Limitations of Eight-Bit independent specification of color. Us- system. Intensity ers and applications will be able to Pseudocolor As I mentioned in the Gamma in Com- specify colors in a device-independent puter Graphics section earlier, com- form based on the CIE international A pseudocolor (or , or puter graphics systems that render syn- standards for color, without any con- color mapped) system dedicates several thetic imagery usually perform compu- cern about gamma correction. This will bits — usually eight — to each pixel in tations in the linear-light (intensity) do- make it easy to obtain color matching an image or framebuffer. The content of main. Graphics accelerators usually per- across different graphics libraries, and each pixel is used as an index into a form Gouraud shading in the intensity different hardware. In the meantime, color look-up table (CLUT, or colormap) domain, and store eight-bit intensity you can take the following steps: that retrieves red, green and blue signal components in the framebuffer. Eight- values upon display of the pixel. An bit intensity representations suffer con- • Establish good viewing conditions. If 8-bit framebuffer displays at most 256 touring artifacts due to the poor percep- you are using a CRT display, you will different colors on the screen at once. A tual performance of eight-bit intensi- get better if your overall typical lookup table has eight-bit values ties, due to the contrast sensitivity thresh- ambient illumination is reduced. for each of red, green and blue, so each old of human vision that I discussed in pixel can be chosen from set of 16.7␣mil- the Perception section of this note. The • Ensure that the Black Level (or Bright- lion possible codes. As in 24-bit color visibility of contouring is enhanced by a ness) of your CRT is set to correctly systems, the number of these colors perceptual effect called Mach bands, reproduce black elements on the from this set that can be distinguished is consequently the artifact is sometimes screen. considerably less than sixteen million. called banding. • Use gamma-corrected representations Pseudocolor systems usually have In fixed-point intensity coding where of RGB values whenever you can. An lookup tables whose outputs produce black is code zero, code␣100 is at the image coded in gamma-corrected voltage at the display. Consequently, it threshold of visibility at␣1% contrast space has very good perceptual uni- is conventional for a pseudocolor (or sensitivity: code␣50 represents the dark- formity, and will display much higher “8-bit”) application to provide, to a est gray the can be reproduced without quality than if coded as 8-bit intensity graphics system, RGB color values that the increments between adjacent codes values. are already gamma-corrected for a typi- being perceptible. I call this value best cal monitor. Consequently, a • When you exchange images either in gray. I consider one of the determinants truecolor or pseudocolor form, code pseudocolor image stored in a TIFF, of the quality of a computer graphics GIF or SunRaster file is almost invari- RGB color values using the image to be the intensity ratio between CCIR␣Rec.␣709 transfer function, ably accompanied by a colormap whose brightest white and best gray. In an RGB values implicitly incorporate gamma corrected with a 0.45-power eight-bit linear-light system, this ratio is function. gamma correction. If these RGB values a mere 2.55:1. If an image is contained are loaded into a 24-bit framebuffer within this contrast ratio then it will not • In the absence of reliable information whose lookup table is arranged to exhibit banding, but the low contrast about your monitor, assume a gamma gamma-correct intensity values, the ratio will cause the image to appear flat. value of 2.5 at the display and pre- pseudocolor values will be gamma cor- If an image has a contrast ratio substan- correct accordingly. If your monitor is rected a second time resulting in a se- tially larger than 2.5:1, then it is liable to viewed in a dim surround, precorrect verely “washed-out” appearance of the show banding. In twelve-bit linear light for a gamma value of about 2.2. colors. coding the ratio improves to 40:1, which Acknowledgments If you want to recover intensity from is adequate for the office but does not gamma-corrected RGB values, for ex- approach the quality of a photographic I would like to thank LeRoy E. DeMarsh ample to “back-out” the gamma correc- reproduction or the cinema. for many helpful discussions on these tion that is implicit in RGB colormap High-end software systems that are not topics. I thank my employer Sun values associated with an 8-bit dependent on hardware acceleration Microsystems Computer Corporation — colormapped image, construct an in- usually perform rendering calculations and particularly my manager Dr. Paul verse-gamma table. You can employ a in intensity domain, then map into the Borrill — for permitting me to spend lookup technique as above, but building gamma-corrected domain through soft- considerable time contributing to an inverse table INTEN_FROM_SIG ware and write gamma-corrected val- SMPTE activities. Linda Bohn and Dean using the exponent (1.0/0.45) instead of ues into the framebuffer. These systems Stanton of Sun also contributed to this note.

1108 SMPTE Journal, December 1993