6

I want to analyze the color distribution and statistics of my pictures in GIMP. There are two spaces to view the colors, the 'linear space' and 'perceptual space'. What is the precise definition of the two spaces?

For example, when viewing the histogram of the picture, one can select the spaces as below:

The linear space:

enter image description here

The perceptual space:

enter image description here

Furthermore, I notice the 'Mean' value of the histogram differs when viewed under the linear and perceptual spaces. Why is that and how the mean value is calculated in these two spaces?

3 Answers 3

6

The math facts are already written in plain English language in older answers. But the histogram is not the only place where you will meet linear vs. perceptual or as well non-gamma corrected vs. gamma corrected.

The confrontation occurs when you start a new image. To keep beginners less confused the advanced options are fortunately hidden and GIMP offers by default the usual gamma corrected (=perceptual) version of sRGB color space - this one:

enter image description here

It can be considered as an attempt to make brightness (=value) numbers 0...255 correspond the perceived brightnesses. The concept was a huge challenge 75...80 years ago when electronics industry tried to construct mass produceable televisions with a million times simpler circuits than available today. It arose another time to a big challenge when graphics started to creep into computers. The price of the technology in 1970's forced to find ways to make 8 bits enough to cover the full range of brightnesses between black and white. The current gamma correction is a legacy from 1970's.

If you draw a linear gradient from black to white you have again a possibility to select linear vs. perceptual. I have selected perceptual. GIMP attempts to draw visually as linear looking gradient as it can:

enter image description here

Perceptual histogram shows that GIMP claims it has succeeded:

enter image description here

If we switch to linear histogram we see something only imagined:

enter image description here

It can be interpreted as "If we had a linear gamma color space we would get the shown gradient by having this brightness number distribution".

We can try it. Let's start a new image with linear gamma version of sRGB:

enter image description here

The visually quite smooth gradient can still be drawn if one wants perceptual blending. But the linear histogram shows now the distribution of the actual written brightness values:

enter image description here

The previous imagined histogram resembles it. A perceptual histogram is sparse because 8 bits really is quite a low number. This is a poor approximation of unformly distributed brightnesses:

enter image description here

It's sparse near black.

If we make a linear gradient in linear color space and ask the gradient tool to allow it look visually non-linear we get this:

enter image description here

The linear histogram is, of course, uniform but the brightness grows accelerating towards white.

But is the linear gamma color space ever needed?

It is needed in special cases. Color mixing caused by transparency, blurring or blending modes creates easily unexpected results if the mix is calculated with the numbers of the normal 8 bit sRGB color space. One can get unwanted borders in areas which should look uniform or have a smooth gradient. See these examples:

How to get rid of weird black borders in Krita?

Why does using additive blending with a linear colour dropoff result in dark fringes?

They can be avoided in linear color space or by letting at least color mixes to be calculated in a linear color space. Those things must be selected in program preferences, new job color settings or program's general color settings - it's different in different programs. Fortunately the programmers of GIMP seem to have done great job by offering as defaults modes which do not generate weird color mixing results.

Linear color space gives easily coarse results if one has only 8 bit brightness values. Fortunately programs have today 16 bit color depth available and the programs still run smoothly.

3

Human vision is not linear, like most of our senses. Meaning that 2 times the light received by your eye does not get interpreted as 2 times as bright. Your monitor and your image files are encoded in a semi logarithmic space in order to have data where it counts most.* (8 bits of color would be really insufficient without this).

In essence this means that as far as image data is concerned:

Intensity of 1 + intensity of 1 ≠ intensity of 2

Which is admittedly incomprehensible for a lot of people who hasn't had some pretty high level of math thrusted on them.

This button simply toggles between the nonlinear image data numbers and what intensities they would represent. Simply because its useful to be able to reason in a space where 1+1=2. There are a lot of computations and problems that are easier to think in linear spaces.

Mean obviously changes because the distribution and meaning of the value changes. If you don't actually do computation on images, or some physics stuff. Its probably irrelevant for you at this point, you might need it somewhere down the line though. Its useful for camera correct blurring, physically accurate color mixing etc. I do need this, but not very often. A full time graphics programmer might need it weekly.

* unfortunately, the image/monitor space is not necessarily equal to the non linearity of human vision. Just closer, so you can not use it to measure visually double either.

1

One is gamma-corrected (perceptual) and one is not (linear).

The mean value is of course the mean value of the values as displayed in the histogram.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.