Gamma Bears or the Tale of Stolen Irises

This story is written for artists (further reading is restricted for physicians) to sort out some cases when we should really care about image gamma.
Here you'll find short simplified explanation of how the gamma works in practice, without excessive theory.

Unlike in the traditional art, in video systems gamma value means the exponent of the power function.
So when you perform the gamma operation, each pixel's color values are raised to the power of gamma.
It's crucial to know that here we mean normalized color values, where black is 0 and white is 1. If an application considers the black to white range as 0 to 255, like in 8 bit times, it will first normalize the values and then perform gamma, after which the original 0 to 255 range will be restored.
This happens in Adobe Photoshop and some other outdated software.

Why gamma? Where does it come from?
Once upon a time, when LCD monitors didn't exist and mice were futuristic devices with a ball inside, people of the world suddenly discovered that brightness produced by CRT-displays wasn't linearly proportional to the quantity of electrons sent to it's phosphor-coated fluorescent screen.
So the picture looked darker and it was darkened non-linearly. To fight the darkness, they started to color-correct the image before it's sent to the screens. The darker screens and brighter images reached a dialectic balance and people could get beautiful colors happily ever after.

It turned out that the law of this correction was similar to the mathematical power function, whose graph is a parabola.

If you define the darkest color which can be reproduced by a display (it's black) as 0 and the brightest color (it's white) as 1, then the gamma value is the exponent to the power of which the intermediate color values are raised with the correction.
For example, if gamma = 2, then 02 = 0, 0.52 = 0.25, 12 = 1, 22 = 4
0 (black) and 1 (white) are never changed by gamma-correction, while midtones (between 0 and 1) get dimmer with gamma > 1 and brighter with gamma < 1.
Then sRGB standard was established for digital pictures. It compensated non-liner darkening of the image on screens using gamma. So, monitors darken picture with gamma about 2.2 and sRGB pictures are lightened with gamma 0.45(45) that is 1/2.2 to look linear on CRT displays.

Computer software operate by inverted gamma (gamma-correction) instead of gamma, so, when you want to make midtones lighter, you can intuitively increase the Gamma parameter and get result you expect.

Consequentially, if you set Gamma = 2 in Fusion, you get not power of two, but square root.

Inverted Gamma is 1 / Gamma, so when you set the Gamma parameter in Brightness / Contrast = 3, you actually, get the cubic root of your color and when you set the Gamma = 0.333(3) that is 1/3, you actually raise your color to the power of 3.

If you are interested by values below 0 (super blacks, negative colors, black holes) in most cases gamma isn't defined below zero, but for your convenience, Fusion applies reflected parabola to that range

So −12 = −1, −13 = −1, −0.52 = −0.25, −0.53 = −0.125

It's not perfectly correct in sense of traditional mathematics, but this math we can use for correct image processing.

Gamma 2.2 in Fusion is near to quadratic parabola that we remember from school, fallen on it's side.

-So where is the promised practice? Is it another lesson of mathematics from middle school?!
-Well, now we can continue with practice, 'cause you've got the power!

You might hear that gamma of monitors is almost equal to inverted gamma of our visual perception, so they compensate each other an all is OK.

Here is some mess.

To be honest, human's retina has really non-linear response. We see more details in shadows and less details in highlights. It is great for us because we see the most we can on the ground, between trees and in bushes when we hunt or gather mushrooms and apples and in the same time, the sky that is actually much brighter, doesn't blind us and don't harm our eyes.

So, in our perception, the sky is a little brighter than bushes and trees while it is much brighter actually.

Many of contemporary humans and most of ones, who read this article so far, notice that you can easily see different shades on buildings, trees and ground in the street as well as different shades of clouds, bright LED-displays, lamps and so on... But when we see all that things reflected in a car surface, in glass, or in wet asphalt, the picture is completely different! Clouds become more contrasty, bright lamps and LED-displays are almost the same, while the ground, buildings, trees and even people are almost black!

The reason for that is: reflected picture is dimmed linearly (multiplied with reflectivity of the surface) while our perception is still non-linear.

The graph of our retina's response is much closer to logarithmic than to graph of the power function though we can use gamma to simplify work flow and speed-up calculations.

Anyway, there is not much relation between the monitor gamma and our non-linear sight.

But it's handy to use gamma instead of the logarithm because its behavior is suddenly close to logarithmic and it's easier to implement using our usual tools.

You can guess that the result of math operations applied to linear values and then raised to the power of gamma differs from the result of the same operations applied to pre-gamma corrected values.

In other words,

(0.5 ∗ 0.4)0.45 is not equal to 0.50.45 ∗ 0.4

as well as

0.50.45 + 0.40.45 is not equal to (0.5 + 0.4)0.45

So, when you apply gamma after applying blurs and merges, areas of confusion are brighter than if you blur and merge two gamma-corrected images.

Not everyone knows and understands the formulas, but everybody sees the difference between real-world phenomena and CG reproduction

graph with two gamma-curves and graph with two lines and gamma

So, we need digital pictures to be gamma-corrected to look linear on our monitors but when we apply real-world (linear) math to them the result differs from real-world result.

It can be particularly seen on defocus and motion blur phenomena real defocus-sRGB-defocus-Linear def-linear to sRGB

When you apply defocus to already gamma-corrected image you get a kind of box-blur, but when you apply defocus to a true-linear picture and then gamma correct it, you get result similar to real. As real-world is linear and all the real phenomena algorithms are linear but we see them, let's say gamma-corrected.

That effect can be also observed when you merge a masked actor over bright background. Soft edges of the foreground layer in motion blurred or defocused areas are shrinked in the areas where background is bright. If you merge two gamma-corrected images, you need to make some tricks to achieve that. But if your images are linear (relative to measured real luminance) and you apply gamma-correction after merge operation, the Merge reproduce that itself.

You can correctly apply linear algorithms in different ways:

If you import TGA sequences, you can place the Gamut tool right after loaders and set the Source Space to sRGB, check the Remove Gamma

  • Loaders should be set to 32 bit float mode.
  • A Gamut must be placed before the Saver as well. Set the Output Space to sRGB, check the Add Gamma.
  • Intermediate results can be previewed using an additional Gamut node. For your convenience you can save a .setting file from it to the Fusion:\LUTs folder and then select it from Display LUT menu Screenshot with simple composition menu and Gamut_sRGB item.

Similar results can be achieved if you replace the Gamut with the BrightnessContrast. In that case the BrightnessContrast after loaders must have Gamma = 1/2.2 and the BrightnessContrast before the saver must have Gamma = 2.2. It will be less accurate but more simple. For previewing intermediate results you can use Fusion View LUT. Select Edit, set Gamma = 2.2 Screenshot with LUT setup dialog

If you work with DPX, just use format settings by default. Check if color depth of the loader is 32 bit float. If not, select it in the Import tab.

This method has some disadvantages. For example, the ColorCorrector gives unexpected results because it's math is applied to linear image and results are viewed using gamma-correction.

When you increase the Contrast, you expect that the gray point remains intact, while black and white points are adjusted equally to the opposite directions, but actually what you get is that highlights and midtones barely change, while shadows are adjusted immensely. This happens, because, ((Color − 0.5) ∗ (Contrast + 1) + 0.5)2.2 is not the same as (Color2.2 − 0.5) ∗ (Contrast + 1) + 0.5

When you adjust the Brightness, you can see that shadows are influenced much more too because Color2.2 + Brightness is not equal to (Color + Brightness)2.2

Similar things happen to Gain and Levels. And by the way, the Histogram in the ColorCorrector doesn't represent the image you see on the screen. It rather shows the values of the image before gamma compensation

Another way is to decrease gamma in the BrightnessContrast tool right before the important operations like Merge, Defocus and DirectionalBlur and restore it with the BrightnessContrast after.

As you can see, there is no need for the artificial and ugly bloom effect. In the macro it's set to 0. Fusion Defocus tool works correctly by itself in the Lens mode being applied to a true-linear image.

The main idea of this article is: all the linear CG algorithms should be applied to image with decreased gamma and viewed with the gamma restored back.

If gamma is increased after effects are applied, the picture gets natural look.

Explanation of some Fusion therms, you might need for your experiments with gamma

Gain is an operation of multiplication: New Color = Color ∗ Gain

Inverted Gain = 1 / Gain

Brightness adds a constant value to your color: New Color = Color + Brightness

Inverted Brightness = −Brightness

P.S. Don't forget to set correct neutral white and black points before compositing to not suffer from wrong operations order (further explatation).

If you think two plus two multiplied by two equals eight, just believe everything above is true. If you think it equals six, you know what I mean.

© Gregory Chalenko 15.02.2008
Special thanks to Dmitry Slepichev and Roman Fedotov for help in math and usage of gnuplot.