Skip to content

[BUG]: Conversion graph wrong results when converting between Lab and LCHab #1392

@lassefschmidt

Description

@lassefschmidt

Description

Description

I get weird results when using conversion graph between Lab and LCHab.

When I use as input the spectral distribution, conversion result is correct for both LCHab and Lab. But when I convert between Lab and LCHab, I get wrong results. In the backend, we use LCHab_to_Lab/Lab_to_LCHab. These functions are wrappers only and use JChab_to_Jab/Jab_to_JChab. But they have different annotations compared to LCHab_to_Lab -- maybe this causes the issue ?

Best,
Lasse

Code for Reproduction

import colour
import numpy as np

remission_curve = np.array([
    0.41408, 0.6332, 0.76334, 0.80015, 0.81076, 0.81892, 0.82485, 0.82879, 0.8314, 0.83452,
    0.83614, 0.83643, 0.83471, 0.83307, 0.83233, 0.82874, 0.82496, 0.82656, 0.82918, 0.82945,
    0.82993, 0.83085, 0.83332, 0.8376, 0.84379, 0.85061, 0.86037, 0.87132, 0.88176, 0.89274, 0.90209
])

wavelenghts = np.arange(400, 701, 10)

data = {
    float(wl): float(v) for wl, v in zip(wavelenghts, remission_curve)
}

reference = colour.SpectralDistribution(
    data
).align(colour.SpectralShape(400, 700, 1))

cmfs = colour.MSDS_CMFS['CIE 1964 10 Degree Standard Observer']
illuminant_sds = colour.SDS_ILLUMINANTS["D65"]
illuminant_ccs = colour.CCS_ILLUMINANTS['CIE 1964 10 Degree Standard Observer']["D65"]

lab = colour.convert(
    reference, "Spectral Distribution", "CIE Lab", to_reference_scale=True,
    sd_to_XYZ={"cmfs": cmfs, "illuminant": illuminant_sds, "method": "Integration"},
    XYZ_to_Lab={"illuminant": illuminant_ccs},
)

lch = colour.convert(
    reference, "Spectral Distribution", "CIE LCHab", to_reference_scale=True,
    sd_to_XYZ={"cmfs": cmfs, "illuminant": illuminant_sds, "method": "Integration"},
    XYZ_to_Lab={"illuminant": illuminant_ccs},
)

# these printouts are the correct values ! (verified)
print(lab, lch)

reconv_lab = colour.convert(lch, "CIE LCHab", "CIE Lab")
reconv_lch = colour.convert(lab, "CIE Lab", "CIE LCHab")

# these printouts are wrong (compare the values to previous printout -- the edges used in the conversion graph are LCHab_to_Lab [using JChab_to_Jab in backend which has other annotations compared to LCHab_to_Lab] and Lab_to_LCHab [same issue in backend])
print(reconv_lab, reconv_lab==lab)
print(reconv_lch, reconv_lch==lch)

Exception Message

Environment Information

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.14.0 (main, Oct 10 2025, 12:47:49) [Clang 20.1.4 ]         *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.4.7                                                        *
*                                                                             *
*   Runtime :                                                                 *
*       matplotlib : 3.10.7                                                   *
*       networkx : 3.5                                                        *
*       numpy : 2.3.3                                                         *
*                                                                             *
===============================================================================
defaultdict(dict,
            {'Interpreter': {'python': '3.14.0 (main, Oct 10 2025, 12:47:49) [Clang 20.1.4 ]'},
             'colour-science.org': {'colour': '0.4.7'},
             'Runtime': {'matplotlib': '3.10.7',
              'networkx': '3.5',
              'numpy': '2.3.3'}})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions