question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why does "colour.wavelength_to_XYZ" definition returns values outside expected range?

See original GitHub issue

Hi,

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KelSolaarcommented, Jun 5, 2020

You are welcome! 😃

1reaction
KevinJWcommented, Jun 4, 2020

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.

Kevin

Read more comments on GitHub >

github_iconTop Results From Across the Web

Programmer's Guide to XYZ, RGB
All RGB, XYZ, and yxY numbers in this tutorial are floating point numbers. RGB numbers have the nominal range 0 to 1, as...
Read more >
How is the visible gamut bounded? - colors - Stack Overflow
The methodology is to convert the square wave SPDs with various bandwidth to CIE XYZ tristimulus values, this will form the outer surface....
Read more >
From XYZ to RGB - Ocean Optics Web Book
Thus the sRBG color model returns the D65 illuminant as the white color, and it returns the equal-energy spectrum E as a pink...
Read more >
PRECISE COLOR COMMUNICATION | Konica Minolta
The concept for the XYZ tristimulus values is based on the three-component theory of color vision, which states that the eye possesses receptors...
Read more >
Color Topics for Programmers
XYZ, CIELAB, and CIELUV color spaces are based on human color perception. ... of light across the electromagnetic spectrum (see "Spectral Color Functions")....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found