Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
image/color: are the coefficients for grayModel correct? #16251
For now there are coefficients for NTSC, not sRGB.
See sRGB table: http://www.brucelindbloom.com/index.html?WorkingSpaceInfo.html
The formula using to calculate relative luminance (or brightness):
But it is correct in NTSC (1953) color space only. This formula is deprecated and legacy.
Correct formula is:
A lot of work or refactoring is not required. We can simply replace this coefficients.
Note that the NTSC formula is also used by https://github.com/golang/go/blob/master/src/image/color/ycbcr.go#L10 based on the JFIF specification.
Changing the grayModel function to use the sRGB coefficients instead of the NTSC coefficients would break the nice property that, in theory, converting an image.RGBA to an image.YCbCr and then taking only the Y channel is equivalent to converting an image.RGBA directly to an image.Gray. In practice, the two use slightly different formulae (the ycbcr.go one uses a shift instead of a divide), but we could harmonize them.
We could conceivably change the ycbcr.go formulae to do something compatible with the sRGB coefficients, but that has larger knock-on effects, and we are then also disregarding the JFIF spec.
I appreciate that there are arguments for sRGB over NTSC, but I think this is a situation where everything has trade-offs, and there being multiple competing standards, instead of there being a single 'correct' answer. I'm happy with the trade-off that the image/color package makes.
You are of course free to write your own function that takes an image.RGBA and produces an image.Gray based on the sRGB coefficients.
Sorry for the delay in replying.