Skip to content

[css-color-4] Should we recommend DeltaE OK2 over the original DeltaE OK? #14207

Closed

Description

@svgeesus

Delta E is a class of algorithms to measure the actual perceived difference between two colors.

ΔEOK2 is a slightly modified version of the existing ΔEOK which scales the a and b axes by a factor of 2
as recommended by Björn Ottosson, inventor of Oklab:

Adjust the scaling of a&b to more accurately predict color distances

He also said

I unfortunately didn't spend that much time calculating and validating that scaling factor when I first derived Oklab since I was mostly focused on the orthogonality between L, C and h (and I didn't expect it to become so widespread so quickly), and it seems like it is off by quite a bit.
I've recently done some tests with color distance datasets as implemented in Colorio and on both the Combvd dataset and the OSA-UCS dataset a scale factor of slightly more than 2 for a and b would give the best results (2.016 works best for Combvd and 2.045 for the OSA-UCS dataset).

So instead of changing the definition of Oklab, which is now widely adopted, the proposal is to make another distance metric, ΔEOK2, if it is demonstrably better then ΔEOK.

Experimental verification

I generated a synthetic dataset of normally distributed base colors (so, favoring more common low-chroma colors but including wide-gamut colors). Colors outside rec2020 were eliminated. I then produced, for each color in the dataset, a group of similar colors by perturbing the lightness, chroma and hue (again, normally distributed).

To avoid any dependence on Oklab itself, the base colors were generated in CAM16 JMh as were the derived colors. Here is a plot of the base colors, converted to Oklab

Image

SVG

I then compared the well established (but computationally complex) ΔE2000 with the existing ΔEOK and proposed ΔEOK2.

For those who want to study the verification in detail, see the detailed description.

Results

The correlation coefficient (higher is better) and the line of best fit were calculated.

Image

SVG of ΔE2000 vs ΔEOK

Image

SVG of ΔE2000 vs ΔEOK2

Conclusion

ΔEOK2, which is ΔEOK with the Oklab a and b axes scaled by 2, agrees with the highly-regarded but computationally complex ΔE2000 noticeably better than ΔEOK does (correlation coefficient r² 0.722 vs 0.642 on 5000 BT.2020 color
pairs). Scaling the a/b axes by 2 is a measurable improvement, supporting Ottosson's recommendation. It remains computationally simple and fast.

Proposed resolution: add ΔEOK2 to CSS Color 4 and recommend it over ΔEOK.

Activity

  1. svgeesus commented on Jul 20, 2026

    @svgeesus
    CollaboratorAuthor
  2. facelessuser commented on Jul 20, 2026

    @facelessuser
    Contributor

    I would note that when using MINDE chroma reduction, which specifically relies on color distancing, at most lightness ranges, hue shift is lessened when using OK2 vs OK, which is a good thing.

    This doesn't affect GMA approaches that do not rely on distancing: Ray Trace, Edge Seeker, Cubic solvers (Halley, Cardano, etc.).

    It seems from the bit I've looked into ∆E OK2 that it does seem to be a better approach.

  3. facelessuser commented on Jul 24, 2026

    @facelessuser
    Contributor

    One small note, if the goal is to increase r^2, the only other easy thing you could do is apply the Oklrab toe function to the lightness of both colors. This makes the lightness closer to CIE Lab; therefore, making the r^2 value closer.

    Image

    Edit: Updated with the image that corresponds to the OkLrab toe function. I was playing around with the toe function coefficients. It can certainly be tuned even closer to CIE Lab, raising the r^2 value a bit more; that's what I first posted, but not what I meant to represent here.

  4. svgeesus commented on Jul 24, 2026

    @svgeesus
    CollaboratorAuthor

    the only other easy thing you could do is apply the Oklrab toe function to the lightness of both colors

    Interesting. I have wondered for some time if CSS should add Oklrab and Oklrch. They seem to work better in light mode, while the existing Oklab and Oklch work fine in dark mode (where the page background is not the primary adaptive stimulus). The downside is that Lr is more computationally complex than L; that downside would also apply to a ΔE that used Oklrab.

  5. facelessuser commented on Jul 24, 2026

    @facelessuser
    Contributor

    Interesting. I have wondered for some time if CSS should add Oklrab and Oklrch. They seem to work better in light mode, while the existing Oklab and Oklch work fine in dark mode (where the pge background is not the primary adaptive stimulus). The downside is that Lr is more computationally complex than L; that downside would also apply to a ΔE that used Oklrab.

    Yep, definitely more complex, but not drastically so. Either way, I thought it was something interesting to point out.

  6. svgeesus commented on Jul 29, 2026

    @svgeesus
    CollaboratorAuthor

    the only other easy thing you could do is apply the Oklrab toe function to the lightness of both colors. This makes the lightness closer to CIE Lab; therefore, making the r^2 value closer.

    I updated the investigation to add that as well. Oddly the unscaled ΔEOKr was a bit worse than unscaled ΔEOK, while scaled ΔEOKr2 was better than scaled ΔEOK2.

  7. facelessuser commented on Jul 29, 2026

    @facelessuser
    Contributor

    Oddly the unscaled ΔEOKr was a bit worse than unscaled ΔEOK, while scaled ΔEOKr2 was better than scaled ΔEOK2.

    I guess that doesn't surprise me. I'm sure the lightness helps "on average". The distance of every color doesn't necessarily correlate better with ∆E2000, but on average it does, but only when values aren't so skewed away from ∆E2000. So requiring both adjustments kind of makes sense to me.

    In this experiment, I was tweaking the toe function to better match LCh lightness across the board for tonal palettes. Nothing fancy, just adjusting the coefficients.

    When I applied the tweaked toe function values after the doubling of the ∆a and ∆b, it improved a little more. Nothing drastic, but just a little more. But of course, this only applies with ∆a and ∆b correction as well.

    K1 = 0.173
    K2 = 0.004
    K3 = (1.0 + K_1) / (1.0 + K_2)
    
    Image

    I haven't looked any further than noting that the r^2 value improves. So, it seems, as long as the ∆a and ∆b are skewed more favorably with ∆E2000, adjusting ∆L to look more like LCh also improves the r^2 (on average).

  8. moved this from Agenda+ FTF to Thursday Morning in CSSWG summer 2026 meeting agendaon Aug 1, 2026
  9. svgeesus commented on Aug 4, 2026

    @svgeesus
    CollaboratorAuthor

    Related question is whether to add Oklrab (and Oklrch) as supported color spaces. I made a little comparison app

  10. css-meeting-bot commented on Aug 6, 2026

    @css-meeting-bot
    Member

    The CSS Working Group just discussed [css-color-4] Should we recommend DeltaE OK2 over the original DeltaE OK?, and agreed to the following:

    • RESOLVED: Add ok2r as distance measure
    The full IRC log of that discussion <TabAtkins> ChrisL: Do people know what deltaE is?
    <TabAtkins> ChrisL: okay, it's a measure of how different two colors are
    <TabAtkins> ChrisL: if they're the same it's 0, then it gets larger
    <TabAtkins> ChrisL: And you want it to correspond well to human vision
    <TabAtkins> ChrisL: different measures do this better or worse
    <TabAtkins> ChrisL: so the industry generally uses deltaE2000, the fourth iteration of some ISO standard
    <TabAtkins> ChrisL: it's in the appendix for how to do it in JS. it's slow but it gets results
    <TabAtkins> ChrisL: we also have deltaEOK, which is just geom distance between the points in oklab, it's all right but very fast
    <TabAtkins> ChrisL: oklab creator said a and b axises are too short
    <TabAtkins> ChrisL: he did some experiments, and found the correction ratios were 2-ish
    <TabAtkins> ChrisL: I tested this
    <TabAtkins> ChrisL: in the issue you'll see a scatter plot, I generated a synthetic scatterplot
    <TabAtkins> ChrisL: for each point a spread of values and measured their distance in dE2000 and dEOK and dEOK2, the scaled one
    <TabAtkins> ChrisL: you'll see the residual line looks better for the new one
    <TabAtkins> (deOK2 matches dE2000 better)
    <TabAtkins> ChrisL: so I was ready to suggest switchin, then a new commenter
    <TabAtkins> ChrisL: dEOK assumes the color si by itself, basically dark mode. but it's usually against white, you need a different curve
    <TabAtkins> ChrisL: theres' a variant okLRAB, so dEOK2LR, the scatterplot is even better
    <florian> q+
    <TabAtkins> ChrisL: so, do we go for the good enough ok2, or do we add the even better one
    <TabAtkins> ChrisL: and if we do the better deltaE, do we add it just as that, or as a color space too?
    <TabAtkins> astearns: can you tell me what that Algo does in the spec?
    <TabAtkins> ChrisL: it's used for any color measurement stuff, like the gamut mapping
    <TabAtkins> kbabbitt: will this impact contrast-color()?
    <TabAtkins> ChrisL: no, it's not affecting the lightness plane
    <TabAtkins> astearns: your first analysis didn't consider perceiving the color on a light background. is it only on a white background or is it also good on darker?
    <TabAtkins> ChrisL: that's the thing. oklab is better on darker bgs
    <TabAtkins> ChrisL: let me pull up a link...
    <ChrisL> https://github.com/svgeesus/deltaE-OK2/tree/main
    <TabAtkins> ChrisL: this is the repo where I did all of this
    <TabAtkins> ChrisL: you can see there if you scroll a bit, there are four plots
    <TabAtkins> ChrisL: deOK vs 2000, not great. ok2 is definitely better
    <TabAtkins> astearns: and 2000 is in the spec?
    <romain> q+
    <TabAtkins> ChrisL: it's in the spec as the "best" but we don't recommend it because it's expensive. currently deOK is what we recommend
    <florian> q?
    <ChrisL> https://apps.colorjs.io/lr-vs-l/?color1=%2300000F&color2=black
    <TabAtkins> ChrisL: and to help people understand, I made another app
    <TabAtkins> ChrisL: it lets you compare interpolation in oklab vs oklrab
    <TabAtkins> ChrisL: and lets you swap bg from black to white
    <TabAtkins> ChrisL: but that's more for "should we add this as another color space"
    <TabAtkins> florian: some qs. how important is it that we measure the same way others do? how problematic/un is it to have a moving target?
    <TabAtkins> florian: do we break compat over time?
    <TabAtkins> florian: and another q, is there a worldview where it could make sense to have the author supplying their own function?
    <TabAtkins> ChrisL: measuring the same way as others isn't quite the way to put it. we'r measuring how different two colors appear. we have the "good" Algo that's slow and an okay one in the spec we use. gamut mapping needs good and fast.
    <TabAtkins> ChrisL: the impact on gamut mapping will be slight, I think. not major, but slightly better.
    <TabAtkins> florian: so if we don't match Photoshop or something it wont' really matter?
    <TabAtkins> ChrisL: not much, no. small details. at some point, invisible details
    <TabAtkins> florian: so if in a few years we come up with something slightly better it's okay to switch?
    <TabAtkins> ChrisL: right
    <TabAtkins> ChrisL: and note ATM there are 3 algos in the spec and we let impls choose, so there's already possible variation.k they're all extremely better than channel clipping.
    <TabAtkins> astearns: this would replace one of the algos?
    <TabAtkins> ChrisL: I'd probably leave them in, just recommend the new ok2 algo
    <TabAtkins> ChrisL: i'd change the gamut mappers to use ok2
    <astearns> ack florian
    <TabAtkins> ChrisL: 2000 is in the spec for understanding, but we don't actually use it, same thing
    <astearns> ack romain
    <TabAtkins> romain: I agree
    <TabAtkins> romain: clarify, most gamut mapping algos, particular the favored ones, dont' use this at all
    <TabAtkins> romain: only the original do
    <TabAtkins> romain: ray-tracing and edge-seeker dont' need this anyway
    <TabAtkins> ChrisL: right, those don't measure how far out you are, they just compute an intersection. they don't need to measure distance
    <TabAtkins> ChrisL: this'll also help gradients, it's a better linearity measurement
    <TabAtkins> ChrisL: so an evenly-spaced ramp of colors it'll give a better result
    <TabAtkins> astearns: so decisions?
    <TabAtkins> ChrisL: 1) yes, the spec should use ok2 rather than ok
    <TabAtkins> ChrisL: but should it just use ok2, or the lr variant that's slightly better against white?
    <kbabbitt> q+
    <TabAtkins> ChrisL: 2) last, happy to be a separate issue, should we add this color space to the spec?
    <astearns> ack kbabbitt
    <TabAtkins> kbabbitt: i'm hearing there's a good Algo, a better, and an even better
    <TabAtkins> kbabbitt: what's the downside of adopting the even better one?
    <TabAtkins> ChrisL: don't see one if it's just the distance measurement
    <TabAtkins> ChrisL: slightly more complex computationally but not bad, especially compared to 2000
    <TabAtkins> kbabbitt: i'm concerned because it will show up in color conversions, so perf is a concern
    <TabAtkins> ChrisL: won't show up at all yet, since it's not a color space you can use, so no conversions
    <TabAtkins> ChrisL: my preference is to go ahead and use the ok2lr, then open a separate issue about the new color space
    <TabAtkins> astearns: sounds good
    <TabAtkins> PROPOSED: Add ok2r as distance measure
    <TabAtkins> RESOLVED: Add ok2r as distance measure
  11. svgeesus commented on Aug 6, 2026

    @svgeesus
    CollaboratorAuthor
  12. facelessuser commented on Aug 6, 2026

    @facelessuser
    Contributor

    @svgeesus does this mean ΔEOKr2 (was it meant to be ΔEOKLr2?) should be the recommendation for the MINDE gamut mapping approach?

  13. svgeesus commented on Aug 7, 2026

    @svgeesus
    CollaboratorAuthor

    does this mean ΔEOKr2 (was it meant to be ΔEOKLr2?) should be the recommendation for the MINDE gamut mapping approach?

    Yes, but I didn't make that edit yet because I want to do some testing in color.js first.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    ⌂ 换网址