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

Unnecessary multiply and divide in calculation of F_L #27

Open
nick-shaw opened this issue May 29, 2024 · 4 comments
Open

Unnecessary multiply and divide in calculation of F_L #27

nick-shaw opened this issue May 29, 2024 · 4 comments

Comments

@nick-shaw
Copy link
Collaborator

nick-shaw commented May 29, 2024

In the calculation of the viewing condition dependent F_L value in the forward and inverse Hellwig conversion there is a multiply by 0.2 followed immediately by a multiply by 5.0. These clearly cancel out to 1.0, but could introduce precision issues in different implementations.

@nick-shaw
Copy link
Collaborator Author

This also happens in the Hellwig_J_to_Y() and Y_to_Hellwig_J() functions.

@nick-shaw
Copy link
Collaborator Author

It's also worth noting that currently this F_L calculation happens four times per pixel, when in fact it could be precomputed once globally.

@nick-shaw
Copy link
Collaborator Author

Taking it further, at single precision float, the whole complexity of incorporating k and k4 in the calculation of F_L has no effect whatsoever. Three lines could be replaced with a simple:

F_L = pow(L_A / 200, 1 / 3)

which in our case, where L_A = 100, is simply 1 / cbrt(2).

@KelSolaar
Copy link

I was discussing with Nick and it seems advisable to use an approximation here, especially because $L_A$ is kept constant at a rather high value. The full equation really starts to noticeably deviate at low values:

>>> import colour
>>> f = lambda x : (x / 200) ** (1/3)
>>> f(100)
0.7937005259840998
>>> colour.appearance.hunt.luminance_level_adaptation_factor(100)
0.79370052754616727
>>> f(10)
0.3684031498640387
>>> colour.appearance.hunt.luminance_level_adaptation_factor(10)
0.36840451910550759
>>> f(1)
0.17099759466766973
>>> colour.appearance.hunt.luminance_level_adaptation_factor(1)
0.17150541623653787
>>> f(0.1)
0.07937005259840998
>>> colour.appearance.hunt.luminance_level_adaptation_factor(0.1)
0.070863964674330454

I would just keep a reference/note to the full equation.

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

No branches or pull requests

2 participants