Search code examples
formulargbcolor-space

converting XYZ color to RGB


color-primary transformations

Does anyone know of any formula for converting a XYZ to an RGB value?

how find rgb from XYZ in this pic? enter image description here


Solution

  • There is a simple linear relationship between RGB and XYZ spaces (if you wish you can express this in matrix form in the obvious way): R = 3.2404542*X - 1.5371385*Y - 0.4985314*Z G = -0.9692660*X + 1.8760108*Y + 0.0415560*Z B = 0.0556434*X - 0.2040259*Y + 1.0572252*Z

    However, if what you meant is sRGB space, then additional non-linear transformation needs to be applied to each component: R=adj(R), G=adj(G), and B=adj(B). The adj function is defined as follows:

    function adj(C) {
      if (Abs(C) < 0.0031308) {
        return 12.92 * C;
      }
      return 1.055 * Math.pow(C, 0.41666) - 0.055;
    }