Stepok Image Lab

Home - Help - Background - Linear vs. Gamma

Linear vs. Gamma

Many users know the names '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 the value of 255, but the true answer is around 190, (the exact value depends on the colour space). Strange, isn't it? That is because the 8 bits, 0-255 value, is calculated on a gamma-space, which is not linear. That means the value 255 does not represent a double luminance than the value 128, and the value 32 is not 3/4 less brighter than 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), another 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 values. 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 the figure shows, 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.

Now you can understand, running an operation like 'blurring' in a gamma space based program will bring a 'wrong' result. If you run this 'blurring' test in other softwares, you will find that most of them are running under the gamma space instead of linear. Here the big problem is, any processing done in a gamma colour space, where a 'blending' operation is involved, will lead to a wrong result. 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 proper result of grayscale like linear space does. That means all their image editing functions may be wrong. For any professional photographer, this is not acceptable. 

In the program, gamma space is simulated or optional only when it is doing better jobs, otherwise the linear space is used in all algorithms by 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 format. Compared to a JPEG file, RAW format can keep the original data from the camera sensor, which outputs 12 bits per channel for most sensors.

For an 8 bits file format like JPEG, it contains 256 scales of change. For a long time, photo editing softwares worked in 8 bits gamma space, and it is enough for most of the processing.

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

Based on the above reasons, our program chooses 16 bits per channel, which is in linear space as above mentioned, as its internal image data format where all algorithms run on.

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