3 ms·
You almost always want to convert to CIELAB when doing things like averaging or interpolating colors. It is true that the sRGB gamut in CIELAB is not convex - t
by anchpop 7y ago
You almost always want to convert to CIELAB when doing things like averaging or interpolating colors. It is true that the sRGB gamut in CIELAB is not convex - this is less of an issue if you can use bigger color spaces like scRGB but that is often not the case. My advice in this case is to do as much as you can in LAB and then clamp your output to the range of values supported by your color space - i.e. if you get RGB(100, 300, -10) convert that to RGB(100, 255, 0). There are more sophisticated things you can do if you have to but this situation doesn't come up super often so it's not really worth the trouble in most cases.
- jfkebwjsbx 7y agoWhy not convert to linear sRGB (with higher bits per sample) instead? Something like what PNG supports for 16-bits. Does that give incorrect results too compared to going through CIELAB?
- anchpop 7y agoFor interpolation, averaging, etc. anything based on RGB is not going to give good results. For example, if you average pure red and pure blue, you should get something like pure purple. But if you do that in RGB you'll get #7f007f, a much darker color than either pure red or pure blue. If you do it with LAB, you'll get #ca0088, which is perceptually about as bright as either of the colors you started with.
- ThJ 7y agoIt helps to use linear gamma when manipulating RGB values. Linear gamma fixes most issues with interpolating and mixing RGB values and that’s also why most modern CG pipelines use it. It produces the most natural results.
- mark-r 7y agoYes linear gamma generates the most natural results, because that's the way physical light combines. Gamma was a great invention for display and transmission but it sure wrecked our ability to mix colors.
- jfkebwjsbx 7y agoThank you!
- tobr 7y agoThank you for the advice! I thought the appeal of HSLUV was that it has distorted CIELUV as little as necessary to map it perfectly onto three predictable parameters. Thus it would never require clamping. I was hoping there would be an official way to convert the hue/saturation to Cartesian coordinates without losing that benefit, but perhaps it wouldn’t be too hard to do myself.