color-js / color.js

Color conversion & manipulation library by the editors of the CSS Color specifications
https://colorjs.io
MIT License
1.87k stars 82 forks source link

DIN99 Color Space #102

Open Crissov opened 3 years ago

Crissov commented 3 years ago

I know next to nothing about its usefulness or popularity, but it seems like something that could make sense to add: DIN 6176:2001-03 (in German Wikipedia).

Crissov commented 3 years ago

I just realized that the 2018 edition of DIN 6176 changes the parameters from the 2001 values, e.g. rotation by 26° instead of 16°, and refers to it by DIN99o. The German Wikipedia article should now document both variants.

Crissov commented 2 years ago

PS: DIN 6176 offers a near-spherical color space for simple ΔE calculation by Euclidian distance, like default color.deltaE(), with results similar to CIE94 (for DIN99) and CIEDE2000 (DIN99o), i.e. much better than CIELAB following ISO 11664 rules.

Related: #10, #33, #37

facelessuser commented 2 years ago

I'm not sure if Colorjs.io intends to implement every color space out there. I get the impression it mainly focuses on CSS color spaces and research associated with future CSS color solutions.

I believe you could just extend it with a plugin and add it with Color.defineSpace. that seems to be how all other spaces are added. It's not a complicated color space to implement IIRC. I implemented it for a library I maintain just to play around with it.

I did slightly tweak one thing though. The lightness is given with:

 L99o = (303.67 * ln(1 + 0.0039 * L*)) / KE

This yields a lightness of 99.99966889479344, which is fine, but these constants were rounded off. You can calculate a more precise lightness by solving for it with 100% lightness.

303.67 = 100 / ln(1 + 0.0039 * 100)
303.67 = 100 / ln(1.39)

It ends up being 303.67100547050995 which gives you a nice even 100 for lightness.

facelessuser commented 2 years ago

I'll also note that the wiki page has a chart of conversion examples, and talks about using D65, but those results are in D50. That's the only way to get those results. I implemented the space using D65 though.

Crissov commented 2 years ago

I actually considered to write a custom deltaEDIN() function (or two), but since it’s really just the default Euclidean distance I thought it may make more sense to add the whole color space explicitly.

facelessuser commented 2 years ago

Yeah, adding the space makes sense as you have to do the full conversion to the space anyways. You should be able to define it as an object and add it, and then do the same with a new delta E method. I cannot speak expressly for this project, and I don't have a full grasp on the goals outside of this being a playground for CSS research. That's the only reason why I suggest writing a plugin for the color space and then registering a new delta E may get you their faster. They might accept a pull if you do this, though it could also not fit the plan/goals and you'd just have keep it separate, but either way, you'd at least have access to what you are looking for as you will have already implemented it 🙂.

DINN99o simply augments the CIELAB color space to a more agreeable shape to use Euclidean distance instead of delta E 2000 which takes the lab color space and essentially builds the compensation into the delta E algorithm. Both are trying to compensate for the fact that CIELAB is not quite ideally shaped for Euclidean distance, they just do it in different ways. Compensation baked into the space vs the distance algorithm, but both go through CIELAB.

LeaVerou commented 2 years ago

We'd be happy to merge this as an optional plugin.

But this makes me think we need to somehow attach deltaE methods to color spaces, since they often come together (even when it's not a simple Euclidean distance, see deltaOK)

Crissov commented 7 months ago

For what it’s worth, https://github.com/Evercoder/culori does support DIN99 and some other spaces. https://github.com/colorjs/color-space does not support this one, but others..

rumpelrausch commented 7 months ago

DIN99 is meant for fast color distance calculation (in the range of small distances). The latest iteration is not DIN99o because it still has problems with blue colors, e.g. for some blue colors purple appears closer than other blue ones.

DIN99c and DIN99d are probably the best color spaces for fast euclidian distance calculations (as of today). Think matching amounts of colors in a database: You wouldn't want to implement CIE2000 in SQL.

DIN99 is virtually unknown within the English language based communities and academics. Modifying the color space in order to allow unified distancies is also the approach of OKLab. In comparison to DIN99c/d it also has problems with blue/purple and red/pink distancies. However, OKLab performs well synthesizing similar colors and gradients (is part of CSS now), but DIN99c/d promises to be better in measuring distancies.

The best formula source I could find so far: https://tuprints.ulb.tu-darmstadt.de/5870/13/D17%20Einfluss%20der%20Normspektralwertfunktionen%20_final_digital.pdf, pages 29ff. It's in German language, alas.

Problem with DIN99c/d implementation: You can't just convert from CIELab to DIN99c; They introduced a modified CIELab' calculation which slightly shifts the X value.


BTW, culori doesn't support DIN99c/d either, they do DIN99b (which has the blue problems).