I want write code to predict CIE XYZ from LED driver R,G,B output value

36 Views Asked by At

I am making auto white balance calibration application. I have a chromameter and api. So my application can measure CIExyY and CIEXYZ. And my app can set R,G,B output value of my devices's LED panel.

I set R,G,B value combination and measureed CIEXYZ three times. And then I evaluated follow matrix.

matrix

I thought that once I evaluated the matrix, I could calculate CIEXYZ with R,G,B output value.

But It's not correct value.

R,G,B output value is 0~1023. 0 doesn't mean 0 output. 0~1023 is just level.

1

There are 1 best solutions below

4
Kel Solaar On

Using colour, given the primaries and whitepoint expressed as CIE XYZ tristimulus, you can compute the normalised primary matrix converting from your LED colourspace to CIE XYZ as follows:

import colour
import numpy as np

XYZ_PRIMARIES = np.array(
    [
        [2.12500000, 1.00000000, -0.00000000],
        [0.38405797, 1.00000000, 0.06521739],
        [2.50000000, 1.00000000, 13.16666667],
    ]
)
XYZ_WHITEPOINT = np.array([0.89458689, 1.00000000, 0.95441595])

NPM = colour.normalised_primary_matrix(
    colour.XYZ_to_xy(XYZ_PRIMARIES), colour.XYZ_to_xy(XYZ_WHITEPOINT)
)

print(NPM)
print(np.linalg.inv(NPM))
[[  4.45169812e-01   2.77134409e-01   1.72282669e-01]
 [  2.09491676e-01   7.21595256e-01   6.89130676e-02]
 [ -3.63410128e-17   4.70605593e-02   9.07355391e-01]]
[[ 2.72539405 -1.01800301 -0.4401632 ]
 [-0.79516802  1.68973205  0.02264719]
 [ 0.04124189 -0.08763902  1.10092938]]

You can also create a new RGB colourspace which will allow you to convert to other known colourspaces:

RGB_COLOURSPACE_LED = colour.RGB_Colourspace(
    "LED", colour.XYZ_to_xy(XYZ_PRIMARIES), colour.XYZ_to_xy(XYZ_WHITEPOINT)
)
print(RGB_COLOURSPACE_LED)

print(
    colour.matrix_RGB_to_RGB(RGB_COLOURSPACE_LED, colour.models.RGB_COLOURSPACE_BT2020)
)
[[  7.05392504e-01   2.49107517e-01   4.54999792e-02]
 [  4.04429548e-02   9.47423997e-01   1.21330485e-02]
 [ -5.83382089e-04   2.69551875e-02   9.73628195e-01]]

Note that this assumes that the LED behave linearly which is almost certainly not the case!