Skip to content
Filter a picture

Averaging in gamma versus linear light

A JPG does not store light, it stores numbers chosen to suit the eye. Average those numbers and the result is darker than the light they stand for — which is why a blurred string of fairy lights turns into a grey smear.

The short answer

A pixel value of 128 is not half the light of 255; it is about a fifth of it. Photo files are gamma-encoded so that the 256 available steps are spent where the eye notices differences, in the darks. That encoding is perfect for storing a picture and wrong for mixing one: the average of a black pixel and a white pixel ought to be the grey that emits half the light, which is stored as about 188, not 128.

Stripes: half black, half white
Average of the stored numbers: 128
Average of the light: 188
Step back from the screen or squint until the stripes blur: they match the right-hand grey, not the middle one. The two numbers are what this lab’s own blur returns on such stripes, measured in its kernel tests (128 off, 178–188 on, depending on the radius).

Where it shows

Blurs

A blur is an average over a neighbourhood. Averaged in stored numbers, a small bright light next to a dark background loses most of its brightness and spreads into a dull ring; averaged in light, it keeps its energy and spreads into a glow. Bright edges against dark ones also shift: the dark side wins, so the edge looks thinner and the picture slightly darker overall.

Mosaics

A mosaic tile is the average of every pixel under it. A tile holding a few bright highlights on a dark ground comes out a muddy grey in stored numbers, and a lighter, truer tone in light. On busy, contrasty photos the whole mosaic reads brighter with the option on.

What the lab does

With Average in linear light switched on, Blur styles and Mosaic decode each pixel to linear light (the sRGB transfer curve, inverted), weight it by its transparency, average, and encode the result back. The same code runs on the strip, the preview, the full-size file and, for the mosaic, the SVG. With it off, they average the stored numbers, which is what they always did and what most editors do.

Neither is “correct” for every picture. Linear light is physically right and keeps highlights; stored-number averaging is familiar and holds shadows a little deeper. The switch is there so you can see both on your own photo and choose.

Questions

Which effects have the linear-light option?

Blur styles and Mosaic, square or hexagon: the effects whose whole job is to average neighbouring pixels. Both have an “Average in linear light” switch, off by default.

Why is it off by default?

Most photo editors and browsers average the stored numbers, so that is what people expect a blur to look like, and recipes saved before the option existed must look the same as they did. Turn it on when bright details matter.

Does the saved file match the preview with it on?

Yes. The preview, the strip and the export run the same kernel with the same switch, and the SVG export of a mosaic averages its tiles the same way.

Do the colour looks use linear light?

No. A look is a colour mapping applied to each pixel on its own; nothing is averaged between pixels, so the question does not arise.

Back to the lab

Rendered on your computer, not on a server.