这是indexloc提供的服务,不要输入任何密码
Skip to content

[BUG]: *nan* are generated by colour.difference.delta_E_CIE1994 definition. #1206

@volrak

Description

@volrak

Description

Certain values passed into delta_E_CIE1994() cause an exception or nan result.

The cause looks like rounding of intermediate floating point values resulting in a square root of a negative number. For the example inputs in the reproduction section, the argument to sqrt is:

>>> delta_A**2 + delta_B**2 - delta_C**2
-2.5153490401663703e-17

A likely fix seems be to enforce a lower bound of 0 on this expression before the sqrt.

Code for Reproduction

from colour.difference import delta_E_CIE1994
v1 = [76.62311359, 0.81274256, 4.01990717]
v2 = [76.12591697, 0.82627158, 4.08682309]
delta_E_CIE1994(v1, v2, textiles=True)

Exception Message

~/.local/lib/python3.10/site-packages/colour/difference/delta_e.py:220: RuntimeWarning: invalid value encountered in sqrt(delta_H = np.sqrt(delta_A**2 + delta_B**2 - delta_C**2)

Environment Information

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]            *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.4.1                                                        *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.22.0                                                      *
*       matplotlib : 3.6.0                                                    *
*       networkx : 2.8.6                                                      *
*       numpy : 1.23.3                                                        *
*       pandas : 1.4.4                                                        *
*       scipy : 1.9.1                                                         *
*                                                                             *
===============================================================================
defaultdict(<class 'dict'>, {'Interpreter': {'python': '3.10.6 (main, Aug 10 2022, 11:40:04) [GCC 11.3.0]'}, 'colour-science.org': {'colour': '0.4.1'}, 'Runtime': {'imageio': '2.22.0', 'matplotlib': '3.6.0', 'networkx': '2.8.6', 'numpy': '1.23.3', 'pandas': '1.4.4', 'scipy': '1.9.1'}})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions