I'm trying to use this solution to calculate the secondary coordinates from primaries: https://photo.stackexchange.com/a/75238/115749
But it won't work for any other primary than those in the solution (red and green). The results are wrong.
Here is my adaption to work with colour 0.4.4:
import colour
import numpy as np
from colour.models import RGB_COLOURSPACE_BT709
Conversion from RGB to chromaticity coordinates.
Defining RGB values for reference.
RGB_r = np.array([1, 0, 0])
RGB_g = np.array([0, 1, 0])
We assume they are encoded in sRGB colourspace.
XYZ_r = colour.RGB_to_XYZ(RGB_r,RGB_COLOURSPACE_BT709)
XYZ_g = colour.RGB_to_XYZ(RGB_g,RGB_COLOURSPACE_BT709)
Conversion to chromaticity coordinates.
xy_r = colour.XYZ_to_xy(XYZ_r)
print(xy_r)
[ 0.64 0.33]
xy_g = colour.XYZ_to_xy(XYZ_g)
print(xy_g)
[ 0.3 0.6]
Conversion to CIE xyY in order to maintain Luminance ratios.
Using sRGB Luminance ratios, second row of the NPM.
xyY_r = [xy_r[0], xy_r[1], colour.models.RGB_COLOURSPACE_BT709.matrix_RGB_to_XYZ[1, 0]]
xyY_g = [xy_g[0], xy_g[1], colour.models.RGB_COLOURSPACE_BT709.matrix_RGB_to_XYZ[1, 1]]
print(xyY_r)
print(xyY_g)
xy_s = colour.XYZ_to_xy(
colour.RGB_to_XYZ(
colour.XYZ_to_RGB(colour.xyY_to_XYZ(xyY_r),RGB_COLOURSPACE_BT709) +
colour.XYZ_to_RGB(colour.xyY_to_XYZ(xyY_g),RGB_COLOURSPACE_BT709),RGB_COLOURSPACE_BT709))
print(xy_s)
So if I change here to any other primary the coordinates are wrong:
RGB_r = np.array([1, 0, 0])
RGB_g = np.array([0, 1, 0])
- Yellow ([1, 0, 0] + [0, 1, 0]) --> [ 0.419306 0.505257] correct
- Cyan ([0, 1, 0] + [0, 0, 1]) --> [ 0.15433113 0.07559207] not correct
- Magenta ([1, 0, 0] + [0, 0, 1]) --> [ 0.17513059 0.07384747] not correct