luox-app / luox

Code base for the luox platform
https://luox.app/
GNU General Public License v3.0
14 stars 11 forks source link

Various fixes for uvToCorrelatedColourTemperatureRobertson function #28

Closed floehopper closed 3 years ago

floehopper commented 3 years ago

There were a couple of mistakes in the port from this Python code.

This latter point is why I haven't yet merged these fixes.

floehopper commented 3 years ago

I've now investigated the failing test which highlights a discrepancy with the data in the Hunt & Pointer book appendix...

I looks as if there was a transcription error in the u & v values copied from the book to the commit note. The commit note gives them as 0.3721, 0.3751 respectively, but I think those are the values for x & y. I think the u & v values should be 0.2202, 0.3331. See the screenshot below.

Screenshot 2021-01-14 at 11 38 25

When I correct those u & v values, I get a colour temperature of 4224.994. While this still doesn't exactly match the value in the book, it does exactly match the value returned from the Python colour-science package:

# python3 -m venv env
# source env/bin/activate
# pip install colour-science

import numpy as np
import colour

uv = np.array([0.2202, 0.3331])
result = colour.temperature.uv_to_CCT_Robertson1968(uv)
print(result) # => [  4.22499406e+03   1.92254317e-03]

Given that @chrislo wrote the following in the original commit note, I'm happy that it's OK to go with the fixed implementation in this branch, although I will of course update and thus fix the failing test.

I spent some time trying to track down the source of this error, including using a different implementation of the Robertson method in the R colorscience package[4]. This gave a different value again of 4223.8.

In the end, after discussion with Manuel, we decided to take into account the note in CIE015:2018 (p 39):

The computed correlated colour temperature is highly dependent on
specifications of the computing process though the variations are
insignificant in most practical applications... An agreement about
details of the computing method is necessary to avoid undesirable
discrepancies between computed correlated colour temperatures

And on page 71

Different rounding or calculation methods can produce a difference
of 2 K in the CCT and a difference of 1 in the colour rendering
indices and colour fidelity index.

We're confident that our implementation of Robertson's method agrees to within 2K of other implementations we could find.