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

New method: deltas() #437

Open
LeaVerou opened this issue Feb 14, 2024 · 3 comments
Open

New method: deltas() #437

LeaVerou opened this issue Feb 14, 2024 · 3 comments

Comments

@LeaVerou
Copy link
Member

When working on the gamut mapping playground recently, I needed to calculate deltas in OKLCh (differences per component) and ended up doing so by hand.

This seems like a more generally useful function. We have distance() and a bunch of deltaE() methods, but nothing that is done per-component.

What do you think?

@svgeesus
Copy link
Collaborator

svgeesus commented Mar 6, 2024

I realized that we claim to calculate ΔH but are in fact calculating Δh (the angle, not the length of the arc). What this means is that we over-emphasize the difference for near-neutrals and under-emphasize it for high chroma colors.

But yes a general method that gives the set of deltas is probably better and likely faster if the user calculates each one separately.

@LeaVerou
Copy link
Member Author

LeaVerou commented Mar 6, 2024

I realized that we claim to calculate ΔH but are in fact calculating Δh (the angle, not the length of the arc). What this means is that we over-emphasize the difference for near-neutrals and under-emphasize it for high chroma colors.

But yes a general method that gives the set of deltas is probably better and likely faster if the user calculates each one separately.

Oh that's really interesting. That would explain a lot in the GMA app.

@svgeesus
Copy link
Collaborator

It also strikes me that, for Οklab, calculating these gets you most the way to DeltaE OK and so there is a risk that these get calculated twice, for the common case where you want ΔΕ ΔL ΔC and ΔH. So I wonder if deltas should return an array of four items rather than 3.

But then, this is not the case at all for complex formulae like ΔE2000 so perhaps not.

Note too the optimization in ΔECMC:

let H2 = (Δa ** 2) + (Δb ** 2) - (ΔC ** 2);

and then ΔH is Math.sqrt(H2) and also

ΔE = Math.sqrt((ΔL ** 2) + (Δa ** 2) + (Δb ** 2))
= Math.sqrt( (ΔL ** 2) + (ΔC ** 2) + (ΔH** 2))
= Math.sqrt( (ΔL ** 2) + (ΔC ** 2) + H2)

which can be further optimized by keeping the values of those squares around rather than calculating them twice.

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