gamma correction

27 篇文章 3 订阅
13 篇文章 1 订阅


Gamma is an important but seldom understood characteristic of virtually all digital imaging systems. It defines the relationship between a pixel's numerical value and its actual luminance. Without gamma, shades captured by digital cameras wouldn't appear as they did to our eyes (on a standard monitor). It's also referred to as gamma correction, gamma encoding or gamma compression, but these all refer to a similar concept. Understanding how gamma works can improve one's exposure technique, in addition to helping one make the most of image editing.


1. Our eyes do not perceive light the way cameras do. With a digital camera, when twice the number of photons hit the sensor, it receives twice the signal (a "linear" relationship). Pretty logical, right? That's not how our eyes work. Instead, we perceive twice the light as being only a fraction brighter — and increasingly so for higher light intensities (a "nonlinear" relationship).

linear vs nonlinear gamma - cameras vs human eyes  
Reference Tone

Perceived as 50% as Bright
by Our Eyes
Detected as 50% as Bright
by the Camera

Refer to the tutorial on the photoshop curves tool if you're having trouble interpreting the graph.
Accuracy of comparison depends on having a well-calibrated monitor set to a display gamma of 2.2.
Actual perception will depend on viewing conditions, and may be affected by other nearby tones.
For extremely dim scenes, such as under starlight, our eyes begin to see linearly like cameras do.

Compared to a camera, we are much more sensitive to changes in dark tones than we are to similar changes in bright tones. There's a biological reason for this peculiarity: it enables our vision to operate over a broader range of luminance. Otherwise the typical range in brightness we encounter outdoors would be too overwhelming.

But how does all of this relate to gamma? In this case, gamma is what translates between our eye's light sensitivity and that of the camera. When a digital image is saved, it's therefore "gamma encoded" — so that twice the value in a file more closely corresponds to what we would perceive as being twice as bright.

Technical Note: Gamma is defined by Vout = Vingamma , where Vout is the output luminance value and Vin is the input/actual luminance value. This formula causes the blue line above to curve. When gamma<1, the line arches upward, whereas the opposite occurs with gamma>1.

2. Gamma encoded images store tones more efficiently. Since gamma encoding redistributes tonal levels closer to how our eyes perceive them, fewer bits are needed to describe a given tonal range. Otherwise, an excess of bits would be devoted to describe the brighter tones (where the camera is relatively more sensitive), and a shortage of bits would be left to describe the darker tones (where the camera is relatively less sensitive):

Original: smooth 8-bit gradient (256 levels)
 Encoded using only 32 levels (5 bits)
linearly encoded gradient
gamma encoded gradient

Note: Above gamma encoded gradient shown using a standard value of 1/2.2
See the tutorial on bit depth for a background on the relationship between levels and bits.

Notice how the linear encoding uses insufficient levels to describe the dark tones — even though this leads to an excess of levels to describe the bright tones. On the other hand, the gamma encoded gradient distributes the tones roughly evenly across the entire range ("perceptually uniform"). This also ensures that subsequent image editing, color andhistograms are all based on natural, perceptually uniform tones.

However, real-world images typically have at least 256 levels (8 bits), which is enough to make tones appear smooth and continuous in a print. If linear encoding were used instead, 8X as many levels (11 bits) would've been required to avoid image posterization.


Despite all of these benefits, gamma encoding adds a layer of complexity to the whole process of recording and displaying images. The next step is where most people get confused, so take this part slowly. A gamma encoded image has to have "gamma correction" applied when it is viewed — which effectively converts it back into light from the original scene. In other words, the purpose of gamma encoding is for recording the image — not for displaying the image. Fortunately this second step (the "display gamma") is automatically performed by your monitor and video card. The following diagram illustrates how all of this fits together:

RAW Camera Image is Saved as a JPEG File   JPEG is Viewed on a Computer Monitor   Net Effect
image file gamma + display gamma = system gamma
1. Image File Gamma   2. Display Gamma   3. System Gamma

1. Depicts an image in the sRGB color space (which encodes using a gamma of approx. 1/2.2).
2. Depicts a display gamma equal to the standard of 2.2

1. Image Gamma. This is applied either by your camera or RAW development software whenever a captured image is converted into a standard JPEG or TIFF file. It redistributes native camera tonal levels into ones which are more perceptually uniform, thereby making the most efficient use of a given bit depth.

2. Display Gamma. This refers to the net influence of your video card and display device, so it may in fact be comprised of several gammas. The main purpose of the display gamma is to compensate for a file's gamma — thereby ensuring that the image isn't unrealistically brightened when displayed on your screen. A higher display gamma results in a darker image with greater contrast.

3. System Gamma. This represents the net effect of all gamma values that have been applied to an image, and is also referred to as the "viewing gamma." For faithful reproduction of a scene, this should ideally be close to a straight line (gamma = 1.0). A straight line ensures that the input (the original scene) is the same as the output (the light displayed on your screen or in a print). However, the system gamma is sometimes set slightly greater than 1.0 in order to improve contrast. This can help compensate for limitations due to the dynamic range of a display device, or due to non-ideal viewing conditions and image flare.


The precise image gamma is usually specified by a color profile that is embedded within the file. Most image files use an encoding gamma of 1/2.2 (such as those using sRGB and Adobe RGB 1998 color), but the big exception is with RAW files, which use a linear gamma. However, RAW image viewers typically show these presuming a standard encoding gamma of 1/2.2, since they would otherwise appear too dark:

linear RAW Linear RAW Image
(image gamma = 1.0)
gamma encoded sRGB image Gamma Encoded Image
(image gamma = 1/2.2)

If no color profile is embedded, then a standard gamma of 1/2.2 is usually assumed. Files without an embedded color profile typically include many PNG and GIF files, in addition to some JPEG images that were created using a "save for the web" setting.

Technical Note on Camera Gamma. Most digital cameras record light linearly, so their gamma is assumed to be 1.0, but near the extreme shadows and highlights this may not hold true. In that case, the file gamma may represent a combination of the encoding gamma and the camera's gamma. However, the camera's gamma is usually negligible by comparison. Camera manufacturers might also apply subtle tonal curves, which can also impact a file's gamma.


This is the gamma that you are controlling when you perform monitor calibration and adjust your contrast setting. Fortunately, the industry has converged on a standard display gamma of 2.2, so one doesn't need to worry about the pros/cons of different values. Older macintosh computers used a display gamma of 1.8, which made non-mac images appear brighter relative to a typical PC, but this is no longer the case.

Recall that the display gamma compensates for the image file's gamma, and that the net result of this compensation is the system/overall gamma. For a standard gamma encoded image file (), changing the display gamma () will therefore have the following overall impact () on an image:

gamma curves chart with a display gamma of 1.0 
Display Gamma 1.0  Gamma 1.0
gamma curves chart with a display gamma of 1.8 
Display Gamma 1.8  Gamma 1.8
gamma curves chart with a display gamma of 2.2 
Display Gamma 2.2  Gamma 2.2
gamma curves chart with a display gamma of 4.0 
Display Gamma 4.0  Gamma 4.0

Diagrams assume that your display has been calibrated to a standard gamma of 2.2.
Recall from before that the image file gamma () plus the display gamma () equals the overall system gamma (). Also note how higher gamma values cause the red curve to bend downward.

If you're having trouble following the above charts, don't despair! It's a good idea to first have an understanding of how tonal curves impact image brightness and contrast. Otherwise you can just look at the portrait images for a qualitative understanding.

How to interpret the charts. The first picture (far left) gets brightened substantially because the image gamma () is uncorrected by the display gamma (), resulting in an overall system gamma () that curves upward. In the second picture, the display gamma doesn't fully correct for the image file gamma, resulting in an overall system gamma that still curves upward a little (and therefore still brightens the image slightly). In the third picture, the display gamma exactly corrects the image gamma, resulting in an overall linear system gamma. Finally, in the fourth picture the display gamma over-compensates for the image gamma, resulting in an overall system gamma that curves downward (thereby darkening the image).

The overall display gamma is actually comprised of (i) the native monitor/LCD gamma and (ii) any gamma corrections applied within the display itself or by the video card. However, the effect of each is highly dependent on the type of display device.

CRT Monitor   LCD Monitor
CRT Monitors LCD (Flat Panel) Monitors

CRT Monitors. Due to an odd bit of engineering luck, the native gamma of a CRT is 2.5 — almost the inverse of our eyes. Values from a gamma-encoded file could therefore be sent straight to the screen and they would automatically be corrected and appear nearly OK. However, a small gamma correction of ~1/1.1 needs to be applied to achieve an overall display gamma of 2.2. This is usually already set by the manufacturer's default settings, but can also be set during monitor calibration.

LCD Monitors. LCD monitors weren't so fortunate; ensuring an overall display gamma of 2.2 often requires substantial corrections, and they are also much less consistent than CRT's. LCDs therefore require something called a look-up table (LUT) in order to ensure that input values are depicted using the intended display gamma (amongst other things). See the tutorial on monitor calibration: look-up tables for more on this topic.

Technical Note: The display gamma can be a little confusing because this term is often used interchangeably with gamma correction, since it corrects for the file gamma. However, the values given for each are not always equivalent. Gamma correction is sometimes specified in terms of the encoding gamma that it aims to compensate for — not the actual gamma that is applied. For example, the actual gamma applied with a "gamma correction of 1.5" is often equal to 1/1.5, since a gamma of 1/1.5 cancels a gamma of 1.5 (1.5 * 1/1.5 = 1.0). A higher gamma correction value might therefore brighten the image (the opposite of a higher display gamma).


Other important points and clarifications are listed below.

  • Dynamic Range. In addition to ensuring the efficient use of image data, gamma encoding also actually increases the recordable dynamic range for a given bit depth. Gamma can sometimes also help a display/printer manage its limited dynamic range (compared to the original scene) by improving image contrast.
  • Gamma Correction. The term "gamma correction" is really just a catch-all phrase for when gamma is applied to offset some other earlier gamma. One should therefore probably avoid using this term if the specific gamma type can be referred to instead.
  • Gamma Compression & Expansion. These terms refer to situations where the gamma being applied is less than or greater than one, respectively. A file gamma could therefore be considered gamma compression, whereas a display gamma could be considered gamma expansion.
  • Applicability. Strictly speaking, gamma refers to a tonal curve which follows a simple power law (where Vout = Vingamma), but it's often used to describe other tonal curves. For example, the sRGB color space is actually linear at very low luminosity, but then follows a curve at higher luminosity values. Neither the curve nor the linear region follow a standard gamma power law, but the overall gamma is approximated as 2.2.
  • Is Gamma Required? No, linear gamma (RAW) images would still appear as our eyes saw them — but only if these images were shown on a linear gamma display. However, this would negate gamma's ability to efficiently record tonal levels.

For more on this topic, also visit the following tutorials:

Gamma 校正


图1 CRT显示器的亮度响应曲线图



图2 按图进行曲线补偿


图3 理想状态下的曲线




γ校正(Gamma Correction,伽玛校正):所 谓伽玛校正就是对图像的伽玛曲线进行编辑,以对图像进行非线性色调编辑的方法,检出图像信号中的深色部分和浅色部分,并使两者比例增大,从而提高图像对比 度效果。计算机绘图领域惯以此屏幕输出电压与对应亮度的转换关系曲线,称为伽玛曲线(Gamma Curve)。以传统CRT(Cathode Ray Tube)屏幕的特性而言,该曲线通常是一个乘幂函数,Y=(X+e)γ,其中,Y为亮度、X为输出电压、e为补偿系数、乘幂值(γ)为伽玛值,改变乘幂 值(γ)的大小,就能改变CRT的伽玛曲线。典型的Gamma值是0.45,它会使CRT的影像亮度呈现线性。使用CRT的电视机等显示器屏幕,由于对于 输入信号的发光灰度,不是线性函数,而是指数函数,因此必需校正。

在电视和图形监视器中,显像管发生的电子束及其生成的图像亮度并不是随显像管的输入电压线性变化,电子流与输入电压相比是按照指数曲线变化的,输入 电压的指数要大于电子束的指数。这说明暗区的信号要比实际情况更暗,而亮区要比实际情况更高。所以,要重现摄像机拍摄的画面,电视和监视器必须进行伽玛补 偿。这种伽玛校正也可以由摄像机完成。我们对整个电视系统进行伽玛补偿的目的,是使摄像机根据入射光亮度与显像管的亮度对称而产生的输出信号,所以应对图 像信号引入一个相反的非线性失真,即与电视系统的伽玛曲线对应的摄像机伽玛曲线,它的值应为1/γ,我们称为摄像机的伽玛值。电视系统的伽玛值约为 2.2,所以电视系统的摄像机非线性补偿伽玛值为0.45。彩色显像管的伽玛值为2.8,它的图像信号校正指数应为1/2.8=0.35,但由于显像管内 外杂散光的影响,重现图像的对比度和饱和度均有所降低,所以现在的彩色摄像机的伽玛值仍多采用0.45。在实际应用中,我们可以根据实际情况在一定范围内 调整伽玛值,以获得最佳效果。




γ校正的原理是修改显示系统的配色方案,本来显示系统输出的r g b电子枪线性的根据显存中的各个颜色值输出对应的控制电压,但是通过伽码校正可以把某个颜色值对应的输出电压调整高或调整低。达到校正显示系统色泽的目的。







2 gamma概念的演化
2.1 gamma概念的第一演化(系统gamma和显示器gamma)




2.2 gamma概念的第二次演化
显示器gamma表示一种失真,系统gamma表示一种校正,这两者共同之处是都表示对原始信号的一种变换,所以gamma概念发展到这里,其一般性含义已经又两层含义,a表示对原始信号的一种变换, b表示这种变换的度量参数。
2.3 gamma概念的第三次演化(文件gamma)
这要从人的视觉原理说起。人的眼睛感觉到亮度增加一级的时候,光强(光的能量)将增加一倍,同样,当人的眼睛感觉到亮度减小一级的时候,光强将减少一半。就是说,人的眼睛感觉到的亮度的成比例的线性变化,是由光强的倍数变化引起的。如果将一段连续变化的亮度从暗到亮等差分成a b c d e f g 七段,那么这七段亮度对应的光强不是1 2 3 4 5 6 7,而是1 2 4 8 16 32 64。打个数学比方,人眼感觉到的亮度是等差数列,而光强的物理实在是等比数列!为何如此,因为这样可以确保人眼即适应高亮度的阳光下的景物,又能在夜晚看清星光下的猎物,这是大自然的造化。
2.4 gamma概念的第四次演化
c 在不同的上下文环境中,会特指显示器gamma,系统gamma,文件gamma三个概念中的某个具体概念,注意领会。
2.5 概念总结(四种gamma)
2.5.1 gamma
2.5.2 显示器gamma
2.5.3 文件gamma
对一个给定的数码相片文件,按照相关标准规范, 这个gamma是一个定值,所以无需对其校正。如果出于某种特殊需要,一定要改变某数码相片文件的gamma值,这种改变也不能称作“校正”,而是称作“变换”。
2.5.4 系统gamma


还有篇文章不错,要看的话搜索 Gamma校正的快速算法及其C语言实现



以r来说 先归一化,转到[0,1]

temp = (r+0.5)/256

预补偿公式temp  = temp ^(1/gamma)  其中gamma一般是2.2


r = temp*256 – 0.5










public static Bitmap SetGramma(Bitmap b, double gramma)
    int maxGray=0;
    ColorDelegate grayMaxDelegate = (ref int red, ref int green, ref int blue) =>
        int gray = (int)(red * 0.299 + green * 0.587 + blue * 0.114);
        if (gray > maxGray)
            maxGray = gray;

    LoopPixel(b, grayMaxDelegate);

    double maxLight = maxGray;
    double g = 1/gramma;
    ColorDelegate colorDelegate = (ref int red, ref int green, ref int blue) =>
        red = (int)((maxLight * Math.Pow(red / maxLight, g)) + 0.5);
        green = (int)((maxLight * Math.Pow(green / maxLight, g)) + 0.5);
        blue = (int)((maxLight * Math.Pow(blue / maxLight, g)) + 0.5);

    return LoopPixel(b, colorDelegate);

  • 0
  • 1
    觉得还不错? 一键收藏
  • 0


  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助




当前余额3.43前往充值 >
领取后你会自动成为博主和红包主的粉丝 规则
钱包余额 0