Old page wikitext, before the edit (old_wikitext ) | '[[File:GammaFunctionGraph.svg|thumb|Example of [[Cathode ray tube|CRT]] gamma correction]]
[[Image:GammaCorrection demo.jpg|thumb|The effect of gamma correction on an image: The original image was taken to varying powers, showing that powers larger than one make the shadows darker, while powers smaller than one make dark regions lighter.]]
'''Gamma correction''', '''gamma nonlinearity''', '''gamma encoding''', or often simply '''gamma''', is the name of a nonlinear operation used to code and decode [[luminance (relative)|luminance]] or [[tristimulus value]]s in [[video]] or [[still image]] systems.<ref name=poynton>{{cite book | title = Digital Video and HDTV: Algorithms and Interfaces | author = Charles A. Poynton | publisher = Morgan Kaufmann | year = 2003 | isbn = 1-55860-792-7 | pages = 260, 630 | url = http://books.google.com/books?id=ra1lcAwgvq4C&pg=RA1-PA630&dq=gamma-encoding}}</ref> Gamma correction is, in the simplest cases, defined by the following '''[[Power law|power-law]]''' expression:
:<math>V_{\text{out}} = A {V_{\text{in}}}^{\gamma}</math>
where {{math|''A''}} is a constant and the input and output values are non-negative real values; in the common case of {{math|''A'' {{=}} 1}}, inputs and outputs are typically in the range 0–1. A gamma value {{nowrap|''γ'' < 1}} 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 {{nowrap|''γ'' > 1}} is called a '''decoding gamma''' and the application of the expansive power-law nonlinearity is called '''gamma expansion'''.
== Explanation ==
Gamma encoding of images is required to compensate for properties of human vision - to maximize the use of the bits or bandwidth relative to how humans perceive light and color.<ref name=poynton/> Human vision under common illumination conditions (not pitch black or blindingly bright) follows an approximate gamma or power function. 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/bandwidth to shadow values that humans are sensitive to and would require more bits/bandwidth to maintain the same visual quality.<ref name=poynton/><ref name=FQAGamma>[http://www.poynton.com/notes/color/GammaFQA.html Charles Poynton (2010). Frequently Questioned Answers about Gamma.]</ref> Gamma encoding of [[floating point]] images is not required (and may be counterproductive) because the floating point format already provides a pseudo-logarithmic encoding.
A common misconception is that gamma encoding was developed to compensate for the input–output characteristic of [[cathode ray tube]] (CRT) displays.<ref name=FQAGamma/> In CRT displays the electron-gun current, and thus light intensity, varies nonlinearly with the applied anode voltage. Altering the input signal by gamma compression can cancel this nonlinearity, such that the output picture has the intended luminance. But in fact, 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.<ref name=poynton/><ref name=FQAGamma/> The similarity of CRT physics to the inverse of gamma encoding needed for video transmission was a combination of luck and engineering which simplified the electronics in early television sets.
==Generalized gamma==
The concept of gamma can be applied to any nonlinear relationship. For the [[power-law]] relationship ''V''<sub>out</sub> = ''V''<sub>in</sub><sup>γ</sup>, the curve on a log–log plot is a straight line, with slope everywhere equal to gamma (slope is represented here by the [[derivative]] operator):
:<math>\gamma = \frac{\mathrm{d} \log(V_{\text{out}})}{\mathrm{d} \log(V_{\text{in}})}</math>
That is, gamma can be visualised 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 (strictly speaking, "point gamma"<ref>R.W.G. Hunt, ''The Reproduction of Colour'', 6th Ed, p48</ref>) is defined as the slope of the curve in any particular region.
==In photography==
When a [[photographic film]] is exposed to light, the result of the exposure can be represented on a graph showing log of [[Exposure (photography)|exposure]] on the horizontal axis, and density, or log of transmittance, on the vertical axis. Such curves are known as [[Sensitometry|Hurter–Driffield curves]]. 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 (slide film, reversal film) typically has a gamma greater than 1.
[[Ansel Adams]] describes the gamma concept, but then dismisses it as "a term of interest and significance only to the research scientist and the manufacturer", and elaborates:<ref>{{cite book | title = The Negative | author = Ansel Adams | year = 1968 | publisher = Morgan & Morgan, Inc}}</ref>
<blockquote>"7 minutes at 68°F in Ansco 47 for Isopan" represents "normal" to me. I have no idea what the actual effective gamma is, nor do I care. I could consider this degree of development as yielding Gamma = 1.0 or being Development No. 9 or Operation H, or any other symbol I choose. But why should I inject an unnecessary and confusing symbol for a perfectly simple statement of procedure? "Isopan/Ansco 47/68°F/7minutes" is definite and easily expressed and understood as the means of obtaining ''my'' "normal" negative.</blockquote>
[[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 (dynamic range) that can be captured by typical electronic cameras.<ref>
{{cite book
| title = An introduction to video and audio measurement
| edition = 3rd
| author = Peter Hodges
| publisher = Elsevier
| year = 2004
| isbn = 978-0-240-80621-1
| page = 174
| url = http://books.google.com/books?id=Fmd0lbD32R0C&pg=PA174
}}</ref>
For this reason, considerable artistic effort is invested in choosing in which reduced form 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 (e.g. for storage into JPEG image format), 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 (a [[gamma compression]]) of the intended intensities of the [[primary color]]s of the photographic reproduction; in addition, the intended reproduction is almost always nonlinearly related to the measured scene intensities, via a [[tone reproduction]] nonlinearity.
==Windows, Mac, sRGB and TV/video standard gammas==
[[Image:SRGB gamma.svg|thumb|right|227px|Plot of the [[sRGB]] standard gamma-expansion nonlinearity (red), and its local gamma value, slope in log–log space (blue).]]
In most 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 release of Mac OS X 10.6 (Snow Leopard) in September 2009, were [[Macintosh]] computers: they used 0.55 and 1.8 respectively. In any case, [[binary file|binary]] data in still image files (as [[JPEG]]) are explicitly encoded (that is, they carry gamma-encoded values, not linear intensities), as are motion picture files (such as [[MPEG]]). 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. Below a compressed value of 0.04045 or a linear intensity of 0.00313, the curve is linear (encoded value proportional to intensity), so {{nowrap|1=''γ'' = 1}}. The dashed black curve behind the red curve is a standard {{nowrap|1=''γ'' = 2.2}} power-law curve, for comparison.
Output to CRT-based television receivers and monitors does not usually require further gamma correction, since the standard video signals that are transmitted or stored in image files incorporate gamma compression that provides a pleasant image after the gamma expansion of the CRT (it is not the exact inverse). For television signals, the actual gamma values are defined by the video standards ([[NTSC]], [[PAL]] or [[SECAM]]), and are always fixed and well known values.
==Power law for video display==
A '''gamma characteristic''' is a [[power law|power-law]] relationship that approximates the relationship between the encoded [[Luminance (video)|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<ref name="EbnerCIC61998">Fritz Ebner and Mark D Fairchild, "Development and testing of a color space (IPT) with improved hue uniformity," ''Proceedings of IS&T/SID's Sixth Color Imaging Conference,'' p 8-13 (1998).</ref> used an exponent of 0.43 to convert linear intensity into lightness for neutrals; the reciprocal, approximately 2.33 (quite close to the 2.2 figure cited for a typical display subsystem), would provide optimal perceptual encoding of grays. The following illustration shows the difference between a scale with linearly-increasing encoded luminance signal (linear input) and a scale with linearly-increasing intensity (i.e., gamma-corrected) scale (linear output).
{| style="background: #000000; color: gray; padding: 1em; margin: 0 2em 0 2em;"
| style="color: #A0A0A0;" | Linear encoding
| style="color: #A0A0A0;" | ''V''<sub>''S''</sub> =
| style="background: #000000; color: #FFFFFF;" | 0.0
| style="background: #1A1A1A; color: #FFFFFF;" | 0.1
| style="background: #333333; color: #FFFFFF;" | 0.2
| style="background: #4D4D4D; color: #FFFFFF;" | 0.3
| style="background: #666666; color: #FFFFFF;" | 0.4
| style="background: #808080; color: #FFFFFF;" | 0.5
| style="background: #999999; color: #000000;" | 0.6
| style="background: #B3B3B3; color: #000000;" | 0.7
| style="background: #CCCCCC; color: #000000;" | 0.8
| style="background: #E6E6E6; color: #000000;" | 0.9
| style="background: #FFFFFF; color: #000000;" | 1.0
|-
| style="color: #A0A0A0;" | Linear intensity
| style="color: #A0A0A0;" | ''I'' =
| style="background: #000000; color: #FFFFFF;" | 0.0
| style="background: #5A5A5A; color: #FFFFFF;" | 0.1
| style="background: #7B7B7B; color: #FFFFFF;" | 0.2
| style="background: #949494; color: #000000;" | 0.3
| style="background: #A9A9A9; color: #000000;" | 0.4
| style="background: #BBBBBB; color: #000000;" | 0.5
| style="background: #CBCBCB; color: #000000;" | 0.6
| style="background: #D9D9D9; color: #000000;" | 0.7
| style="background: #E7E7E7; color: #000000;" | 0.8
| style="background: #F4F4F4; color: #000000;" | 0.9
| style="background: #FFFFFF; color: #000000;" | 1.0
|}
On most displays (those with gamma of about 2.2), 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 linearly-encoded scale, which has a nonlinearly-increasing intensity, will show much more even steps in perceived brightness.
A [[cathode ray tube]] (CRT), for example, converts a video signal to light in a nonlinear way, because the electron gun's intensity (brightness) as a function of applied video voltage is nonlinear. The light intensity ''I'' is related to the source [[voltage]] ''V''<sub>''S''</sub> according to
:<math>I \propto V_{\rm S}{}^{\gamma}</math>
where ''γ'' is the [[Greek alphabet|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 table]]s in computers usually adjust the system gamma to the range 1.8 to 2.2,<ref name=poynton/> 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 (representing mid-gray) is fed to the display, the intensity or brightness is about 0.22 (resulting in a dark gray). Pure black (0.0) and pure white (1.0) are the only shades that are unaffected by gamma.
To compensate for this effect, the inverse transfer function ('''gamma correction''') 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:
:<math>V_{\rm C} \propto V_{\rm S}{}^{(1/\gamma)}</math>
where ''V''<sub>C</sub> is the corrected voltage and ''V''<sub>''S''</sub> 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 or 0.45.
A color CRT receives three video signals (red, green and blue) and in general each color has its own value of gamma, denoted ''γ''<sub>''R''</sub>, ''γ''<sub>''G''</sub> or ''γ''<sub>''B''</sub>. 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 ''V''<sub>''S''</sub> 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 {{nowrap|1=''γ'' = 2.5}} behavior. In [[NTSC]] [[television]] recording, {{nowrap|1=''γ'' = 2.2}}.
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 {{nowrap|''x'' + ''K''}} (where ''K'' is a constant) 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.
==Methods to perform display gamma correction in computing==
Up to four elements can be manipulated in order to achieve gamma encoding to correct the image to be shown on a typical 2.2- or 1.8-gamma computer display:
* The pixel's intensity values in a given image file; that is, the binary pixel values are stored in the file in such way that they represent the light intensity via gamma-compressed values instead of a linear encoding. This is done systematically with digital video files (as those in a [[DVD]] movie), in order to minimize the gamma-decoding step while playing, and maximize image quality for the given storage. Similarly, pixel values in standard image file formats are usually gamma-compensated, either for sRGB gamma (or equivalent, an approximation of typical of legacy monitor gammas), or according to some gamma specified by metadata such as an [[ICC profile]]. If the encoding gamma does not match the reproduction system's gamma, further correction may be done, either on display or to create a modified image file with a different profile.
* The rendering software writes gamma-encoded pixel binary values directly to the video memory (when [[highcolor]]/[[truecolor]] modes are used) or in the [[CLUT]] [[hardware register]]s (when [[indexed color]] modes are used) of the [[display adapter]]. They drive [[Digital-to-Analog Converter]]s (DAC) which output the proportional voltages to the display. For example, when using [[List of monochrome and RGB palettes#24-bit RGB|24-bit RGB]] color (8 bits per channel), writing a value of 128 (rounded midpoint of the 0–255 [[byte]] range) in video memory it outputs the proportional {{nowrap|≈ 0.5}} voltage to the display, which it is shown darker due to the monitor behavior. Alternatively, to achieve {{nowrap|≈ 50%}} intensity, a gamma-encoded [[look-up table]] can be applied to write a value near to 187 instead of 128 by the rendering software.
* Modern display adapters have dedicated calibrating CLUTs, which can be loaded once with the appropriate gamma-correction [[look-up table]] in order to modify the encoded signals digitally before the DACs that output voltages to the monitor.<ref>[http://msdn2.microsoft.com/en-us/library/ms536529.aspx ''SetDeviceGammaRamp'', the Win32 API to download arbitrary gamma ramps to display hardware]</ref> Setting up these tables to be correct is called ''hardware calibration''.<ref name=cm>[http://ftp2.bmtmicro.com/dlc/Color%20Management.pdf Jonathan Sachs (2003). Color Management. Digital Light & Color.]</ref>
* Some modern monitors allow to the user to manipulate their gamma behavior (as if it were merely another brightness/contrast-like setting), encoding the input signals by themselves before they are displayed on screen. This is also a ''calibration by hardware'' technique but it is performed on the analog electric signals instead of remapping the digital values, as in the previous cases.
In a correctly calibrated system, each component will have a specified gamma for its input and/or output encodings.<ref name=cm/> Stages may change the gamma to correct for different requirements, and finally the output device will do gamma decoding or correction as needed, to get to a linear intensity domain. All the encoding and correction methods can be arbitrarily superimposed, without mutual knowledge of this fact among the different elements; if done incorrectly, these conversions can lead to highly distorted results, but if done correctly as dictated by standards and conventions will lead to a properly functioning system.
In a typical system, for example from camera through [[JPEG]] file to display, the role of gamma correction will involve several cooperating parts. The camera encodes its rendered image into the JPEG file using one of the standard gamma values such as 2.2, for storage and transmission. The display computer may use a [[color management]] engine to convert to a different color space (such as older Macintosh's {{nowrap|1=''γ'' = 1.8}} color space) before putting pixel values into its video memory. The monitor may do its own gamma correction to match the CRT gamma to that used by the video system. Coordinating the components via standard interfaces with default standard gamma values makes it possible to get such system properly configured.
==Simple monitor tests==
[[Image:Gammatest.svg|left|300 px]]
To see whether one's computer [[Computer display|monitor]] is properly hardware adjusted and can display shadow detail in sRGB images properly, they should see the left half of the circle in the large black square very faintly (or not at all), but the right half should be clearly visible.
If not, one can adjust their monitor's [[Contrast (vision)|contrast]] and/or [[brightness]] setting. This alters the monitor's perceived gamma. The image is best viewed against a black background.
This procedure is not suitable for [[Color calibration|calibrating]] or print-proofing a monitor. It can be useful for making a monitor display sRGB images approximately correctly, on systems in which profiles are not used (for example, the Firefox browser prior to version 3.0 and many others) or in systems that assume untagged source images are in the sRGB colorspace.
On some operating systems running the [[X Window System]] one can change gamma-correction settings, by issuing the command <code>xgamma -gamma 2.1</code> for setting gamma value to 2.1, and <code>xgamma</code> for querying current value. In [[Macintosh]] systems, the gamma and other related screen calibrations are made through the OS control panel. [[Microsoft Windows]] versions before Windows Vista lack a first-party developed calibration tool.
[[Image:srgbnonlinearity.png|right]]
In the test pattern to the right, the linear intensity of each solid bar is the average of the linear intensities in the surrounding striped dither; therefore, ideally, the solid squares and the dithers should appear equally bright in a properly adjusted [[sRGB]] system.
==Terminology==
The term [[luminous emittance|intensity]] refers strictly to the amount of light that is emitted per unit of time and per unit of surface, in units of [[lux]]. Note, however, that in many fields of science this quantity is called [[luminous emittance]], as opposed to [[luminous intensity]], which is a different quantity. These distinctions, however, are largely irrelevant to gamma compression, which is applicable to any sort of normalized linear intensity-like scale.
''Luminance'' can mean several things even within the context of video and imaging:
*[[Luminance]] is the photometric brightness of an object, taking into account the wavelength-dependent sensitivity of the human eye (in units of [[candela|cd]]/m²);
*[[Luminance (video)]] is the encoded video "luma" signal, i.e. similar to the signal voltage ''V''<sub>''S''</sub>.
*[[Luminance (relative)]] is the luminance signal used in a color-space encoding, relative to a white level.
One contrasts "luminance" in the sense of color (no gamma compression) with "luma" in the sense of video (with gamma compression), and denote luminance by ''Y'' and luma by ''Y''′, the prime symbol (′) denoting gamma compression.<ref>Engineering Guideline EG 28, "Annotated Glossary of Essential Terms for Electronic Production," SMPTE, 1993.</ref>
Likewise, ''[[brightness]]'' is sometimes applied to various measures, including light levels, though it more properly applies to a subjective visual attribute.
Gamma correction is a type of [[power law]] function whose exponent is the [[Greek letter]] [[gamma]] (''γ''). It should not be confused with the mathematical [[Gamma function]]. The lower case gamma, ''γ'', is a [[parameter]] of the former; the upper case letter, Γ, is the name of (and symbol used for) the latter (as in Γ(''x'')). To use the word "function" in conjunction with gamma correction, one may avoid confusion by saying "generalized power law function."
Without context, a value labeled gamma might be either the encoding or the decoding value. Caution must be taken to correctly interpreting the value as that to be applied-to-compensate or to be compensated-by-applying its inverse. In common parlance, in many occasions the decoding value (as 2.2) is employed as if it were the encoding value, instead of its inverse (1/2.2 in this case) which is the ''real'' value that must be applied to encode gamma.
== See also ==
* [[Brightness]]
* [[Color management]]
* [[Color grading]]
* [[Contrast (vision)]]
* [[Luminance]]
* [[Luminance (video)]]
* [[Luminance (relative)]]
* [[Post-production]]
* [[Telecine]]
* [[Tone mapping]]
==References==
{{reflist}}
==External links==
===General information===
*[http://www.poynton.com/PDFs/Rehabilitation_of_gamma.pdf Rehabilitation of Gamma] by [[Charles Poynton]]
*[http://www.libpng.org/pub/png/spec/1.2/PNG-GammaAppendix.html Gamma tutorial] (from the [[Portable Network Graphics|PNG]] specification)
*[http://www.poynton.com/notes/colour_and_gamma/GammaFAQ.html Frequently Asked Questions about Gamma]
*[http://www.cgsd.com/papers/gamma.html CGSD - Gamma Correction Home Page] by Computer Graphics Systems Development Corporation
*[http://www.lagom.nl/lcd-test/index.php The Lagom LCD monitor test pages]
*[http://www.hdtvtest.co.uk/news/what-is-gamma-20080511108.htm Gamma Control Adjustment for HDTVs]
*[http://artbyplunkett.com/Unreal/gamma.html Gamma for Computer Games]
*[http://union-d.ru/projects/imagetools Batch gamma adjuster for Windows/Linux]
* Stanford University CS 178 [http://graphics.stanford.edu/courses/cs178/applets/gamma.html interactive Flash demo ] about gamma correction.
===Monitor gamma tools===
*[http://www.hex2bit.com/products/product_mcw.asp Monitor Calibration Wizard]
*[http://www.photoscientia.co.uk/Gamma.htm The Gamma adjustment page]
*[http://www.fho-emden.de/~hoffmann/measgamma10022004.pdf Measuring Gamma for Monitors (Gernot Hoffman)]
* [http://www.normankoren.com/makingfineprints1A.html#Monitor_test_pattern Monitor test pattern] for correct gamma correction (by Norman Koren)
*[http://links.twibright.com/calibration.html Links browser Gamma Calibration page]
*[http://www.quickgamma.de/indexen.html QuickGamma]
[[Category:Display technology]]
[[Category:Science of photography]]
[[Category:Power laws]]
[[bn:গামা সংশোধন]]
[[ca:Correcció gamma]]
[[de:Gammakorrektur]]
[[es:Corrección gamma]]
[[fr:Correction gamma]]
[[ko:감마 보정]]
[[it:Correzione di gamma]]
[[nl:Gammacorrectie]]
[[pl:Korekcja gamma]]
[[ru:Гамма-коррекция]]
[[fi:Gammakorjaus]]
[[sv:Gammakurva]]
[[zh:伽瑪校正]]' |
New page wikitext, after the edit (new_wikitext ) | '[[File:GammaFunctionGraph.svg|thumb|Example of [[Cathode ray tube|CRT]] gamma correction]]
[[Image:GammaCorrection demo.jpg|thumb|The effect of gamma correction on an image: The original image was taken to varying powers, showing that powers larger than one make the shadows darker, while powers smaller than one make dark regions lighter.]]
'''Gamma correction''', '''gamma nonlinearity''', '''gamma encoding''', or often simply '''gamma''', is the name of a nonlinear operation used to code and decode [[luminance (relative)|luminance]] or [[tristimulus value]]s in [[video]] or [[still image]] systems.<ref name=poynton>{{cite book | title = Digital Video and HDTV: Algorithms and Interfaces | author = Charles A. Poynton | publisher = Morgan Kaufmann | year = 2003 | isbn = 1-55860-792-7 | pages = 260, 630 | url = http://books.google.com/books?id=ra1lcAwgvq4C&pg=RA1-PA630&dq=gamma-encoding}}</ref> Gamma correction is, in the simplest cases, defined by the following '''[[Power law|power-law]]''' expression:
:<math>V_{\text{out}} = A {V_{\text{in}}}^{\gamma}</math>
where {{math|''A''}} is a constant and the input and output values are non-negative real values; in the common case of {{math|''A'' {{=}} 1}}, inputs and outputs are typically in the range 0–1. A gamma value {{nowrap|''γ'' < 1}} 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 {{nowrap|''γ'' > 1}} is called a '''decoding gamma''' and the application of the expansive power-law nonlinearity is called '''gamma expansion'''.
== Explanation ==
Gamma encoding of images is required to compensate for properties of human vision - to maximize the use of the bits or bandwidth relative to how humans perceive light and color.<ref name=poynton/> Human vision under common illumination conditions (not pitch black or blindingly bright) follows an approximate gamma or power function. 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/bandwidth to shadow values that humans are sensitive to and would require more bits/bandwidth to maintain the same visual quality.<ref name=poynton/><ref name=FQAGamma>[http://www.poynton.com/notes/color/GammaFQA.html Charles Poynton (2010). Frequently Questioned Answers about Gamma.]</ref> Gamma encoding of [[floating point]] images is not required (and may be counterproductive) because the floating point format already provides a pseudo-logarithmic encoding.
A common misconception is that gamma encoding was developed to compensate for the input–output characteristic of [[cathode ray tube]] (CRT) displays.<ref name=FQAGamma/> In CRT displays the electron-gun current, and thus light intensity, varies nonlinearly with the applied anode voltage. Altering the input signal by gamma compression can cancel this nonlinearity, such that the output picture has the intended luminance. But in fact, 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.<ref name=poynton/><ref name=FQAGamma/> The similarity of CRT physics to the inverse of gamma encoding needed for video transmission was a combination of luck and engineering which simplified the electronics in early television sets.
==Generalized gamma==
The concept of gamma can be applied to any nonlinear relationship. For the [[power-law]] relationship ''V''<sub>out</sub> = ''V''<sub>in</sub><sup>γ</sup>, the curve on a log–log plot is a straight line, with slope everywhere equal to gamma (slope is represented here by the [[derivative]] operator):
:<math>\gamma = \frac{\mathrm{d} \log(V_{\text{out}})}{\mathrm{d} \log(V_{\text{in}})}</math>
That is, gamma can be visualised 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 (strictly speaking, "point gamma"<ref>R.W.G. Hunt, ''The Reproduction of Colour'', 6th Ed, p48</ref>) is defined as the slope of the curve in any particular region.
==In photography==
When a [[photographic film]] is exposed to light, the result of the exposure can be represented on a graph showing log of [[Exposure (photography)|exposure]] on the horizontal axis, and density, or log of transmittance, on the vertical axis. Such curves are known as [[Sensitometry|Hurter–Driffield curves]]. 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 (slide film, reversal film) typically has a gamma greater than 1.
[[Ansel Adams]] describes the gamma concept, but then dismisses it as "a term of interest and significance only to the research scientist and the manufacturer", and elaborates:<ref>{{cite book | title = The Negative | author = Ansel Adams | year = 1968 | publisher = Morgan & Morgan, Inc}}</ref>
<blockquote>"7 minutes at 68°F in Ansco 47 for Isopan" represents "normal" to me. I have no idea what the actual effective gamma is, nor do I care. I could consider this degree of development as yielding Gamma = 1.0 or being Development No. 9 or Operation H, or any other symbol I choose. But why should I inject an unnecessary and confusing symbol for a perfectly simple statement of procedure? "Isopan/Ansco 47/68°F/7minutes" is definite and easily expressed and understood as the means of obtaining ''my'' "normal" negative.</blockquote>
[[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 (dynamic range) that can be captured by typical electronic cameras.<ref>
{{cite book
| title = An introduction to video and audio measurement
| edition = 3rd
| author = Peter Hodges
| publisher = Elsevier
| year = 2004
| isbn = 978-0-240-80621-1
| page = 174
| url = http://books.google.com/books?id=Fmd0lbD32R0C&pg=PA174
}}</ref>
For this reason, considerable artistic effort is invested in choosing in which reduced form 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 (e.g. for storage into JPEG image format), 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 (a [[gamma compression]]) of the intended intensities of the [[primary color]]s of the photographic reproduction; in addition, the intended reproduction is almost always nonlinearly related to the measured scene intensities, via a [[tone reproduction]] nonlinearity.
==Windows, Mac, sRGB and TV/video standard gammas==
[[Image:SRGB gamma.svg|thumb|right|227px|Plot of the [[sRGB]] standard gamma-expansion nonlinearity (red), and its local gamma value, slope in log–log space (blue).]]
In most 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 release of Mac OS X 10.6 (Snow Leopard) in September 2009, were [[Macintosh]] computers: they used 0.55 and 1.8 respectively. In any case, [[binary file|binary]] data in still image files (as [[JPEG]]) are explicitly encoded (that is, they carry gamma-encoded values, not linear intensities), as are motion picture files (such as [[MPEG]]). 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. Below a compressed value of 0.04045 or a linear intensity of 0.00313, the curve is linear (encoded value proportional to intensity), so {{nowrap|1=''γ'' = 1}}. The dashed black curve behind the red curve is a standard {{nowrap|1=''γ'' = 2.2}} power-law curve, for comparison.
Output to CRT-based television receivers and monitors does not usually require further gamma correction, since the standard video signals that are transmitted or stored in image files incorporate gamma compression that provides a pleasant image after the gamma expansion of the CRT (it is not the exact inverse). For television signals, the actual gamma values are defined by the video standards ([[NTSC]], [[PAL]] or [[SECAM]]), and are always fixed and well known values.
==Power law for video display==
A '''gamma characteristic''' is a [[power law|power-law]] relationship that approximates the relationship between the encoded [[Luminance (video)|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<ref name="EbnerCIC61998">Fritz Ebner and Mark D Fairchild, "Development and testing of a color space (IPT) with improved hue uniformity," ''Proceedings of IS&T/SID's Sixth Color Imaging Conference,'' p 8-13 (1998).</ref> used an exponent of 0.43 to convert linear intensity into lightness for neutrals; the reciprocal, approximately 2.33 (quite close to the 2.2 figure cited for a typical display subsystem), would provide optimal perceptual encoding of grays. The following illustration shows the difference between a scale with linearly-increasing encoded luminance signal (linear input) and a scale with linearly-increasing intensity (i.e., gamma-corrected) scale (linear output).
{| style="background: #000000; color: gray; padding: 1em; margin: 0 2em 0 2em;"
| style="color: #A0A0A0;" | Linear encoding
| style="color: #A0A0A0;" | ''V''<sub>''S''</sub> =
| style="background: #000000; color: #FFFFFF;" | 0.0
| style="background: #1A1A1A; color: #FFFFFF;" | 0.1
| style="background: #333333; color: #FFFFFF;" | 0.2
| style="background: #4D4D4D; color: #FFFFFF;" | 0.3
| style="background: #666666; color: #FFFFFF;" | 0.4
| style="background: #808080; color: #FFFFFF;" | 0.5
| style="background: #999999; color: #000000;" | 0.6
| style="background: #B3B3B3; color: #000000;" | 0.7
| style="background: #CCCCCC; color: #000000;" | 0.8
| style="background: #E6E6E6; color: #000000;" | 0.9
| style="background: #FFFFFF; color: #000000;" | 1.0
|-
| style="color: #A0A0A0;" | Linear intensity
| style="color: #A0A0A0;" | ''I'' =
| style="background: #000000; color: #FFFFFF;" | 0.0
| style="background: #5A5A5A; color: #FFFFFF;" | 0.1
| style="background: #7B7B7B; color: #FFFFFF;" | 0.2
| style="background: #949494; color: #000000;" | 0.3
| style="background: #A9A9A9; color: #000000;" | 0.4
| style="background: #BBBBBB; color: #000000;" | 0.5
| style="background: #CBCBCB; color: #000000;" | 0.6
| style="background: #D9D9D9; color: #000000;" | 0.7
| style="background: #E7E7E7; color: #000000;" | 0.8
| style="background: #F4F4F4; color: #000000;" | 0.9
| style="background: #FFFFFF; color: #000000;" | 1.0
|}
On most displays (those with gamma of about 2.2), 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 linearly-encoded scale, which has a nonlinearly-increasing intensity, will show much more even steps in perceived brightness.
A [[cathode ray tube]] (CRT), for example, converts a video signal to light in a nonlinear way, because the electron gun's intensity (brightness) as a function of applied video voltage is nonlinear. The light intensity ''I'' is related to the source [[voltage]] ''V''<sub>''S''</sub> according to
:<math>I \propto V_{\rm S}{}^{\gamma}</math>
where ''γ'' is the [[Greek alphabet|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 table]]s in computers usually adjust the system gamma to the range 1.8 to 2.2,<ref name=poynton/> 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 (representing mid-gray) is fed to the display, the intensity or brightness is about 0.22 (resulting in a dark gray). Pure black (0.0) and pure white (1.0) are the only shades that are unaffected by gamma.
To compensate for this effect, the inverse transfer function ('''gamma correction''') 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:
:<math>V_{\rm C} \propto V_{\rm S}{}^{(1/\gamma)}</math>
where ''V''<sub>C</sub> is the corrected voltage and ''V''<sub>''S''</sub> 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 or 0.45.
A color CRT receives three video signals (red, green and blue) and in general each color has its own value of gamma, denoted ''γ''<sub>''R''</sub>, ''γ''<sub>''G''</sub> or ''γ''<sub>''B''</sub>. 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 ''V''<sub>''S''</sub> 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 {{nowrap|1=''γ'' = 2.5}} behavior. In [[NTSC]] [[television]] recording, {{nowrap|1=''γ'' = 2.2}}.
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 {{nowrap|''x'' + ''K''}} (where ''K'' is a constant) 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.
==Methods to perform display gamma correction in computing==
Up to four elements can be manipulated in order to achieve gamma encoding to correct the image to be shown on a typical 2.2- or 1.8-gamma computer display:
* The pixel's intensity values in a given image file; that is, the binary pixel values are stored in the file in such way that they represent the light intensity via gamma-compressed values instead of a linear encoding. This is done systematically with digital video files (as those in a [[DVD]] movie), in order to minimize the gamma-decoding step while playing, and maximize image quality for the given storage. Similarly, pixel values in standard image file formats are usually gamma-compensated, either for sRGB gamma (or equivalent, an approximation of typical of legacy monitor gammas), or according to some gamma specified by metadata such as an [[ICC profile]]. If the encoding gamma does not match the reproduction system's gamma, further correction may be done, either on display or to create a modified image file with a different profile.
* The rendering software writes gamma-encoded pixel binary values directly to the video memory (when [[highcolor]]/[[truecolor]] modes are used) or in the [[CLUT]] [[hardware register]]s (when [[indexed color]] modes are used) of the [[display adapter]]. They drive [[Digital-to-Analog Converter]]s (DAC) which output the proportional voltages to the display. For example, when using [[List of monochrome and RGB palettes#24-bit RGB|24-bit RGB]] color (8 bits per channel), writing a value of 128 (rounded midpoint of the 0–255 [[byte]] range) in video memory it outputs the proportional {{nowrap|≈ 0.5}} voltage to the display, which it is shown darker due to the monitor behavior. Alternatively, to achieve {{nowrap|≈ 50%}} intensity, a gamma-encoded [[look-up table]] can be applied to write a value near to 187 instead of 128 by the rendering software.
* Modern display adapters have dedicated calibrating CLUTs, which can be loaded once with the appropriate gamma-correction [[look-up table]] in order to modify the encoded signals digitally before the DACs that output voltages to the monitor.<ref>[http://msdn2.microsoft.com/en-us/library/ms536529.aspx ''SetDeviceGammaRamp'', the Win32 API to download arbitrary gamma ramps to display hardware]</ref> Setting up these tables to be correct is called ''hardware calibration''.<ref name=cm>[http://ftp2.bmtmicro.com/dlc/Color%20Management.pdf Jonathan Sachs (2003). Color Management. Digital Light & Color.]</ref>
* Some modern monitors allow to the user to manipulate their gamma behavior (as if it were merely another brightness/contrast-like setting), encoding the input signals by themselves before they are displayed on screen. This is also a ''calibration by hardware'' technique but it is performed on the analog electric signals instead of remapping the digital values, as in the previous cases.
In a correctly calibrated system, each component will have a specified gamma for its input and/or output encodings.<ref name=cm/> Stages may change the gamma to correct for different requirements, and finally the output device will do gamma decoding or correction as needed, to get to a linear intensity domain. All the encoding and correction methods can be arbitrarily superimposed, without mutual knowledge of this fact among the different elements; if done incorrectly, these conversions can lead to highly distorted results, but if done correctly as dictated by standards and conventions will lead to a properly functioning system.
In a typical system, for example from camera through [[JPEG]] file to display, the role of gamma correction will involve several cooperating parts. The camera encodes its rendered image into the JPEG file using one of the standard gamma values such as 2.2, for storage and transmission. The display computer may use a [[color management]] engine to convert to a different color space (such as older Macintosh's {{nowrap|1=''γ'' = 1.8}} color space) before putting pixel values into its video memory. The monitor may do its own gamma correction to match the CRT gamma to that used by the video system. Coordinating the components via standard interfaces with default standard gamma values makes it possible to get such system properly configured.
==Simple monitor tests==
[[Image:Gammatest.svg|left|300 px]]
To see whether one's computer [[Computer display|monitor]] is properly hardware adjusted and can display shadow detail in sRGB images properly, they should see the left half of the circle in the large black square very faintly (or not at all), but the right half should be clearly visible.
If not, one can adjust their monitor's [[Contrast (vision)|contrast]] and/or [[brightness]] setting. This alters the monitor's perceived gamma. The image is best viewed against a black background.
This procedure is not suitable for [[Color calibration|calibrating]] or print-proofing a monitor. It can be useful for making a monitor display sRGB images approximately correctly, on systems in which profiles are not used (for example, the Firefox browser prior to version 3.0 and many others) or in systems that assume untagged source images are in the sRGB colorspace.
On some operating systems running the [[X Window System]] one can change gamma-correction settings, by issuing the command <code>xgamma -gamma 2.1</code> for setting gamma value to 2.1, and <code>xgamma</code> for querying current value. In [[Macintosh]] systems, the gamma and other related screen calibrations are made through the OS control panel. [[Microsoft Windows]] versions before Windows Vista lack a first-party developed calibration tool.
[[Image:srgbnonlinearity.png|right]]
In the test pattern to the right, the linear intensity of each solid bar is the average of the linear intensities in the surrounding striped dither; therefore, ideally, the solid squares and the dithers should appear equally bright in a properly adjusted [[sRGB]] system.
==Terminology==
The term [[luminous emittance|intensity]] refers strictly to the amount of light that is emitted per unit of time and per unit of surface, in units of [[lux]]. Note, however, that in many fields of science this quantity is called [[luminous emittance]], as opposed to [[luminous intensity]], which is a different quantity. These distinctions, however, are largely irrelevant to gamma compression, which is applicable to any sort of normalized linear intensity-like scale.
''Luminance'' can mean several things even within the context of video and imaging:
*[[Luminance]] is the photometric brightness of an object, taking into account the wavelength-dependent sensitivity of the human eye (in units of [[candela|cd]]/m²);
*[[Luminance (video)]] is the encoded video "luma" signal, i.e. similar to the signal voltage ''V''<sub>''S''</sub>.
*[[Luminance (relative)]] is the luminance signal used in a color-space encoding, relative to a white level.
One contrasts "luminance" in the sense of color (no gamma compression) with "luma" in the sense of video (with gamma compression), and denote luminance by ''Y'' and luma by ''Y''′, the prime symbol (′) denoting gamma compression.<ref>Engineering Guideline EG 28, "Annotated Glossary of Essential Terms for Electronic Production," SMPTE, 1993.</ref>
Likewise, ''[[brightness]]'' is sometimes applied to various measures, including light levels, though it more properly applies to a subjective visual attribute.
Gamma correction is a type of [[power law]] function whose exponent is the [[Greek letter]] [[gamma]] (''γ''). It should not be confused with the mathematical [[Gamma function]]. The lower case gamma, ''γ'', is a [[parameter]] of the former; the upper case letter, Γ, is the name of (and symbol used for) the latter (as in Γ(''x'')). To use the word "function" in conjunction with gamma correction, one may avoid confusion by saying "generalized power law function."
Without context, a value labeled gamma might be either the encoding or the decoding value. Caution must be taken to correctly interpreting the value as that to be applied-to-compensate or to be compensated-by-applying its inverse. In common parlance, in many occasions the decoding value (as 2.2) is employed as if it were the encoding value, instead of its inverse (1/2.2 in this case) which is the ''real'' value that must be applied to encode gamma.
==References==
{{reflist}}
==External links==
===General information===
*[http://www.poynton.com/PDFs/Rehabilitation_of_gamma.pdf Rehabilitation of Gamma] by [[Charles Poynton]]
*[http://www.libpng.org/pub/png/spec/1.2/PNG-GammaAppendix.html Gamma tutorial] (from the [[Portable Network Graphics|PNG]] specification)
*[http://www.poynton.com/notes/colour_and_gamma/GammaFAQ.html Frequently Asked Questions about Gamma]
*[http://www.cgsd.com/papers/gamma.html CGSD - Gamma Correction Home Page] by Computer Graphics Systems Development Corporation
*[http://www.lagom.nl/lcd-test/index.php The Lagom LCD monitor test pages]
*[http://www.hdtvtest.co.uk/news/what-is-gamma-20080511108.htm Gamma Control Adjustment for HDTVs]
*[http://artbyplunkett.com/Unreal/gamma.html Gamma for Computer Games]
*[http://union-d.ru/projects/imagetools Batch gamma adjuster for Windows/Linux]
* Stanford University CS 178 [http://graphics.stanford.edu/courses/cs178/applets/gamma.html interactive Flash demo ] about gamma correction.
===Monitor gamma tools===
*[http://www.hex2bit.com/products/product_mcw.asp Monitor Calibration Wizard]
*[http://www.photoscientia.co.uk/Gamma.htm The Gamma adjustment page]
*[http://www.fho-emden.de/~hoffmann/measgamma10022004.pdf Measuring Gamma for Monitors (Gernot Hoffman)]
* [http://www.normankoren.com/makingfineprints1A.html#Monitor_test_pattern Monitor test pattern] for correct gamma correction (by Norman Koren)
*[http://links.twibright.com/calibration.html Links browser Gamma Calibration page]
*[http://www.quickgamma.de/indexen.html QuickGamma]
[[Category:Display technology]]
[[Category:Science of photography]]
[[Category:Power laws]]
[[bn:গামা সংশোধন]]
[[ca:Correcció gamma]]
[[de:Gammakorrektur]]
[[es:Corrección gamma]]
[[fr:Correction gamma]]
[[ko:감마 보정]]
[[it:Correzione di gamma]]
[[nl:Gammacorrectie]]
[[pl:Korekcja gamma]]
[[ru:Гамма-коррекция]]
[[fi:Gammakorjaus]]
[[sv:Gammakurva]]
[[zh:伽瑪校正]]' |