1

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
FLX
  • 111
  • 1
  • I’m voting to close this question because it is not about the photography: https://photo.stackexchange.com/help/on-topic – Romeo Ninov Mar 27 '24 at 21:13
  • @RomeoNinov the link to the solution I used is on the same topic ... – FLX Mar 28 '24 at 09:59
  • I cannot vote to NOT close this question because apparently more than 15 years are needed to implement this feature. – Euri Pinhollow Mar 29 '24 at 19:17

1 Answers1

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.

Euri Pinhollow
  • 5,071
  • 17
  • 36