Search code examples
javascriptphpcolor-schemephilips-hue

PHP - How to convert RGB color to CIE 1931 color specification


I am creating my own PHP based application where i want to change RGB color into xy format of CIE 1931.

How can i convert my RGB color specs to the CIE color space?


Solution

  • First calculate X, Y and Z with the transform matrix and then normalize the result

    X = 0.4124*R + 0.3576*G + 0.1805*B
    Y = 0.2126*R + 0.7152*G + 0.0722*B
    Z = 0.0193*R + 0.1192*G + 0.9505*B
    

    Normalize:

    x = X / (X + Y + Z)
    y = Y / (X + Y + Z)