Why does "colour.wavelength_to_XYZ" definition returns values outside expected range? #746
-
Hi, I'm trying to obtain RGB values of the visible spectrum. Therefore, I do this:
Based on this: 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
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. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
It looks like you are trying to map the locus values (outer edge of the diagram) of the CIE1931 space onto sRGB space. Most of these fall out side the sRGB space. To interpolate to a value I believe they should be clipped to 0 or 1. |
Beta Was this translation helpful? Give feedback.
-
Hmm, yes, that makes sense, thanks! So I suppose that I should simply clip the XYZ values to [0; 1] before converting to sRGB, right? I am basically trying to create spectral distribution plots just like what is created by the function |
Beta Was this translation helpful? Give feedback.
-
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 colour/colour/plotting/colorimetry.py Line 152 in 3bebd7e 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 |
Beta Was this translation helpful? Give feedback.
-
Hi @LeCyberDucky, To expand on @KevinJW and @Ron024, the reported domains and ranges in the documentation can be somehow misleading if you haven't read this portion of the documentation: https://colour.readthedocs.io/en/develop/basics.html#domain-range-scales. You can think about them as indicative soft limits. Colour is built to work on double-precision floating-point numbers. We promote everything to float64 by default so that we can manipulate HDRI imagery and values that are outside the common gamuts and even outside the spectral locus. This is critical when dealing with digital-still and motion-picture cameras. With that in mind, we try to never clip nor normalise anything, except in very rare instances, e.g. web colours. I hope it makes sense! |
Beta Was this translation helpful? Give feedback.
-
Yes, that makes sense. I hadn't seen that documentation page. Thank you very much. |
Beta Was this translation helpful? Give feedback.
-
You are welcome! :) |
Beta Was this translation helpful? Give feedback.
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
colour/colour/plotting/colorimetry.py
Line 152 in 3bebd7e
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