What are OKLCH colors?
68 points by susam
68 points by susam
Seems like it would be reasonable to link or credit the original post by Björn Ottosson that describes the design of the OkLab color space: https://bottosson.github.io/posts/oklab/
I like OkLab/OkLCh so much, I used it to make a Neovim colorscheme to try and find maximally-distinguishable color hues with consistent color contrast for readability.
More color pickers:
Hah, that’s exactly how I made my own terminal colorscheme (analogous to your “smooth” scheme). Though I used CieLab because OkLab didn’t exist at the time: https://justinpombrio.net/archive/terminal-colors.html
your colorscheme looks similar to modus-themes, which also has a goal of being maximally-distinguishable
i wonder if both of you used the same approach!
It looks nice.
So can a colorspace like this effectively give a metric or distance between any two colors? If so, can we define a “geodesic” or path of least distance between two points to define the gradient? The gradient does seem to take an unexpected detour and I suspect that we could get a better result by thinking harder about it.
Euclidean distance on any color space tends to not work for large distances: https://en.wikipedia.org/wiki/Color_difference
Well - I think that’s exactly my point!
A curved manifold doesn’t actually support any coordinate transform to coordinates that support a Euclidean distance. We keep talking about “distance in colorspace is complicated” and ignoring “distance is colorspace may be curved / non-Euclidiean” and all the known maths around non-Euclidean spaces.
I suppose I am hypothesizing that a metric (distance between any two colors) can be defined and computed, that the resultant geometry has non-zero curvature, and the current techniques (gradients being linear interpolants in some colorspace) are not general enough to support this.
So can a colorspace like this effectively give a metric or distance between any two colors?
There are near-uniform colorspaces that you can use to get an accurate euclidean distance between colors. They aren’t truly uniform, so they don’t work if you want absolute accuracy (and if you find a color space that is perfectly uniform, you should publish a paper and become a renowned scientist.)
If so, can we define a “geodesic” or path of least distance between two points to define the gradient? The gradient does seem to take an unexpected detour and I suspect that we could get a better result by thinking harder about it.
Fundamentally, a color gradient is just linear interpolation between the two points in whatever colorspace you use. The LCH colorspace end up interpolating hue, which means you end up passing through other colors. The LAB colorspace fades the color out and in if your two points are on different sides. The boring answer here is that there are no “correct” way of doing gradients unless your two points are very close to each other.
I am proposing that if we could (experimentally or otherwise) quantify how “different” any two colors are, then we define a metric. The resultant geometry can be expressed in lots of different coordinate systems (like RGB vs HSL) but there are quantities like curvature which are independent of choice of coordinate system.
Only if curvature is zero everywhere can you say the geodesic / path of least distance between two colors is a straight line in some possible coorinate system. If it is nonzero, then actually this is not true… the gradient should really follow some curve in order to produce a spectrum of colors which interpolate two values while “travelling” least - what I am postulating as the most “natural looking” or “least suprising” colors to find in between (the “best” gradient).
If you define “a gradient is a linear interpolation in some coordinate system” you actually restrict yourself from a whole spectrum (pun not intended) of possibility. You might find a coordinate system that works well locally everywhere, or non-locally between some colors you use often, but not globally between any two colors. (This is just a simple fact about curved manifolds - and also an observation about color spaces and gradients used in practice).
Fundamentally, color is just a frequency on the light spectrum. This is then interpreted by our eyes and brains (barring things like color blindness) mostly the same between humans. All colorspaces are just ways to try to bake this process into some N-dimensional space. All colorspaces are completely artificial constructs.
Only if curvature is zero everywhere can you say the geodesic / path of least distance between two colors is a straight line in some possible coorinate system. If it is nonzero, then actually this is not true… the gradient should really follow some curve in order to produce a spectrum of colors which interpolate two values while “travelling” least - what I am postulating as the most “natural looking” or “least suprising” colors to find in between (the “best” gradient).
I’m not versed in non-euclidian geometry beyond a quick read on Wikipedia, but this seems prima facie wrong on account of colorspaces being completely artificial, because whatever curve you come up with for the gradient, a colorspace can be constructed in which that curve is flattened to a straight line, as a colorspace is fundamentally just some mathematical formulas to turn N numbers into varying amounts of light. It can self-intersect, it can repeat, it can do basically anything you can express mathematically. You’ll probably sacrifice other properties, but that’s already something every colorspace does, almost all our colorspaces are already non-euclidian when actually projected to “real” color.
related: a slightly more thorough read that also goes into detail in how to use this on the web (css, svg, …):