Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
volrak opened this issue Oct 13, 2023 · 3 comments
Closed

Comments

@volrak
Copy link

volrak commented Oct 13, 2023

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'}})
@volrak volrak added the Defect label Oct 13, 2023
@KelSolaar
Copy link
Member

Hi @volrak,

Thank you, this is rather unfortunate the subtraction produces that. I'm wondering if we should not take the absolute value rather than clamping to zero. I will check if the CIE has some recommendations for that.

Cheers,

Thomas

@KelSolaar
Copy link
Member

Implementation note from Bruce Lindbloom:

image

http://www.brucelindbloom.com

@KelSolaar KelSolaar changed the title [BUG]: Exception/nan in delta_E_CIE1994() [BUG]: *nan* are generated by colour.difference.delta_E_CIE1994 definition. Oct 13, 2023
@KelSolaar KelSolaar added this to the v0.4.4 milestone Oct 13, 2023
@KelSolaar
Copy link
Member

Looked at most implementations and everybody seems to be clamping. I have seen only one implementation that takes the absolute value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants