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.

"colour.convert" definition: sRGB should be the default RGB colorspace, but actually is not?

See original GitHub issue

The documentation for colour.convert states that:

Various defaults have been systematically adopted compared to the low-level Colour API: (…) The default RGB colourspace is the sRGB colourspace. It can also be changed on a per definition basis along the conversion path.

This is my code:

# pip install colour-science networkx
import colour
import numpy as np

np.set_printoptions(suppress=True)

input_rgb = colour.models.eotf_sRGB(np.array([127, 127, 127]) / 255.0)
converted = colour.convert(input_rgb, 'RGB', 'Cie Lab', verbose={'mode': 'Long', 'width': 120})

I assume that this should produce the same output as when changing the last line to

converted = colour.convert(input_rgb, 'sRGB', 'Cie Lab', verbose={'mode': 'Long', 'width': 120})

However, there is a dramatic difference.

This is the output for ‘RGB’:

========================================================================================================================
*                                                                                                                      *
*   [ Conversion Path ]                                                                                                *
*                                                                                                                      *
*   "RGB_to_XYZ" --> "XYZ_to_Lab"                                                                                      *
*                                                                                                                      *
========================================================================================================================
========================================================================================================================
*                                                                                                                      *
*   [ "RGB_to_XYZ" ]                                                                                                   *
*                                                                                                                      *
*   [ Signature ]                                                                                                      *
*                                                                                                                      *
*   <Signature (RGB, illuminant_RGB, illuminant_XYZ, RGB_to_XYZ_matrix, chromatic_adaptation_transform='CAT02',        *
*   cctf_decoding=None, **kwargs)>                                                                                     *
*                                                                                                                      *
*   [ Conversion Output ]                                                                                              *
*                                                                                                                      *
*   [ 0.20172533  0.21223076  0.23111929]                                                                              *
*                                                                                                                      *
========================================================================================================================
========================================================================================================================
*                                                                                                                      *
*   [ "XYZ_to_Lab" ]                                                                                                   *
*                                                                                                                      *
*   [ Signature ]                                                                                                      *
*                                                                                                                      *
*   <Signature (XYZ, illuminant=array([ 0.3127,  0.329 ]))>                                                            *
*                                                                                                                      *
*   [ Conversion Output ]                                                                                              *
*                                                                                                                      *
*   [ 0.53192777  0.0000461   0.00002109]                                                                              *
*                                                                                                                      *
========================================================================================================================

This is the output for ‘sRGB’:

========================================================================================================================
*                                                                                                                      *
*   [ Conversion Path ]                                                                                                *
*                                                                                                                      *
*   "sRGB_to_XYZ" --> "XYZ_to_Lab"                                                                                     *
*                                                                                                                      *
========================================================================================================================
========================================================================================================================
*                                                                                                                      *
*   [ "sRGB_to_XYZ" ]                                                                                                  *
*                                                                                                                      *
*   [ Signature ]                                                                                                      *
*                                                                                                                      *
*   <Signature (RGB, illuminant=array([ 0.3127,  0.329 ]), chromatic_adaptation_method='CAT02',                        *
*   apply_cctf_decoding=True, **kwargs)>                                                                               *
*                                                                                                                      *
*   [ Conversion Output ]                                                                                              *
*                                                                                                                      *
*   [ 0.03521062  0.03704431  0.04034126]                                                                              *
*                                                                                                                      *
========================================================================================================================
========================================================================================================================
*                                                                                                                      *
*   [ "XYZ_to_Lab" ]                                                                                                   *
*                                                                                                                      *
*   [ Signature ]                                                                                                      *
*                                                                                                                      *
*   <Signature (XYZ, illuminant=array([ 0.3127,  0.329 ]))>                                                            *
*                                                                                                                      *
*   [ Conversion Output ]                                                                                              *
*                                                                                                                      *
*   [ 0.22669199  0.00002576  0.00001179]                                                                              *
*                                                                                                                      *
========================================================================================================================

EDIT: This is my environment.

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC   *
*   v.1916 64 bit (AMD64)]                                                    *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.3.15                                                       *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.9.0                                                       *
*       matplotlib : 3.2.2                                                    *
*       networkx : 2.4                                                        *
*       numpy : 1.19.0                                                        *
*       pandas : 1.0.5                                                        *
*       scipy : 1.5.0                                                         *
*       six : 1.15.0                                                          *
*                                                                             *
===============================================================================

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
KelSolaarcommented, Jul 19, 2020
1reaction
KelSolaarcommented, Jul 18, 2020

Hi @rsnitsch,

Thanks! As you saw the main difference pertains to encoding/decoding in that case, we should make the documentation clearer but besides that, the default IS sRGB, whether it is encoded or not is critical obviously but it does change the fact that the illuminant is D65 and the primaries are that of BT.709/sRGB. We will amend the documentation accordingly, that being said there are hints at that in the notes:

    -   The **RGB** colour representation is assumed to be linear and
        representing *scene-referred* imagery. To convert such *RGB* values to
        *output-referred* (*display-referred*) imagery, i.e. encode the *RGB*
        values using an encoding colour component transfer function
        (Encoding CCTF) / opto-electronic transfer function (OETF / OECF), the
        **Output-Referred RGB** representation must be used.

The graph code is still considered experimental as the warning implies so if you have other issues or misunderstanding, please keep them coming!

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Standard Default Color Space for the Internet - sRGB - W3C
There is a need to merge the many standard and non-standard RGB monitor spaces into a single standard RGB color space. Such a...
Read more >
Are RGB images converted to sRGB automatically before ...
A browser or device will only convert tagged images of a non-sRGB colorspace TO sRGB IF there is a color management engine.
Read more >
sRGB color space in OpenGL - Unlimited 3D - WordPress.com
sRGB defines a standard RGB color space, to be used “by default” – by monitor, printer and even internet content, so that it...
Read more >
P: Save For Web, Convert to sRGB should be off by
Photoshop's Save for Web ability contains a setting called Convert to sRGB. If on, it destructively changes the resulting file's colour values from...
Read more >
Adobe RGB Versus sRGB Color Space - Which Should You ...
Which is the best Color Space sRGB or Adobe RGB? ... When you take a RAW file, the camera captures all the colors...
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