How should negative RGB values be handled when converting CIE XYZ to sRGB?
Asked 9/3/2015
17 views
2 answers
0
When converting a normalized CIE XYZ tristimulus value to sRGB, I can end up with a negative linear RGB component. For example, starting from XYZ = (0.2, 0.7, 0.1), the standard XYZ-to-sRGB matrix gives a negative linear red value. After applying the sRGB transfer function, that produces a negative gamma-corrected result, even though sRGB values are usually described as being in the 0 to 1 range. Is this expected, and should negative values simply be clipped when converting to displayable sRGB?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
10y ago
2 Answers
2
You are not clipping the intermediate RGB values.
From the sRGB Wikipedia article you linked to,
The intermediate parameters R, G and B for in-gamut colors are defined to be in the range [0,1], ... The linear RGB values are usually clipped to that range, with display white represented as (1,1,1)
From the W3C sRGB spec you linked to,
... XYZ are normalised such that Y=1 for the reference white and values of RGB outside of 0-1 are clipped.
Note that your (x,y) values are just about polar opposite from red, in the green region in the upper left of the CIE color space chromaticity diagram. Effectively, you are "so far away from red", it's almost like "negative red". Clip the R value: in sRGB, your red emphatically will be zero.
Originally by user11924. Source · Licensed CC BY-SA 4.0
user11924
10y ago
0
Generated from our catalog & community — verify before relying on it.
Yes — this is expected. A negative linear RGB component means the color is outside the sRGB gamut for that channel. In practical sRGB conversion, RGB values outside the valid 0–1 range are clipped to that range before final display/output.
So in your example, the red channel should be clipped to 0, not kept as a negative number. The same applies to any channel above 1: clip it to 1.
Why it happens: the XYZ color you started with represents a chromaticity that sRGB cannot reproduce exactly. The matrix conversion can therefore yield negative or greater-than-1 linear RGB values.
Typical handling:
- Convert XYZ to linear sRGB
- Clip each channel to [0, 1]
- Apply the sRGB transfer function
- If needed, scale to 0–255
For your case, the red value is effectively “no red” in sRGB, so it becomes 0 after clipping. Based on the community calculations, the final color is approximately pure green in sRGB: (0, 1, 0), or (0, 255, 0) in 8-bit terms.
Recommended products
UniqueBot
AI10y ago
Your Answer
Related Questions
How does the Y component in CIE XYZ relate to physical luminance?
How do I correctly calculate secondary chromaticity coordinates from RGB primaries on a CIE xy diagram?
What RAW/linear RGB value should an 18% gray card have with correct exposure?
What gamma setting should I use when calibrating my monitor for photography?
Why is the CIE 1931 chromaticity diagram non-linear, why doesn’t it reach y = 1, and how was it derived?