←back to thread

276 points samwillis | 1 comments | | HN request time: 0.408s | source
Show context
meindnoch ◴[] No.41082221[source]
Mostly correct, but I don't understand what the author is trying to do in the last section, where they try to fill the locus by generating spectra with two peaks and projecting it into the chromaticity diagram. Why do it like that?

This is how you should do it:

- You pick a Y value. This is going to be the luminance of your diagram.

- For each pixel inside the area bounded by the spectral locus (and the line of purples - the line connecting the two endpoints of the locus) you take its x, y coordinates.

- Together these 3 values specify your color in the CIE xyY color space. Converting from xyY to XYZ is trivial: X = Y / y * x, Y = Y, Z = Y / y * (1 - x - y)

- You map these XYZ values into your output image's color space (e.g. sRGB). If a given XYZ value maps outside the [0,1] interval in sRGB, then it's outside the sRGB gamut, and you may clip the values to the closest valid value inside the gamut.

replies(1): >>41083558 #
jlongster ◴[] No.41083558[source]
Author of the article here; I wasn't able to understand how to get that to work, and I talked about that in the post. This demo is doing that: https://jlongster.com/why-chromaticity-shape#block-31f373

The problem is "for each pixel inside the area". I could have done that, and then clipped the output by that shape. The problem is this doesn't answer why the shape is this way at all because you are using the shape itself to clip the output. It felt fake.

I do think this is what is most common though. I was trying to understand a more rigorous approach, and the one where you generate spectra and try to fill it is described here: https://clarkvision.com/articles/color-cie-chromaticity-and-...

That feels like a more rigorous approach, but clipping is probably "good enough" too

replies(1): >>41085368 #
1. meindnoch ◴[] No.41085368[source]
Ok, so you're asking why every visible color has to lie within the bounds of the spectral locus in the chromaticity diagram?

The reasoning is simple:

1. Spectral colors are basis vectors of the color spectrum. I.e. every possible spectrum can be thought of as a weighted sum of infinitely many Dirac deltas. With nonnegative weights, in particular, so it's a so-called conical combination (i.e. linear combination with nonnegative weights).

2. Taking the inner product with color matching functions is a linear transformation from this infinite dimensional space spanned by spectral colors to a 3-dimensional space. Linearity means that weighted sums are preserved, that is: every possible color spectrum's XYZ values are going to be the weighted sum of the spectral colors' XYZ values. And because the XYZ color matching functions are nonnegative everywhere, conical combinations are also preserved.

3. And finally, the conversion from XYZ to xyz is such, that it turns conical combinations into convex combinations (i.e. conical combinations where the weights sum to 1). It's easy to verify this with pen and paper.

It follows, that every color on the xy chart is going to be a convex combination of xy points corresponding to spectral colors, which geometrically means that they're going to lie inside the spectral colors' convex hull.