<p>You can certainly convert the wavelengths of the visible spectrum into the XYZ colour space with some extra considerations. Converting wavelengths of the visible spectrum into RGB will present some problems due to the gamut limits of RGB.
The wavelengths of the visible spectrum are usually displayed in the CIE 1931 xy chromaticity space, where each wavelength has a fixed xy position independent of intensity. In LMS, XYZ, RGB and most colour spaces, the position will depend on the intensity of the wavelength. (Please note that the lowercase xy chromaticity values are not the same as the uppercase XY of the XYZ values.) This means you need to choose the intensity for each wavelength, and will get different results based on what you choose.
The graph below shows the shape to expect for equal intensity of each wavelength, intensity of the wavelength in typical sunlight, and the maximum intensity which stimulates one of the cones in the human eye at 100%. For comparison there is a hexagon which shows the limit of the sRGB gamut. There is one dot for each 5-nanometre difference in wavelength.
<a href="https://i.sstatic.net/tpjsW.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tpjsW.jpg" alt="DKL space spectrum at various intensities compared to sRGB" /></a>
This chart is showing the values in the colour plane of DKL space, where the values are calculated from the three cone L, M and S values. The horizontal axis is the (L-M)*4.5, and the vertical axis is (L+M)/2 – S.
The graph showing wavelengths as maximum intensity is the outside limit of what values are possible, with the conceptual “line of purples” joining the two extreme ends of the graph.
Converting these values into RGB requires mapping values outside of the RGB gamut into the RGB gamut. Here is some analysis of an RGB image of a spectrum (presumably of daylight) showing how the image mapped the values showing the same 2d range as in the chart above. You can see how the shape below relates to the Sunlight graph above. The hexagon in white is again the RGB limit, and the curved shape outside of it is the MacAdam limit, which is a theoretical limit of surface colours. (The colours below are just illustrating this two-dimensional position in RGB space, they are not the colours of the actual pixels.)
<a href="https://i.sstatic.net/5P8sv.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5P8sv.jpg" alt="Range of sRGB pixels in a photograph of a spectrum" /></a>
I was initially expecting that a photograph of a spectrum would necessarily be the outside limit of colours in RGB space. When I investigated further, I learned that wavelengths of light are only at the outside edge of possible colours when viewed at maximum intensity, such as viewing one wavelength on its own in a dark environment.
If you look at the LMS response curves below, you can see that between blue and green, around 490 nanometres, none of the cones respond strongly, so the colour sensation at that wavelength is notably weak when viewed in a whole spectrum. At the far-red end beyond 640 nanometres the L cones responds many times more strongly than the M cone, so the colour response of those pure wavelengths is much stronger than any mix of wavelengths that is likely to be seen reflecting from an object.</p>
<p><a href="https://i.sstatic.net/iAWU0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iAWU0.png" alt="LMS response curves" /></a>
The graphs of the spectrum in DKL space above do show an explanation for why the spectrum appears to have bands of colour. Where the dots are closely spaced there is little difference in perceived colour across a range of wavelengths. Where the dots are widely spaced there is a greater difference in perceived colour. This creates the appearance of bands of colour separated from each other. The reason for this can be seen in the LMS response curve chart above. From 430 to 460 nanometres none of the response curves change greatly. This is in contrast to the range from 470 to 500 nanometres, where the S response drops off sharply as the L and M responses increase more sharply. This creates the impression of a blue colour band which then changes to another band as the wavelength increases.</p>
<p>As Nathan Reed said in the comment, the necessary tables are on cvrl.org, and there is more useful information about conversion between different colour spaces on <a href="http://www.brucelindbloom.com" rel="nofollow noreferrer">www.brucelindbloom.com</a></p>

CC BY-SA 4.0
2022-09-12T16:45:39.223Z
2022-09-12T16:45:39.223Z
Timothy Maguire
<p><a href="https://en.wikipedia.org/wiki/LMS_color_space#:%7E:text=LMS%20%28long%2C%20medium%2C%20short%29%2C%20is%20a%20color%20space,the%20lower%20end%20is%20generally%20bounded%20by%20zero." rel="nofollow noreferrer">LMS Color Space</a> is based on responsivity of 3 cones in Human eyes with each having different curves. I'm looking for a way to plot those curves. Moreover, Is threre a way to covert wavelength under visible spectrum to RGB or XYZ colorspace?</p>

CC BY-SA 4.0
2022-09-01T19:22:37.660Z
The data sets are freely available from http://www.cvrl.org/ in CSV format, from which you can easily plot the data using a variety of tools. For converting a wavelength to RGB or XYZ, what you want is the color matching functions (CMFs).
Nathan Reed
<2d-graphics><colorspace>
How do I plot tristimulus curves?
vector X
# How do I plot tristimulus curves?

(Asked by: username_0 on 2022-09-01)

[LMS Color Space](https://en.wikipedia.org/wiki/LMS_color_space#:%7E:text=LMS%20%28long%2C%20medium%2C%20short%29%2C%20is%20a%20color%20space,the%20lower%20end%20is%20generally%20bounded%20by%20zero.) is based on responsivity of 3 cones in Human eyes with each having different curves. I'm looking for a way to plot those curves. Moreover, Is threre a way to covert wavelength under visible spectrum to RGB or XYZ colorspace?

**Tags:** 2d-graphics, colorspace

> **Comments:**
> **username_1**: The data sets are freely available from http://www.cvrl.org/ in CSV format, from which you can easily plot the data using a variety of tools. For converting a wavelength to RGB or XYZ, what you want is the color matching functions (CMFs).  

---

## 1 answers

### Answer by username_2 on 2022-09-12. Score: 2

You can certainly convert the wavelengths of the visible spectrum into the XYZ colour space with some extra considerations. Converting wavelengths of the visible spectrum into RGB will present some problems due to the gamut limits of RGB.
The wavelengths of the visible spectrum are usually displayed in the CIE 1931 xy chromaticity space, where each wavelength has a fixed xy position independent of intensity. In LMS, XYZ, RGB and most colour spaces, the position will depend on the intensity of the wavelength. (Please note that the lowercase xy chromaticity values are not the same as the uppercase XY of the XYZ values.) This means you need to choose the intensity for each wavelength, and will get different results based on what you choose.
The graph below shows the shape to expect for equal intensity of each wavelength, intensity of the wavelength in typical sunlight, and the maximum intensity which stimulates one of the cones in the human eye at 100%. For comparison there is a hexagon which shows the limit of the sRGB gamut. There is one dot for each 5-nanometre difference in wavelength.
[![DKL space spectrum at various intensities compared to sRGB](https://i.sstatic.net/tpjsW.jpg)](https://i.sstatic.net/tpjsW.jpg)
This chart is showing the values in the colour plane of DKL space, where the values are calculated from the three cone L, M and S values. The horizontal axis is the (L-M)\*4.5, and the vertical axis is (L+M)/2 – S.
The graph showing wavelengths as maximum intensity is the outside limit of what values are possible, with the conceptual “line of purples” joining the two extreme ends of the graph.
Converting these values into RGB requires mapping values outside of the RGB gamut into the RGB gamut. Here is some analysis of an RGB image of a spectrum (presumably of daylight) showing how the image mapped the values showing the same 2d range as in the chart above. You can see how the shape below relates to the Sunlight graph above. The hexagon in white is again the RGB limit, and the curved shape outside of it is the MacAdam limit, which is a theoretical limit of surface colours. (The colours below are just illustrating this two-dimensional position in RGB space, they are not the colours of the actual pixels.)
[![Range of sRGB pixels in a photograph of a spectrum](https://i.sstatic.net/5P8sv.jpg)](https://i.sstatic.net/5P8sv.jpg)
I was initially expecting that a photograph of a spectrum would necessarily be the outside limit of colours in RGB space. When I investigated further, I learned that wavelengths of light are only at the outside edge of possible colours when viewed at maximum intensity, such as viewing one wavelength on its own in a dark environment.
If you look at the LMS response curves below, you can see that between blue and green, around 490 nanometres, none of the cones respond strongly, so the colour sensation at that wavelength is notably weak when viewed in a whole spectrum. At the far-red end beyond 640 nanometres the L cones responds many times more strongly than the M cone, so the colour response of those pure wavelengths is much stronger than any mix of wavelengths that is likely to be seen reflecting from an object.

[![LMS response curves](https://i.sstatic.net/iAWU0.png)](https://i.sstatic.net/iAWU0.png)
The graphs of the spectrum in DKL space above do show an explanation for why the spectrum appears to have bands of colour. Where the dots are closely spaced there is little difference in perceived colour across a range of wavelengths. Where the dots are widely spaced there is a greater difference in perceived colour. This creates the appearance of bands of colour separated from each other. The reason for this can be seen in the LMS response curve chart above. From 430 to 460 nanometres none of the response curves change greatly. This is in contrast to the range from 470 to 500 nanometres, where the S response drops off sharply as the L and M responses increase more sharply. This creates the impression of a blue colour band which then changes to another band as the wavelength increases.

As username_1 username_1 said in the comment, the necessary tables are on cvrl.org, and there is more useful information about conversion between different colour spaces on [www.brucelindbloom.com](http://www.brucelindbloom.com)


---

