Stepok Image Lab

Home - Help - Background - Linear vs. Gamma

Linear vs. Gamma

Many users know the name 'sRGB' and 'aRGB' as the colour space applied on photos. When considering a channel of 8 bits in sRGB (or aRGB), which varies from 0-255, few users know the answer to this question, which value represents the half energy of the white point (255)?

You may say 127 because it is half value of 255, but the true answer is around 190, (the exactly value depends on the colour space). Strange, isn't it? That is because the 8bits, 0-255 value, is calculated on a gamma-space, which is not linear. That means the value 255 is not represent double bright than the value 128, and the value 32 is not 1/4 bright of the value 127…

The gamma curve theory is based on responses of the human eye. The following figure shows the difference between linear and gamma space.

You may have more questions, but in this article, it is not important why or how, but what effect it will bring to the image in the processing results.

Considering an operation that blends 2 pixels together, one is white (255), one is black (0). The result in gamma space is 127 as the middle value of the two inputs. In linear space, we get 1.0 and 0.0 for the inputs as float value. So the result is 0.5. After transforming from linear space to gamma space, we get 189 in sRGB space. The following figure shows the two results.


As in the above figure, when blurring the pattern, which is constructed from white and black pixels, the linear space result is more accurate to the real feeling of the human eye. If you look at the figure from a distance, with a calibrated monitor, you can see the fact clearly. Feel familiar with this? This is the standard way to calibrate the monitor's gamma value.

So you can understand, running an operation like 'blur' in gamma space will bring a 'wrong' result. If you test other software by using this pattern, you can find that most of them are running under gamma space. So, any processing including a 'blending' operation inside may lead to a wrong result if the gamma space value is used. Let's think about another example, the RGB to grayscale processing. The simple formula is:

L = R * 0.3 + G*0.6 + B * 0.1
Where L is the grayscale outputting, R,G, B are the Red, the Green and the Blue channel values. In theory, these R, G, B values represent the real energy power that means it should be calculated in linear space. But, most software does it in gamma space and gets wrong outputting as in the following sample. This is a repeatable and simple experiment that tests any image software and you can do it yourself. And then, you will find most popular software cannot output a good result of grayscale like linear space does. As a professional photographer, this is a serious problem.

In conclusion, you can benefit from linear space for its accuracy in processing where blending is involved. Gamma space still has its advantages too. It brings better results and is easy to understand on traditional functions like 'curve', 'auto level', etc. To achieve the best balance, in the program, gamma space is simulated or optional when running those functions; except when linear space is used in the algorithms in default.

Refer to 'Tone maker'.

Editing in 16bits per channel

Most digital cameras support RAW formats and many photographers have selected RAW as their preference. Compared to a JPEG file, RAW format can keep the original data from the camera sensor, which outputs 12bits per channel normally.

For 8bits format like JPEG, it contains 256 scales of changing. For a long time photo editing software worked in 8bits gamma space like JPEG system does. 8 bits is enough for most of the processing.

With the RAW format becoming popular, 8 bits is not enough to keep all information of the 12 bits inputs. So the software must be upgraded to 16bits (2 bytes) channel to adapt to it. The advantage of 16bits per channel is obvious: It keeps all details and provides more flexibility in editing the photo.

Based on the above reasons, the program chooses 16 bits per channel, which is in linear space, as its internal image formats.

Copyright 2002-2014,Stepok Image Lab, All rights reserved