Better SRGB to Greyscale Conversion

https://news.ycombinator.com/rss Hits: 1
Summary

A common approach to convert a gamma-corrected sRGB color (R', G', B') to greyscale is to take a weighted sum of its components: Y' = 0.2126 \cdot R' + 0.7152 \cdot G' + 0.0722 \cdot B'. The weights are given in the Rec. 709 HDTV standard and are used to compute what they call a “luminance signal”, a measure of perceived brightness. It’s also subtly wrong. See those tiny prime marks after each symbol? It’s an obscure notation to mean the components are gamma-corrected. So actually, in this case the precise term for Y' is “luma”, not “luminance”. But if we look at the source of the weights in question, it turns out they are meant to be used to map linear RGB to CIEXYZ color space’s Y component, the actual relative luminance. In other words, the standard recommends you compute a gamma-corrected grey value with gamma-corrected RGB inputs using coefficients meant for linear space. Yikes! I’m not familiar with the history of that unfortunate decision, but at least I know how to do greyscale conversion right: First linearize the sRGB gamma-corrected color, compute Y (note the missing prime) with the above weights in linear space, and then map Y back to gamma space to get the final grey value. It’s three steps instead of one but at least in shader programming you get the linearization for free when sampling sRGB textures, so it’s easy to do the right thing. Learning about this debacle naturally got me thinking that it would be interesting to try to fit better coefficients for the gamma-space formula. I didn’t expect there to be much difference so I never got around actually doing it. A couple of weeks later I was idly leafing through a stack of computer graphics books in the local library, as one does, until I was greeted by this page: Source: “Principles of Digital Image Processing: Core Algorithms” by Wilhelm Burger and Mark J. Burge. It says: In this case, the RGB components must first be linearized to obtain the correct luminance values with the above weights. Hey, the...

First seen: 2025-10-19 20:02

Last seen: 2025-10-19 20:02