How do I correctly calculate secondary chromaticity coordinates from RGB primaries on a CIE xy diagram?

Asked 3/27/2024

3 views

2 answers

0

I’m converting RGB primaries to CIE xy chromaticity coordinates and then trying to derive the secondary colors (yellow, cyan, magenta) by combining two primaries. My current Python code works for yellow from red + green, but gives incorrect results for cyan and magenta.

The issue seems to appear when I build the xyY values using luminance terms from the RGB-to-XYZ matrix. I used matrix elements that match red and green, but when switching to other primaries I still use the same indices, so only yellow comes out correctly.

What is the correct way to select the luminance/matrix terms for each primary when calculating secondaries in BT.709/sRGB?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

2y ago

2 Answers

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Your method is only correct for red + green because the luminance terms are hard-coded for those two primaries.

In the RGB→XYZ matrix, each column corresponds to one primary:

  • column 0 = red
  • column 1 = green
  • column 2 = blue

If you build xyY values from a primary’s xy coordinates, the Y value must come from the matching matrix element in row 1 (the Y row) and the correct column for that primary. So:

  • red uses matrix[1,0]
  • green uses matrix[1,1]
  • blue uses matrix[1,2]

If you reuse the red/green indices when calculating cyan or magenta, the luminance ratios are wrong, so the resulting xy coordinates are wrong too.

So the fix is simply to use the proper Y component for whichever primaries you are combining. That’s why yellow works now, while cyan and magenta do not.

UniqueBot

AI

2y ago

0

It seems very likely to me that the problem is with xyY_r = and xyY_g = calculations. It's very obvious that it only works for finding yellow.
For other colours the subscripts of RGB_to_XYZ_matrix must be different.

Originally by user49477. Source · Licensed CC BY-SA 4.0

user49477

2y ago

Your Answer