# RGB nonlinear, what does it mean?

What does it mean and why is it not well suited for describing colors by human?

Is CMYK nonlinear also?

In general, non-linear function would mean that an increase in an input does not produce a proportional increase or decrease in output. Mathematically, any function that relates one value to another that doesn't follow a straight line is non-linear. So x raised to the power y is a non-linear function.

This matters for colors because our brains don't perceive light in a linear fashion. If you double the number of photons reaching the retina, the brain doesn't interpret it as twice as bright. Further, we can better distinguish two dark shades that are separated by a certain difference in intensity than two bright shades that are separated by the same fixed intensity difference.

When encoding light values in a computer, we need to choose how precisely to record them without losing too much quality. If we use too many bits, then our hardware becomes more expensive. If we use too few then the image looks bad. Until the last ~10-15 years or so, it was generally considered too expensive to store more than 8 bits per red, green, and blue channel. The problem is that if you encode the light values linearly (where 2x causes your monitor to produce twice as many photons as 1x does), then images stored with only 8 bits per channel will have very obvious banding in bright areas of continuous color.

But remember above that humans can perceive smaller increments in darker shades than lighter? That means that we can use 8 bits per channel, but not use them linearly. If we instead take each 8-bit color channel value and treat it as a value between 0 and 1, if we raise that value to a power then we have smaller steps in the darker areas than in the lighter. This is called gamma-correction or gamma-encoding. We just have to remember to do the reverse (raise the value to the 1 / x power) when we want to output the values on a display.

So if you're dealing with non-linear RGB, it is probably gamma encoded. sRGB is a popular encoding that uses a power of ~2.2. (In truth, it's a little more complicated than just raising it to a power.) So when someone tells you that RGB is non-linear, that's usually what they are referring to. It is entirely possible to store images in linear RGB, so long as you use more than 8 bits per color channel. There are also formats that use a logarithmic encodings, though they are less common outside of film production.

CMYK is more complicated than RGB. Rather than having only a single thing that is outputting the color (the monitor), with CMYK, you have to deal with the medium you're printing on as well as the inks you are printing with. In a typical scenario, you print onto a white surface (such as a piece of paper). Ideally all visible frequencies of light should be reflected off of the paper and into your eyes or camera. When you add ink, the ink absorbs some frequencies of light and reflects others. (And I believe some passes through the ink, hits the paper and is reflected back as well.) The manner in which an ink reflects light is non-linear. Doubling the amount of ink may not cut in half the number of photons reflected back. So CMYK is also non-linear.

• "In general, non-linear would mean that an increase in a value does not produce a similar increase in perception." That's a very confusing opening line. Perception, IMO, implies human vision, which, as you state, is non-linear. Commented Dec 7, 2017 at 11:07

Although this is an old post, I feel I should add an important correction. The Human Visual System (HVS) is more sensitive to relative differences in darker tones rather than brighter tones.

• How did we all miss that error?! I think I'll see if I can edit the text. Commented Oct 7, 2019 at 7:51