NX101.com - A course in Nikon Digital Photography
 You are here: NX101.com » Understanding Color and Gamma   Donate Feedback  
Index Understanding Color and Gamma

Q: When you open a NEF in Capture NX, you are seeing the RGB values recorded by the camera sensor, right? Actually, no, you are not. First there is white balance correction, but most importantly the RGB color space is a gamma-corrected color space.

Bayer Filter
How color is recorded by your camera: The sensor in your digital camera is a photon (or light) detector. It can not directly see color. Instead, it uses Red, Green, and Blue color filters over the entire sensor (usually in a Bayer filter configuration). When twice the amount of light hits the sensor, twice the value is recorded. When half the amount of light hits the sensor, half the value is recorded. This means that sensor inside your camera has a linear response to light intensity.

How color is displayed on a CRT: No matter if you hook up a CRT display or a LCD monitor to your computer, you expect see the same colors, right? Well, 'the problem' is that the electron-gun used in a CRT used to display colors is a non-linear device. This non-linear curve can be described by a 'gamma curve'. Learn more about gamma correction at Wiki. If you try to display linearly recorded color on a non-linear output device like a CRT, you will not get linear output, and the result instead will be much a much darker color than intended.

Why non-linear? Go all the way back to the creation of TV and the CRT (Cathode Ray Tube). The CRT is a non-linear display. How would you fix the problem that CRT's display in a non-linear manner? Would you add gamma correction into every TV produced, driving up the cost for all TVs? Or would you have TV broadcaster's gamma encode their TV signal, driving up the cost for a few broadcasters? The most cost effective solution prevailed -- have TV broadcaster's implement the fix (gamma encoder). The gamma decoder is then present in every TV as the physical gamma behavior of the electron gun in the CRT. And for compatibility, this legacy remains in how LCD monitors display color.

TV Gamma Encoding: A TV signal is recorded by the video camera (linear color). If transmitted as-is to TV sets, the gamma behavior of each TV would result in a picture way too dark. So, the video camera signal is gamma encoded, broadcast over the airwaves, displayed by a TV/CRT, which physically performs gamma decoding (a byproduct of how the electron gun in a CRT works), and outputs the signal, effectively reproducing the original linear video camera signal.

PC Display Output is Gamma 2.2: Displays for PC's (sRGB color space) have standardized on the same gamma used by the TV (NTSC) industry, a gamma of 2.2. This means that the internal RGB color space (RGB 0..255 values) is a gamma encoded color space, not a linear color space. Here is a series of linear RGB values vs gamma encoded linear values and you can clearly the differences:
Linear vs Gamma 2.2 encoded (corrected) signals
Video signal/voltage (0-1) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
Linear encoding¹ (0-255) 0 26 51 77 102 128 153 179 204 230 255
Gamma encoded² (0-255) 0 90 123 148 169 187 203 217 231 244 255
¹Displays output too dark (non-linear intensity) due to 'automatic' CRT gamma decoding
²Displays output correctly (linear intensity) due to CRT gamma decoding
For 'Linear Enoding' (linear on RGB scale), the output (gamma decoded) is too dark. To compensate, if the linear RGB data is gamma encoded, the result is that the output (gamma decoded) turns into a linear scale.

This PC gamma works incredibly well most of the time. Consider JPEG's, which also are already gamma (2.2) encoded. To use, just uncompress to obtain the RGB pixels, perform no other processing, and display. The end result is that the gamma encoded pixel values are output on a PC display, which has a gamma 2.2 output, resulting in you seeing the original linear color photo.

Implications for digital cameras: Any digital camera that produces JPEG's will produce RGB pixel values that are gamma encoded (not linear). So viewing on any PC display will result in the original linear color information. The RAW files produced by a digital camera will be in a proprietary format, likely still in linear form.

Implications for Capture NX: So when NX opens a NEF (linear color) it is applying gamma correction, which results in the (non-linear) RGB values that you see, which when displayed on a CRT or LCD, are displayed via a gamma curve, resulting in you seeing the original colors (linear).
NX uses a gamma encoded color space, but yet Capture NX fails gamma aware tests
The Implications for YOU: Hopefully a much better understanding of color. So that when you see a RGB value of 128, you don't think it is at 50% output intensity. Instead, you know that '128' is really an output of around 22% output intensity. To obtain 50% output intensity requires a RGB value of around '187'.

Interactive sRGB Gamma Calculator: To help you understand gamma encoding and decoding, play around with the following interactive sRGB gamma calculator (sRGB Color Space Information). Just enter a value (0-255) into any of the following three edit boxes, then exit (press TAB, or click the mouse outside the edit box):
sRGB Gamma Calculator
Digital camera sensor linear value:(0-255)
RGB value, gamma encoded (non-linear):(0-255)
Value seen on CRT (gamma decoded):(0-255)
sRGB Gamma Encoding Curve: The sRGB color space has a more complex gamma encoding curve, which is very close to the 2.2 gamma curve, but changes the lower (black end) of the encoding curve.

Nikon's Gamma+Tone Encoding Curve: And to complicate things even more, camera vendors appear to be using a custom (proprietary) Gamma+Tone encoding curve. Here is the curve that approximates what Nikon uses (D300):

Help support this site - Make a Donation If NX101.com helps you, help this site by making a donation.

Copyright © 2017 Jerry Jongerius