Bit-Depth & Linear Light
This is an elementary introduction to the concepts of bit-depth and linear light in relation to digital imaging. Both these topics play a factor in digital compositing, color grading, and rendering computer generated images.
An RGB image is comprised of at least 3 separate grayscale image channels (red, green, and blue) that, when combined, make up a colored image. Occasionally a fourth channel is used for transparency (alpha).
Each of the color channels has a bit-depth, which determines how many shades of gray that particular channel can represent.
Probably the most common image format today is JPEG, which uses 8 bits-per-channel (bpc).
In 8 bits-per-channel images, there are only 28 (or 256) possible shades of gray for each RGB color channel. It can also be referred to as a 24-bit image (8 bits x 3 color channels = 24 bits of data for every pixel).
Because of the limited bit-depth, very fine gradients will sometimes exhibit artifacts known as “banding” or “posterization”. This occurs because there just isn’t enough information in 8-bits to properly display the image.
One technique for reducing banding is to add dithering (noise) to the image – which can help break up smooth gradients.
16 bits-per-channel images hold much more data. At a maximum of 65,536 shades of gray (216) in each color channel, banding artifacts are greatly reduced. Again, it can also be called a 48-bit image (16 bits x 3 color channels = 48 bits of data for every pixel).
NOTE: There are more than just 8 and 16 bits-per-channel formats. Other bit-depths include 1-6, 10, 12, 32, etc.
Digital cameras see light in a linear way (their sensitivity to light is directly related to the intensity of the light). If you double the light intensity, the pixel value gets doubled as well. This is also how the computer calculates pixel blending operations.
Linear Gradient (gamma 1.0)
Our eyes work differently, however. We perceive more tones in the shadows and less in the highlights.
To account for this, a gamma curve is applied to the data. The gamma remaps the tones in the image so that it pushes more bits into the shadows. It is more economical as well – instead of wasting resources on imperceptible highlights.
sRGB Gradient (~gamma 2.2)
The main issue with working in an 8 bits-per-channel environment (besides possible banding artifacts) is that the colors do not always blend properly. The gamma has essentially been baked into the RGB values.
A simple experiment is to take two “middle gray” sRGB values (128) and add them together in an 8 bits-per-channel Photoshop document. Since the gamma is not compensated for, the result is incorrect:
The problem is that the 128 value is not “middle gray”, but it’s being treated as if it were (it’s really only about 20% gray). When you take that same image into a 32 bits-per-channel linear workspace, the addition is correctly implemented.
Here is another example of an 8 bits-per-channel image in Photoshop:
Notice the dark line between the colors. Photoshop is trying to blend the colors without adjusting for the gamma.
Switching to a 32 bits-per-channel document moves everything into linear space, and allows the colors to blend correctly.
The take-away from all this is that you should do your compositing, grading, and CGI rendering in a high bit-depth, linear environment. From there, you can always render out an 8-bit file if necessary.
You can learn more about bit-depth and linear light at the following places: