Gamma correction
Gamma correction or gamma is a nonlinear operation used to encode and decode luminance in video or images.
Gamma correction is, in the simplest cases, defined by the following power-law expression:
where the non-negative real input value is raised to the power and multiplied by the constant A to get the output value. In the common case of, inputs and outputs are typically in the range 0–1.
A gamma value is sometimes called an encoding gamma, and the process of encoding with this compressive power-law nonlinearity is called gamma compression; conversely, a gamma value is called a decoding gamma, and the application of the expansive power-law nonlinearity is called gamma expansion.
Explanation
Gamma encoding of images is used to optimize the usage of bits when encoding an image, or bandwidth used to transport an image, by taking advantage of the non-linear manner in which humans perceive light and color. The human perception of brightness, under common illumination conditions, follows an approximate power function, with greater sensitivity to relative differences between darker tones than between lighter tones, consistent with the Stevens' power law for brightness perception. If images are not gamma-encoded, they allocate too many bits or too much bandwidth to highlights that humans cannot differentiate, and too few bits or too little bandwidth to shadow values that humans are sensitive to and would require more bits/bandwidth to maintain the same visual quality. Gamma encoding of floating-point images is not required, because the floating-point format already provides a piecewise linear approximation of a logarithmic curve.Although gamma encoding was developed originally to compensate for the brightness characteristics of cathode-ray tube displays, that is not its main purpose or advantage in modern systems. In CRT displays, the light intensity varies nonlinearly with the electron-gun voltage. Altering the input signal by gamma compression can cancel this nonlinearity, such that the output picture has the intended luminance. However, the gamma characteristics of the display device do not play a factor in the gamma encoding of images and video. They need gamma encoding to maximize the visual quality of the signal, regardless of the gamma characteristics of the display device. The similarity of CRT physics to the inverse of gamma encoding needed for video transmission was a combination of coincidence and engineering, which simplified the electronics in early television sets.
Photographic film has a much greater ability to record fine differences in shade than can be reproduced on photographic paper. Similarly, most video screens are not capable of displaying the range of brightnesses that can be captured by typical electronic cameras.
For this reason, considerable artistic effort is invested in choosing the reduced form in which the original image should be presented. The gamma correction, or contrast selection, is part of the photographic repertoire used to adjust the reproduced image.
Analogously, digital cameras record light using electronic sensors that usually respond linearly. In the process of rendering linear raw data to conventional RGB data, color space transformations and rendering transformations will be performed. In particular, almost all standard RGB color spaces and file formats use a non-linear encoding of the intended intensities of the primary colors of the photographic reproduction. In addition, the intended reproduction is almost always nonlinearly related to the measured scene intensities, via a tone reproduction nonlinearity.
Generalized gamma
The concept of gamma can be applied to any nonlinear relationship. For the power-law relationship, the curve on a log–log plot is a straight line, with slope everywhere equal to gamma :That is, gamma can be visualized as the slope of the input–output curve when plotted on logarithmic axes. For a power-law curve, this slope is constant, but the idea can be extended to any type of curve, in which case gamma is defined as the slope of the curve in any particular region.
Film photography
When a photographic film is exposed to light, the result of the exposure can be represented on a graph showing log of exposure on the horizontal axis, and density, or negative log of transmittance, on the vertical axis. For a given film formulation and processing method, this curve is its characteristic or Hurter–Driffield curve. Since both axes use logarithmic units, the slope of the linear section of the curve is called the gamma of the film. Negative film typically has a gamma less than 1; positive film typically has a gamma with absolute value greater than 1.Standard gammas
Analog TV
Output to CRT-based television receivers and monitors does not usually require further gamma correction. The standard video signals that are transmitted or stored in image files incorporate gamma compression matching the gamma expansion of the CRT.For television signals, gamma values are fixed and defined by the analog video standards. CCIR System M, associated with NTSC color, use gamma 2.2; systems B/G, H, I, D/K, K1, L, M, and N, associated with PAL or SECAM color use gamma 2.8.
Computer displays
In most computer display systems, images are encoded with a gamma of about 0.45 and decoded with the reciprocal gamma of 2.2. A notable exception, until the release of Mac OS X 10.6 in September 2009, were Macintosh computers, which encoded with a gamma of 0.55 and decoded with a gamma of 1.8. In any case, binary data in still image files are explicitly encoded, as are motion picture files. The system can optionally further manage both cases, through color management, if a better match to the output device gamma is required.The sRGB color space standard used with most cameras, PCs, and printers does not use a simple power-law nonlinearity as above, but has a decoding gamma value near 2.2 over much of its range, as shown in the plot to the right/above. Below a compressed value of 0.04045 or a linear intensity of 0.00313, the curve is linear, so. The dashed black curve behind the red curve is a standard power-law curve, for comparison.
Gamma correction in computers is used, for example, to display a gamma = 1.8 Apple picture correctly on a gamma = 2.2 PC monitor by changing the image gamma. Another usage is equalizing of the individual color-channel gammas to correct for monitor discrepancies.
Gamma meta information
Some picture formats allow an image's intended gamma to be stored as metadata, facilitating automatic gamma correction. The PNG specification includes the gAMA chunk for this purpose and with formats such as JPEG and TIFF the Exif Gamma tag can be used. Some formats can specify the ICC profile which includes a transfer function.These features have historically caused problems, especially on the web. For HTML and CSS colors and JPG or GIF images without attached color profile metadata, popular browsers passed numerical color values to the display without color management, resulting in substantially different appearance between devices; however those same browsers sent images with gamma explicitly set in metadata through color management, and also applied a default gamma to PNG images with metadata omitted. This made it impossible for PNG images to simultaneously match HTML or untagged JPG colors on every device. This situation has since improved, as most major browsers now support the gamma setting.
Power law for video display
A gamma characteristic is a power-law relationship that approximates the relationship between the encoded luma in a television system and the actual desired image luminance.With this nonlinear relationship, equal steps in encoded luminance correspond roughly to subjectively equal steps in brightness. Ebner and Fairchild used an exponent of 0.43 to convert linear intensity into lightness for neutrals; the reciprocal, approximately 2.33, was found to provide approximately optimal perceptual encoding of grays.
The following illustration shows the difference between a scale with linearly-increasing encoded luminance signal and a scale with linearly-increasing intensity scale.
On most displays, one can observe that the linear-intensity scale has a large jump in perceived brightness between the intensity values 0.0 and 0.1, while the steps at the higher end of the scale are hardly perceptible. The gamma-encoded scale, which has a nonlinearly-increasing intensity, will show much more even steps in perceived brightness.
A CRT, for example, converts a video signal to light in a nonlinear way, because the electron gun's intensity as a function of applied video voltage is nonlinear. The light intensity I is related to the source voltage Vs according to
where γ is the Greek letter gamma. For a CRT, the gamma that relates brightness to voltage is usually in the range 2.35 to 2.55; video look-up tables in computers usually adjust the system gamma to the range 1.8 to 2.2, which is in the region that makes a uniform encoding difference give approximately uniform perceptual brightness difference, as illustrated in the diagram at the top of this section.
For simplicity, consider the example of a monochrome CRT. In this case, when a video signal of 0.5 is fed to the display, the intensity or brightness is about 0.22. Pure black and pure white are the only shades that are unaffected by gamma.
To compensate for this effect, the inverse transfer function is sometimes applied to the video signal so that the end-to-end response is linear. In other words, the transmitted signal is deliberately distorted so that, after it has been distorted again by the display device, the viewer sees the correct brightness. The inverse of the function above is
where Vc is the corrected voltage, and Vs is the source voltage, for example, from an image sensor that converts photocharge linearly to a voltage. In our CRT example 1/γ is 1/2.2 ≈ 0.45.
A color CRT receives three video signals and in general each color has its own value of gamma, denoted γR, γG or γB. However, in simple display systems, a single value of γ is used for all three colors.
Other display devices have different values of gamma: for example, a Game Boy Advance display has a gamma between 3 and 4 depending on lighting conditions. In LCDs such as those on laptop computers, the relation between the signal voltage Vs and the intensity I is very nonlinear and cannot be described with gamma value. However, such displays apply a correction onto the signal voltage in order to approximately get a standard behavior. In NTSC television recording,.
The power-law function, or its inverse, has a slope of infinity at zero. This leads to problems in converting from and to a gamma colorspace. For this reason most formally defined colorspaces such as sRGB will define a straight-line segment near zero and add raising to a power so the curve has continuous slope. This straight line does not represent what the CRT does, but does make the rest of the curve more closely match the effect of ambient light on the CRT. In such expressions the exponent is not the gamma; for instance, the sRGB function uses a power of 2.4 in it, but more closely resembles a power-law function with an exponent of 2.2, without a linear portion.