Why does "colour.wavelength_to_XYZ" definition returns values outside expected range?See original GitHub issue
I’m trying to obtain RGB values of the visible spectrum. Therefore, I do this:
import numpy as np import colour wavelength_range = np.arange(360, 830 + 0.5, 0.5) rgb_spectrum = colour.XYZ_to_sRGB(colour.wavelength_to_XYZ(wavelength_range))
Based on this: https://colour.readthedocs.io/en/develop/generated/colour.wavelength_to_XYZ.html https://colour.readthedocs.io/en/develop/generated/colour.XYZ_to_sRGB.html
I would expect the output to be in the range [0; 1]. From the above code, however, I get a maximum entry of 1.783001. Is there something wrong here, or am I simply missunderstanding the documentation? If the value is correct, I’m not sure how to interpret it.
I have included the output from
$ python -c "import colour;colour.utilities.describe_environment()"
below, in case that might be helpful. I hope somebody can help me with this 😃
=============================================================================== * * * Interpreter : * * python : 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC * * v.1916 64 bit (AMD64)] * * * * colour-science.org : * * colour : 0.3.15 * * * * Runtime : * * imageio : 2.5.0 * * matplotlib : 3.1.1 * * networkx : 2.3 * * numpy : 1.17.2 * * pandas : 0.24.2 * * scipy : 1.3.1 * * six : 1.12.0 * * * ===============================================================================
Edit: Having looked a bit more into this, I can see that not only do I get values greater than 1, I also get at negative minimum value of -9.270830e-08.
Feeding the data into the XYZ_to_sRGB function results in minimum and maximum values of -11.956099 and 1.494786, respectively.
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
You are welcome! 😃
if all you want is the ‘approximate colours’ that are used in that function you could extract just the beginning of that function up to the point it generates the colours object (about half way through the function https://github.com/colour-science/colour/blob/3bebd7e903cbcbee959f56786c020335a1b06cf7/colour/plotting/colorimetry.py#L152)
As was mentioned above there is an adjustment being made to bring the colours in gamut for an sRGB device, as pretty much none of the wavelength buckets are likely to fall inside sRGB.