GithubHelp home page GithubHelp logo

L*a*b* <-> sRGB conversions? about d3-color HOT 5 CLOSED

d3 avatar d3 commented on April 20, 2024
L*a*b* <-> sRGB conversions?

from d3-color.

Comments (5)

danburzo avatar danburzo commented on April 20, 2024 2

Empirically, doing sRGB to Lab / LCh (now using the D50 standard illuminant as a reference white), gives me the following bounds:

lab

Channel Range Description
l [0, 100] Lightness
a [-79.2872, 93.55] Green–red component
b [-112.0294, 93.3884] Blue–yellow component

lch

Channel Range Description
l [0, 100] Lightness
c [0, 131.207] Chroma
h [0, 360] Hue

from d3-color.

danburzo avatar danburzo commented on April 20, 2024 1

Actually I was just investigating this exact same issue. In the library I'm working on, I'm following these instructions to convert Lab to RGB, and I'm getting slightly different values than from d3-color, but they seem to match Wolfram Alpha's.

May be related to the choice of iluminant? D3 takes note of D65, but the W3C steps include a conversion from D50 (Lab) to D65 (sRGB) white point.

To make matters even more confusing, the W3C spec (and the ICC.1:2004) use Xn = 0.9642, Yn = 1.0000, and Zn = 0.8249 for D50, while Wikipedia says they're Xn = 0.966797, Yn = 1.0000, and Zn = 0.825188 (citation needed?)]

😅

from d3-color.

danburzo avatar danburzo commented on April 20, 2024

Hi @mceachen, not all colors that can be described in L* a* b* are displayable, and it's expected for the R/G/B channels to go out of the normal bounds. color.displayable() will let you know when that's the case. (What you can do is clamp the R/G/B channels to [0, 255])

This color picker can give you a sense of when the colors get clipped.

from d3-color.

mbostock avatar mbostock commented on April 20, 2024

Yep, think this should be considered duplicate of #33. Also, it’s my understanding there’s no strict range to the allowed values in Lab space since it depends on your display gamut.

from d3-color.

mceachen avatar mceachen commented on April 20, 2024

OK, I'm clamping values. FWIW it seems that, with clamping, the RGB results match other implementations:

https://www.wolframalpha.com/input/?i=CIE+Lab+0,100,100
24-bit RGB | red 105 | green 0 | blue 0

https://www.wolframalpha.com/input/?i=CIE+Lab+50,-50,-50
24-bit RGB | red 0 | green 142 | blue 204

And from https://www.easyrgb.com/en/convert.php#inputFORM:

CIE-L*ab (D65/2°) = 50 -50 -50
sRGB   0-255 = -868.512  143.165  203.450    D65/2°

Perhaps this warrants a note in the README?

from d3-color.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.