Saturday, 26 May 2012

Gamma correction


Gamma correction, gamma nonlinearity, gamma encoding, or generally artlessly gamma, is the name of a nonlinear operation acclimated to cipher and break luminance or tristimulus ethics in video or still angel systems.1 Gamma alteration is, in the simplest cases, authentic by the afterward power-law expression:

where A is a connected and the ascribe and achievement ethics are non-negative absolute values; in the accepted case of A = 1, inputs and outputs are about in the ambit 0–1. A gamma amount γ < 1 is sometimes alleged an encoding gamma, and the action of encoding with this compressive power-law nonlinearity is alleged gamma compression; against a gamma amount γ > 1 is alleged a adaptation gamma and the appliance of the all-embracing power-law nonlinearity is alleged gamma expansion.

Explanation


Gamma encoding of images is appropriate to atone for backdrop of animal vision, to aerate the use of the $.25 or bandwidth about to how bodies apperceive ablaze and color.1 Animal eyes beneath accepted beam altitude (not angle atramentous or blindingly bright) follows an almost gamma or ability function. If images are not gamma encoded, they admeasure too abounding $.25 or too abundant bandwidth to highlights that bodies cannot differentiate, and too few bits/bandwidth to adumbration ethics that bodies are acute to and would crave added bits/bandwidth to advance the aforementioned beheld quality.12 Gamma encoding of amphibian point images is not appropriate (and may be counterproductive) because the amphibian point architecture already provides a pseudo-logarithmic encoding.

A accepted delusion is that gamma encoding was developed to atone for the input–output appropriate of cathode ray tube (CRT) displays.2 In CRT displays the electron-gun current, and appropriately ablaze intensity, varies nonlinearly with the activated anode voltage. Altering the ascribe arresting by gamma compression can abolish this nonlinearity, such that the achievement account has the advised luminance. However, the gamma characteristics of the affectation accessory do not play a agency in the gamma encoding of images and video — they charge gamma encoding to aerate the beheld superior of the signal, behindhand of the gamma characteristics of the affectation device.12 The affinity of CRT physics to the changed of gamma encoding bare for video manual was a aggregate of luck and engineering which simplified the electronics in aboriginal television sets.

Generalized gamma


The abstraction of gamma can be activated to any nonlinear relationship. For the power-law accord Vout = Vinγ, the ambit on a log–log artifice is a beeline line, with abruptness everywhere according to gamma (slope is represented actuality by the acquired operator):

That is, gamma can be visualised as the abruptness of the input–output ambit if advised on logarithmic axes. For a power-law curve, this abruptness is constant, but the abstraction can be continued to any blazon of curve, in which case gamma (strictly speaking, "point gamma"3) is authentic as the abruptness of the ambit in any accurate region.

In photography


When a accurate blur is apparent to light, the aftereffect of the acknowledgment can be represented on a blueprint assuming log of acknowledgment on the accumbent axis, and density, or log of transmittance, on the vertical axis. Such curves are accepted as Hurter–Driffield curves. Since both axes use logarithmic units, the abruptness of the beeline area of the ambit is alleged the gamma of the film. Negative blur about has a gamma beneath than 1; absolute blur (slide film, changeabout film) about has a gamma greater than 1.

Photographic blur has a abundant greater adeptness to almanac accomplished differences in adumbration than can be reproduced on accurate paper. Similarly, a lot of video screens are not able of announcement the ambit of brightnesses (dynamic range) that can be captured by archetypal cyberbanking cameras.4 For this reason, ample aesthetic accomplishment is invested in allotment in which bargain anatomy the aboriginal angel should be presented. The gamma correction, or adverse selection, is allotment of the accurate repertoire acclimated to acclimatize the reproduced image.

Analogously, agenda cameras almanac ablaze application cyberbanking sensors that usually acknowledge linearly. In the action of apprehension beeline raw abstracts to accepted RGB abstracts (e.g. for accumulator into JPEG angel format), blush amplitude transformations and apprehension transformations will be performed. In particular, about all accepted RGB blush spaces and book formats use a non-linear encoding (a gamma compression) of the advised intensities of the primary colors of the accurate reproduction; in addition, the advised reproduction is about consistently nonlinearly accompanying to the abstinent arena intensities, via a accent reproduction nonlinearity.

Windows, Mac, sRGB and TV/video standard gammas


In a lot of computer systems, images are encoded with a gamma of about 0.45 and decoded with a gamma of 2.2; a notable exception, until the absolution of Mac OS X 10.6 (Snow Leopard) in September 2009, were Macintosh computers: they acclimated 0.55 and 1.8 respectively. In any case, bifold abstracts in still angel files (as JPEG) are absolutely encoded (that is, they backpack gamma-encoded values, not beeline intensities), as are motion account files (such as MPEG). The arrangement can optionally added administer both cases, through blush management, if a bigger bout to the achievement accessory gamma is required.

The sRGB blush amplitude accepted acclimated with a lot of cameras, PCs, and printers does not use a simple power-law nonlinearity as above, but has a adaptation gamma amount abreast 2.2 over abundant of its range, as apparent in the artifice to the right. Below a aeroembolism amount of 0.04045 or a beeline acuteness of 0.00313, the ambit is beeline (encoded amount proportional to intensity), so γ = 1. The abject atramentous ambit abaft the red ambit is a accepted γ = 2.2 power-law curve, for comparison.

Output to CRT-based television receivers and monitors does not usually crave added gamma correction, back the accepted video signals that are transmitted or stored in angel files absorb gamma compression that provides a affable angel afterwards the gamma amplification of the CRT (it is not the exact inverse). For television signals, the absolute gamma ethics are authentic by the video standards (NTSC, PAL or SECAM), and are consistently anchored and able-bodied accepted values.

Power law for video display


A gamma appropriate is a power-law accord that approximates the accord amid the encoded luma in a television arrangement and the absolute adapted angel luminance.

With this nonlinear relationship, according accomplish in encoded luminance accord almost to alone according accomplish in brightness. Ebner and Fairchild5 acclimated an backer of 0.43 to catechumen beeline acuteness into animation for neutrals; the reciprocal, about 2.33 (quite abutting to the 2.2 amount cited for a archetypal affectation subsystem), would accommodate optimal perceptual encoding of grays. The afterward analogy shows the aberration amid a calibration with linearly-increasing encoded luminance arresting (linear input) and a calibration with linearly-increasing acuteness (i.e., gamma-corrected) calibration (linear output).

Linear encoding VS = 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

Linear intensity I = 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0

On a lot of displays (those with gamma of about 2.2), one can beam that the linear-intensity calibration has a ample jump in perceived accuracy amid the acuteness ethics 0.0 and 0.1, while the accomplish at the college end of the calibration are hardly perceptible. The linearly-encoded scale, which has a nonlinearly-increasing intensity, will appearance abundant added even accomplish in perceived brightness.

A cathode ray tube (CRT), for example, converts a video arresting to ablaze in a nonlinear way, because the electron gun's acuteness (brightness) as a action of activated video voltage is nonlinear. The ablaze acuteness I is accompanying to the antecedent voltage VS according to

where γ is the Greek letter gamma. For a CRT, the gamma that relates accuracy to voltage is usually in the ambit 2.35 to 2.55; video look-up tables in computers usually acclimatize the arrangement gamma to the ambit 1.8 to 2.2,1 which is in the arena that makes a compatible encoding aberration accord about compatible perceptual accuracy difference, as illustrated in the diagram at the top of this section.

For simplicity, accede the archetype of a connected CRT. In this case, if a video arresting of 0.5 (representing mid-gray) is fed to the display, the acuteness or accuracy is about 0.22 (resulting in a aphotic gray). Authentic atramentous (0.0) and authentic white (1.0) are the alone shades that are artless by gamma.

To atone for this effect, the changed alteration action (gamma correction) is sometimes activated to the video arresting so that the end-to-end acknowledgment is linear. In added words, the transmitted arresting is advisedly adulterated so that, afterwards it has been adulterated afresh by the affectation device, the eyewitness sees the actual brightness. The changed of the action aloft is:

where VC is the adapted voltage and VS is the antecedent voltage, for archetype from an angel sensor that converts photocharge linearly to a voltage. In our CRT archetype 1/γ is 1/2.2 or 0.45.

A blush CRT receives three video signals (red, blooming and blue) and in accepted anniversary blush has its own amount of gamma, denoted γR, γG or γB. However, in simple affectation systems, a individual amount of γ is acclimated for all three colors.

Other affectation accessories accept altered ethics of gamma: for example, a Game Boy Advance affectation has a gamma amid 3 and 4 depending on lighting conditions. In LCDs such as those on laptop computers, the affiliation amid the arresting voltage VS and the acuteness I is actual nonlinear and cannot be declared with gamma value. However, such displays administer a alteration assimilate the arresting voltage in adjustment to about get a accepted γ = 2.5 behavior. In NTSC television recording, γ = 2.2.

The power-law function, or its inverse, has a abruptness of beyond at zero. This leads to problems in converting from and to a gamma colorspace. For this acumen a lot of formally authentic colorspaces such as sRGB will ascertain a straight-line articulation abreast aught and add adopting x + K (where K is a constant) to a ability so the ambit has connected slope. This beeline band does not represent what the CRT does, but does accomplish the blow of the ambit added carefully bout the aftereffect of ambient ablaze on the CRT. In such expressions the backer is not the gamma; for instance, the sRGB action uses a ability of 2.4 in it, but added carefully resembles a power-law action with an backer of 2.2, after a beeline portion.

Methods to perform display gamma correction in computing


Up to four elements can be manipulated in adjustment to accomplish gamma encoding to actual the angel to be apparent on a archetypal 2.2- or 1.8-gamma computer display:

The pixel's acuteness ethics in a accustomed angel file; that is, the bifold pixel ethics are stored in the book in such way that they represent the ablaze acuteness via gamma-compressed ethics instead of a beeline encoding. This is done systematically with agenda video files (as those in a DVD movie), in adjustment to abbreviate the gamma-decoding footfall while playing, and aerate angel superior for the accustomed storage. Similarly, pixel ethics in accepted angel book formats are usually gamma-compensated, either for sRGB gamma (or equivalent, an approximation of archetypal of bequest adviser gammas), or according to some gamma defined by metadata such as an ICC profile. If the encoding gamma does not bout the reproduction system's gamma, added alteration may be done, either on affectation or to actualize a adapted angel book with a altered profile.

The apprehension software writes gamma-encoded pixel bifold ethics anon to the video anamnesis (when highcolor/truecolor modes are used) or in the CLUT accouterments registers (when indexed blush modes are used) of the affectation adapter. They drive Digital-to-Analog Converters (DAC) which achievement the proportional voltages to the display. For example, if application 24-bit RGB blush (8 $.25 per channel), autograph a amount of 128 (rounded mean of the 0–255 byte range) in video anamnesis it outputs the proportional ≈ 0.5 voltage to the display, which it is apparent darker due to the adviser behavior. Alternatively, to accomplish ≈ 50% intensity, a gamma-encoded look-up table can be activated to address a amount abreast to 187 instead of 128 by the apprehension software.

Modern affectation adapters accept committed calibrating CLUTs, which can be loaded already with the adapted gamma-correction look-up table in adjustment to adapt the encoded signals digitally afore the DACs that achievement voltages to the monitor.6 Ambience up these tables to be actual is alleged accouterments calibration.7

Some avant-garde monitors acquiesce to the user to dispense their gamma behavior (as if it were alone addition brightness/contrast-like setting), encoding the ascribe signals by themselves afore they are displayed on screen. This is aswell a arrangement by accouterments address but it is performed on the analog electric signals instead of remapping the agenda values, as in the antecedent cases.

In a accurately calibrated system, anniversary basic will accept a defined gamma for its ascribe and/or achievement encodings.7 Stages may change the gamma to actual for altered requirements, and assuredly the achievement accessory will do gamma adaptation or alteration as needed, to get to a beeline acuteness domain. All the encoding and alteration methods can be arbitrarily superimposed, after alternate ability of this actuality a part of the altered elements; if done incorrectly, these conversions can advance to awful adulterated results, but if done accurately as dictated by standards and conventions will advance to a appropriately activity system.

In a archetypal system, for archetype from camera through JPEG book to display, the role of gamma alteration will absorb several allied parts. The camera encodes its rendered angel into the JPEG book application one of the accepted gamma ethics such as 2.2, for accumulator and transmission. The affectation computer may use a blush administration engine to catechumen to a altered blush amplitude (such as earlier Macintosh's γ = 1.8 blush space) afore putting pixel ethics into its video memory. The adviser may do its own gamma alteration to bout the CRT gamma to that acclimated by the video system. Coordinating the apparatus via accepted interfaces with absence accepted gamma ethics makes it accessible to get such arrangement appropriately configured.