gtaylor / python-colormath

A python module that abstracts common color math operations. For example, converting from CIE L*a*b to XYZ, or from RGB to CMYK
python-colormath.readthedocs.org
BSD 3-Clause "New" or "Revised" License
456 stars 82 forks source link

delta_e_cie2000 gives 3 different Calcualations #112

Open firaki12345-cmd opened 2 years ago

firaki12345-cmd commented 2 years ago

Hi, so i am using the following two rgb values to compare if they are similar (They are shades of light to mid dark green)

color1_rgb = sRGBColor(143,176,132)

color2_rgb = sRGBColor(140,184,164)

With Python code, i get the result

23.761947751526964

With Colormine website's delta_e_cie2000 Calculator http://colormine.org/delta-e-calculator/Cie2000

12.1502

With JavaScript Library http://zschuessler.github.io/DeltaE/

6.196918217607274

Now, i personally think the answers from the 2nd and third method make more sense as they are similar and hence difference is low. I am going by this table Below:

<= 1.0: Not perceptible by the human eye 1-2: Perceptible through close observation 2-10: Perceptible at a glance 11-49: Colors are more similar than the opposite 100: Colors are exactly the opposite

SO why so much difference in the result ? is there a way to use the website calculation or JS library calculation in python code

Thanks :)

KelSolaar commented 2 years ago

Make that 4!

I don't get the same value than Colormine nor the JS software with Colour but the CIE Lab values before Delta E computations are the same than Colormine:

Lab 1

>>> colour.convert(np.array([143, 176, 132]) / 255, 'Output-Referred RGB', 'CIE Lab', verbose={'mode': 'Long'}) * 100
===============================================================================
*                                                                             *
*   [ Conversion Path ]                                                       *
*                                                                             *
*   "cctf_decoding" --> "RGB_to_XYZ" --> "XYZ_to_Lab"                         *
*                                                                             *
===============================================================================
===============================================================================
*                                                                             *
*   [ "cctf_decoding" ]                                                       *
*                                                                             *
*   [ Signature ]                                                             *
*                                                                             *
*   <Signature (value, function='sRGB', **kwargs)>                            *
*                                                                             *
*   [ Conversion Output ]                                                     *
*                                                                             *
*   [ 0.27467731  0.43415364  0.23074005]                                     *
*                                                                             *
===============================================================================
===============================================================================
*                                                                             *
*   [ "RGB_to_XYZ" ]                                                          *
*                                                                             *
*   [ Signature ]                                                             *
*                                                                             *
*   <Signature (RGB, illuminant_RGB, illuminant_XYZ, matrix_RGB_to_XYZ,       *
*   chromatic_adaptation_transform='CAT02', cctf_decoding=None)>              *
*                                                                             *
*   [ Filtered Arguments ]                                                    *
*                                                                             *
*   {'cctf_decoding': {'return': array([ 0.27467731,  0.43415364,             *
*   0.23074005])}}                                                            *
*                                                                             *
*   [ Conversion Output ]                                                     *
*                                                                             *
*   [ 0.31017884  0.38556251  0.2763708 ]                                     *
*                                                                             *
===============================================================================
===============================================================================
*                                                                             *
*   [ "XYZ_to_Lab" ]                                                          *
*                                                                             *
*   [ Signature ]                                                             *
*                                                                             *
*   <Signature (XYZ, illuminant=array([ 0.3127,  0.329 ]))>                   *
*                                                                             *
*   [ Conversion Output ]                                                     *
*                                                                             *
*   [ 0.684286   -0.19674741  0.1894419 ]                                     *
*                                                                             *
===============================================================================
array([ 68.4286001 , -19.67474119,  18.94418956])

Lab 2

>>> colour.convert(np.array([140, 184, 164]) / 255, 'Output-Referred RGB', 'CIE Lab', verbose={'mode': 'Long'}) * 100
===============================================================================
*                                                                             *
*   [ Conversion Path ]                                                       *
*                                                                             *
*   "cctf_decoding" --> "RGB_to_XYZ" --> "XYZ_to_Lab"                         *
*                                                                             *
===============================================================================
===============================================================================
*                                                                             *
*   [ "cctf_decoding" ]                                                       *
*                                                                             *
*   [ Signature ]                                                             *
*                                                                             *
*   <Signature (value, function='sRGB', **kwargs)>                            *
*                                                                             *
*   [ Conversion Output ]                                                     *
*                                                                             *
*   [ 0.26225066  0.47932018  0.37123768]                                     *
*                                                                             *
===============================================================================
===============================================================================
*                                                                             *
*   [ "RGB_to_XYZ" ]                                                          *
*                                                                             *
*   [ Signature ]                                                             *
*                                                                             *
*   <Signature (RGB, illuminant_RGB, illuminant_XYZ, matrix_RGB_to_XYZ,       *
*   chromatic_adaptation_transform='CAT02', cctf_decoding=None)>              *
*                                                                             *
*   [ Filtered Arguments ]                                                    *
*                                                                             *
*   {'cctf_decoding': {'return': array([ 0.26225066,  0.47932018,             *
*   0.37123768])}}                                                            *
*                                                                             *
*   [ Conversion Output ]                                                     *
*                                                                             *
*   [ 0.34656547  0.42536765  0.41505782]                                     *
*                                                                             *
===============================================================================
===============================================================================
*                                                                             *
*   [ "XYZ_to_Lab" ]                                                          *
*                                                                             *
*   [ Signature ]                                                             *
*                                                                             *
*   <Signature (XYZ, illuminant=array([ 0.3127,  0.329 ]))>                   *
*                                                                             *
*   [ Conversion Output ]                                                     *
*                                                                             *
*   [ 0.71239428 -0.18824073  0.05407946]                                     *
*                                                                             *
===============================================================================
array([ 71.2394275 , -18.82407293,   5.40794591])

Delta E 2000: 8.4930367322829969

Our implementation is verified against Sharma (2004) but I should take a look at what is going on with Colormath, my assumption is that the input values are not interpreted correctly.

blue-j commented 2 years ago

Sharma is not identical to the standard. Maybe some are verifying against standard, others against Sharma?

KelSolaar commented 2 years ago

How is it not identical to the standard? Sharma (2004) is only providing implementation notes and additional data so that one can test its implementation.

firaki12345-cmd commented 2 years ago

thanks for the reply, sorry didn't see earlier as i got no notification for some reason

I hope the calculation gets fixed :)

blue-j commented 2 years ago

How is it not identical to the standard? Sharma (2004) is only providing implementation notes and additional data so that one can test its implementation.

I'll let Sharma himself reply:

http://www2.ece.rochester.edu/~gsharma/ciede2000/

He explicitly says he fixes discontinuities in the standard and that his implementation is not canonical. I believe it to be solid work and superior to the CIE formal spec personally.

KelSolaar commented 2 years ago

@blue-j : Have you actually read the page you just linked or his paper? There is, again, nothing saying that his work is different to the standard, quite the opposite, it is purposely authored to help and verify implementation of the standard.

blue-j commented 2 years ago

@blue-j : Have you actually read the page you just linked or his paper? There is, again, nothing saying that his work is different to the standard, quite the opposite, it is purposely authored to help and verify implementation of the standard.

Thank you for questioning this. It's been years since I read this! You are correct. I believed Sharma was presenting an alternative formulation that addressed the discontinuities he presents, but he does not. Please forgive my intrusion; my intention was to be helpful. - J

KelSolaar commented 2 years ago

No worries! :)

uriel-tannen commented 2 years ago

I'm also getting slightly different results when I compare colormath.color_diff.delta_e_cie1994 to ColorMine. When calculating the delta E between (255, 255, 255) and (237, 28, 36), I get 46.634 with colormath, and 45.2349 with ColorMine. Any explanation as to why results are different (and if one is more 'correct' / accurate than the other) would be most appreciated!