0

Is there a way CIE chromaticity coordinates to gray scale value (0 to 255)?

Any existing implementation in ImageJ, R or Python? Or formula?

Here is the table taken from here.

enter image description here

neversaint
  • 60,904
  • 137
  • 310
  • 477
  • You cannot. Chromacity is about hue, not about brightness. Greys, blacks, whites have all the same chromacity. Note: often we plot colours with xyY (where Y is the luminescence). So xy is just 2 of the 3 dimension we need to specify visible colours. – Giacomo Catenazzi Mar 18 '21 at 15:16
  • In an ironic way, this is "an x y question" as you ask about greyscale, which is achromatic luminance, and list a table of achromatic white point coordinates, all of which are irrespective of any luminance value. The *MOST* that can be determined from that table is the chroma relative to a different whitepoint. But not the luminance which is what defines the "greyscale". So the "y" is .... perhaps you can clarify what you are specifically trying to do or process? – Myndex Oct 23 '21 at 10:59

1 Answers1

3

OP's question:

Is there a way CIE chromaticity coordinates to gray scale value (0 to 255)?

Short Answer:

For both XYZ and xyY, the luminance is Y, therefore the greyscale is Y.

Longer Answer:

Y is linear, so any gamma encoded RGB space needs to be linearized before converting to Y, and a Y value must have gamma applied to convert back to that same RGB space.

The coordinates given in the list of whitepoints do not create greyscales, as they are chromaticity coordinates only and do not include any Y value.

It is not clear what you want to do here. I might assume you want to create an RGB greyscale of something. But then which of the many RGB spaces do you want to use? What do you actually want to make a greyscale of?


Answer for another answer

In the comments to another answer, one which has errors, the author asked for an explanation of why. What follows is a breakdown of that answer.

Because the x,y chromacity1 coordinates describe our perception of color2, and are obtained experimentally3, the best way to understand them is through the CIE’s data tables4

Why xyY

  1. It's "chromaticity" chroma-ti-city.

  2. xy chromaticity coordinates do not "describe our perception of color" you need a color appearance model for that. xy coordinates on the 1931 chromaticity diagram at best predict (with significant error) the approximate hue and chroma, relative to a white point. Still needed is the luminance component Y.

  3. The xy coords are not "obtained experimentally"

    • the CIE standard observer was created by combining/averaging the experimental data of 17 test subjects, collected circa 1924.
    • This data forms the spectral locus, i.e. the outer rim of the chromaticity diagram. You could say this was created experimentally.
    • a given stimuli is measured to determine the xy coordinates, or the xy coordinates are calculated based on known wavelength, etc..
  4. Suggesting reading some abstract lists of numbers is not going to help anyone understand anything.

    • The link to the Wiki page on CIE 1931 is better though it goes direct to the standard observer and skips the useful background and foundation.
    • I list some resources at the bottom of this post.

The x,y coordinates specify a color5, without a luminance6 (~brightness) associated7.

  1. No, the xy coordinates indicate a hue and chroma, relative to a whitepoint and within a certain error. But color is a perception, and there is more than just coordinates to a particular color sensation.

  2. Partly true... yes one xy point does not consider luminance, but then this means that saturation is also not known. And one xy point does not tell us the xy point for the relative white point. If all we have is one xy point and we do not know Y and we do not know the whitepoint, then:

    • NO, we do not know the actual color
      • We do not know the exact hue
      • We do not know the exact chroma
      • We do not know the saturation at all
      • We do not know the lightness/darkness/brightness at all
    • So, without knowing any of those things then I suppose you could say the "xy coordinates specify a color if we also know the luminance and whitepoint which we don't so then the xy coordinates are the un-sprouted seed of a potential color".
  3. ALSO luminance is not brightness. Brightness, lightness, darkness are perceptions. Luminance is spectrally weighted light, and other than the spectral weighting does not model perception.

You can add this luminance Y by picking any value. You now have a color in the Yxy color space (for example 0.5).

  • ???? No, you can not just pick any value. ?!?!?
    • The luminance value is a critical component to the appearance...
    • but moreover, it is the ONLY component of the greyscale.
    • Typical greyscales are Y with the xy discarded.
    • As Y is the entirety of the greyscale, it should be obvious that you cannot just "pick whatever".

Convert this to a XYZ triplet with: X = Y / y * x & Z = Y / y * (1-x-y)

  • While that's a commendable cut & paste, what happens when little y is 0? It can happen with some modern color spaces, and as the result of some transforms. At least clamp the little y so that divide by zero issues don't arise (not a complete solution if we want to retain negative values):
                        //  from SeeLab color library
    function xyYtoXYZ ( ltlx, ltly, oldY ) {
        if (ltly > 0.0) {
            Y = Math.max(oldY,0.0); // sanity check
            X = (ltlx * Y) / ltly;
            Z = ((1.0 - ltlx - ltly) * Y) / ltly;
        } else {
              // clamp X Z to 0 if ltly is <= 0
            X = Z = 0.0;
            Y = Math.max(oldY,0.0);
        }
        return [X,Y,Z]
    }

Finally, convert XYZ to RGB using this matrix multiplication:

Finally?? Well not finally, not at all. Nothing has been done here to create a greyscale.

Moreover, the matrix presented is the XYZ to CIERGB matrix, that goes to CIERGB, a color space that has little practical use. The primaries are imaginary and can not be realized as actual colors. This makes it mainly useful as the theoretical RGB space that XYZ is derived from.

The fact we have XYZ is specifically because CIERGB has negative values, and in the era before computers, when slide rules were the method of calculation, working with negative numbers was difficult. XYZ is just an "all positive" projection of CIERGB, and there is no practical benefit to transforming to CIERGB.

Real RGBs like sRGB

Normally, you want to go to a real RGB space like sRGB, and that is a different matrix. If no RGB space is declared, sRGB is the assumed default (not CIERGB). In fact every combination of color space primaries and whitepoint are going to have their own matrix.

And STILL not finally, as most color spaces also have a gamma or transfer function, and after transiting the matrix you must apply the gamma before multiplying by 255 (or whatever factor per the target bit depth).

If the resulting value is outside the RGB gamut because values are too large, pick a smaller Y value, which is equivalent to just scaling down your RGB values (scale all three equally).

Just changing Y without adjusting the other coordinates results in a shift in saturation. In some applications like dataviz, you want to avoid a saturation shift, so this approach fails. More to the point, xyY is not so much the best space to try gamut mapping as it is not at all perceptually uniform.

If there are negative values because the x,y coordinates cannot be represented by RGB primaries, then you’ll have to find an approximation to your coordinates that can.

What you'd actually want to do is gamut remapping to find a value with the appropriate perceptual intent. Again, not a great space for that.

This is equivalent to finding the nearest RGB triplet that falls within the gamut. One trivial approach to do so is to set any negative values to 0.

Nearest isn't necessarily on the ideal vector. And hard clipping is certainly trivial, but also far from best practices. A soft clamp with balance of the other channels is the preferred trivial fix. If you're clipping over or under runs of the RGB values you are going to have some massive perceptual shifts, particularly hue. So again, you usually want real gamut mapping.

The point:

the smaller gamut of the output space is going to require gamut mapping for out of gamut values, and those out of gamut values may be positive or negative. Adjusting only one of the xyY or XYZ coordinates isn't likely to maintain the perceptual intent, and in any case, what does any of this have to do with greyscale? Nothing!

Greyscale, by definition, is achromatic. This means the xy coordinates will always be on the line between white and black. By definition, you will not go out of gamut (except for super white or super black).

TL;DR

The OP's question is answered "greyscale is on Y, not xy".

The other answer to OP's question is not relevant as stated, but this is in large part as the OP's question is probably really asking a different question (unknown to me at the moment).

Resources

Colorimetry Understanding the CIE System by Janos Schanda (2007) I've seen PDFs online, it is the canonical reference for much of this.

Books by Hunt, Fairchild, Burns, Stone are also good.

For practical application, NASA's color site by Larry Arend is good: https://colorusage.arc.nasa.gov

And Bruce McEvoy's site is fabulous: https://www.handprint.com/HP/WCL/wcolor.html

Best of luck.

Myndex
  • 3,952
  • 1
  • 9
  • 24
  • Feel free to inquire with additional questions if you have them, I try to answer within a day. – Myndex Oct 24 '21 at 16:44