What is log gamma? We use log gamma profiles to record an expanded dynamic range within a limited file bit depth. It’s a clever cheat really.
However, it’s more than just recording a flat image. It’s important to understand what gamma is, and why log gamma profiles give us more image information where we need it. It starts with understanding how you are acquiring your image.
I’ve written before about Demystifying Color Bit Depth and Dynamic Range but here’s a few more notes on light, and log vs linear gamma encoding. It is one of the most important things you can understand in digital cinema acquisition and post, and it can be confusing for the uninitiated.
Light is Linear
If you double the energy emitted from a light source, and the distance from that light source stays constant, the light intensity at that point will also double. Easy right?
The Inverse Square Rule
Imagine a single light source in a massive dark room. Standing right next to the light, you’ll experience the highest light intensity possible. Moving to the far end of the room, you’ll experience the least intensity in the room, because the light intensity diminishes over distance.
However, it doesn’t diminish linearly as distance increases. If you stand half way between the light source and the far end of the room, the light won’t be half as bright; it will actually be approximately a quarter as intense. The light intensity is inversely proportional to the square of the distance from the light source.
In photography and cinematography brightness or light intensity is measured in stops. A stop is a unit used to quantify ratios of light, or exposure. Each added stop represents a doubling of light intensity, or exposure. A decrease of one stop is a halving of light intensity or exposure.
The f-stop scale is an approximately geometric sequence of numbers that corresponds to the sequence of the powers of the square root of 2: f/1, f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, f/11, f/16, f/22, f/32, f/45, f/64, f/90, f/128, etc.
You don’t need to understand the math, just what it means. So f/2 represents double the light intensity of f/2.8 but half the the light intensity of f/1.4.
Human Perception is Not Linear
Our perception of luminance is not linear, and that is important when it comes to how we map real world linear luminance values to perceived brightness. We are more sensitive to small changes in luminance at the low end of the scale than the high end.
The Gamma Curve – Linear vs Log
By encoding luminance non-linearly we can assign a higher number of digital values to the low and mid end of the brightness scale, and fewer values to the highlights.
I found the below descriptions from RyanJuckett.com very useful, he’s speaking in the context of color science as it relates to computer graphics and coding for games but it is a good explanation of the gamma curve nonetheless.
The gamma correction curve is used to convert pixel luminance from a linear scale to an exponential scale. When encoding the final pixel value, the curve is used to gamma compress linear luminance to a gamma corrected value. When decoding a pixel value, the inverse curve is used to gamma expand the value back to linear units.
We don’t perceive the luminance of a color on a linear scale, so this gamma compression actually helps us store more useful information in a limited number of bits per pixel. This nonlinear relationship between linear luminance and the perceived brightness of a color (also known as lightness) is shown below.
If we were to store image values on a linear scale, single steps in value would correspond to large steps in lightness on the lower end of the scale and minor steps in lightness at the higher end of the scale. As a result, we would lose a lot of lightness fidelity in dark colors.
Now let’s look at luminance using the sRGB gamma corrected curve.
We now get consistent steps of lightness across all values letting us encode lightness with more fidelity across the entire scale. While this image does show linear lightness (human perception), it should be stressed that we are no longer working with linear luminance (physics).
To go through this one more time, lets use 10 bit values as an example; you have 1024 possible values (including 0) to map input luminosity levels to output values from black to white. So your output range is between 0 (black) and 1023 (white).
A normal idealised gamma curve is actually almost a straight line, and this linear mapping will divide values perfectly evenly between 0 and 1023 across the scale of linear luminance.
If you have a maximum 1024 possible values to map to luminosity levels, it is a waste of valuable data to spread them perfectly evenly because our perception is not linear, we are more sensitive to changes in the shadows and mid-tones than in highlights.
An approximately logarithmic gamma curve serves to better assign data values according to our perception of brightness, giving us the information we need in the shadows and midtones while sufficiently capturing the expanded highlight information from high dynamic range imaging sensors.
This is why a log image viewed without gamma correction will look very flat and washed out.
In the context of the Blackmagic cameras for instance “Film” and “Video” modes, simply put, “Video” mode applies a more linear gamma curve to the image and “Film” mode applies a logarithmic gamma curve preserving the shadows and midtones and expanding the highlights.
Above, a more linear gamma curve. Video mode.
I highly recommend reading Understanding Gamma, CineGamma, HyperGamma and S-Log by Alistair Chapman on dvinfo.net
Sign Up today for free and be the first to get notified on new digital cinema technology and filmmaking updates from Digital Cinema Demystified.
Follow Digital Cinema Demystified on Facebook to make sure you see future articles and posts directly in your news feed.
Subscribe to learn: technology, technique, creative digital cinema camera and lens tests, color grading tutorials, and much more.