如何在 CIE-XYZ 色彩空间中改变色调?
我需要在CIE颜色空间内实现自己的色调旋转功能。我找不到有关如何完成的技术描述。我发现了高水平的描述,例如“围绕XYZ色彩空间的Y轴旋转”,这是有道理的,因为Y是亮度。
我很快做了一个愚蠢的矩阵旋转:
vec3 xyz = rgb_to_cie_xyz(color.r, color.g, color.b);
vec3 Y_axis = vec3(0,1,0);
mat4 mat = rotationMatrix(Y_axis, hue_angle);
vec4 res_xyz = mat * vec4(xyz, 1.0);
vec3 res = cie_xyz_to_rgb(res_xyz.x, res_xyz.y, res_xyz.z);
但是后来意识到更多关于CIE空间的信息是完全错误的。
所以我的问题是:A。如何在CIE/XYZ中旋转色调?
或B.我应该从XYZ转换为CIE LCH,然后更改H(色调),然后转换回XYZ? (如果我能找到它的功能,这听起来很容易,但是它甚至可以正确 /等同于XYZ中的色调吗?)
还是C。我是否应该从XYZ转换为这个2d-Xy Cie-Xy-Xyy Color Space?您如何旋转色调?
[edit]
我已经为ex 另一个来源& /blob/master/src/js/convert.js“ rel =“ nofollow noreferrer”>另一个来源也计划从xyz到实验室转换为lab,更改色调,然后更改LCH,然后LCH到实验室到XYZ。但这似乎并没有往返。 XYZ-实验室-XYZ -RGB工作正常,看起来相同。但是XYZ -LAB -LCH -LAB -XYZ -RGB断裂;结果颜色与源颜色完全不同。这不是这样使用的(例如,这仅是一种方式吗?),我在误会什么?
vec3 xyz = xyzFromRgb(color);
vec3 lab = labFromXyz(xyz);
vec3 lch = lchFromLab(lab);// doesn't work
//lch.z = lch.z + hue;
lab = labFromLch(lch);// doesn't work
xyz = xyzFromLab(lab);
vec3 rgb = rgbFromXyz(xyz);
我的完整代码: https://github.com/gka/gka/gka/chroma.js/issues/ 295
资源:
XYZ系统基于颜色匹配实验。 x,y和z是 RGB的外推数学创建以避免负数 并称为tristimulus值。此模型中的X值表示 大约是颜色的红色/绿色部分。 Y值代表 大约轻度和z值大致对应于 蓝色/黄色部分。
- cie lab and cie lab and cie lch ::::::::
l c h彩色空间,类似于cielab,有些人优先 行业专业人士,因为其系统与 人眼可感知颜色。它的图与l a b*颜色相同 空间,但使用圆柱坐标代替矩形 坐标。
在此颜色空间中,l*表示轻度,c*表示色度,并且 H是色调角。色度C*的值是距离距离的距离 轻度轴(L*),中心为0。色调角开始 +a*轴并以度表示(例如,0°为 +a*或红色,并且 90°是 +b,或黄色)。
- cie xyz (变换矩阵)
I need to implement my own hue rotation function within the CIE color space. I can't find any technical descriptions of how this is done. I found high level descriptions like "rotate around the Y axis in the XYZ color space", which makes sense because Y is the luminance.
I quickly did a dumb matrix rotation:
vec3 xyz = rgb_to_cie_xyz(color.r, color.g, color.b);
vec3 Y_axis = vec3(0,1,0);
mat4 mat = rotationMatrix(Y_axis, hue_angle);
vec4 res_xyz = mat * vec4(xyz, 1.0);
vec3 res = cie_xyz_to_rgb(res_xyz.x, res_xyz.y, res_xyz.z);
But later realized it's completely wrong learning more about cie space.
So my question is: A. How do you rotate hue in CIE/XYZ?
or B. Should I convert from XYZ to CIE LCH and change the H (hue) there, and then convert back to XYZ? (that sounds easy if I can find functions for it but would that even be correct / equivalent to changing hue in XYZ?)
or C. should I convert from XYZ to this 2D-xy CIE-xyY color space? How do you rotate hue on that?
[EDIT]
I have implemented for ex this code (tried another source & another source too), planning to convert from XYZ to LAB to LCH, change hue, then LCH to LAB to XYZ. But it doesn't seem to make the round trip. XYZ - LAB - XYZ - RGB works fine, looks identical. But XYZ - LAB - LCH - LAB - XYZ - RGB breaks; result color is completely different from source color. Is it not meant to be used like this (e.g. is it one way only?), what am I misunderstanding?
vec3 xyz = xyzFromRgb(color);
vec3 lab = labFromXyz(xyz);
vec3 lch = lchFromLab(lab);// doesn't work
//lch.z = lch.z + hue;
lab = labFromLch(lch);// doesn't work
xyz = xyzFromLab(lab);
vec3 rgb = rgbFromXyz(xyz);
my full code: https://github.com/gka/chroma.js/issues/295
Resources:
XYZ system is based on the color matching experiments. X, Y and Z are
extrapolations of RGB created mathematically to avoid negative numbers
and are called Tristimulus values. X-value in this model represents
approximately the red/green part of a color. Y-value represents
approximately the lightness and the Z-value corresponds roughly to the
blue/yellow part.
The LCh color space, similar to CIELAB, is preferred by some
industry professionals because its system correlates well with how the
human eye perceives color. It has the same diagram as the Lab* color
space but uses cylindrical coordinates instead of rectangular
coordinates.In this color space, L* indicates lightness, C* represents chroma, and
h is the hue angle. The value of chroma C* is the distance from the
lightness axis (L*) and starts at 0 in the center. Hue angle starts at
the +a* axis and is expressed in degrees (e.g., 0° is +a*, or red, and
90° is +b, or yellow).
- How to convert between rgb and CIE XYZ (transformation matrixes)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CIE颜色具有很多表示和子代表,并且在互联网周围没有可视化或在技术上或始终如一地进行可视化或解释。改变色调的唯一方法是从CIE XYZ到CIE实验室,然后转变为可转移的圆柱色调表示,即CIE LCH。
从(RGB-)XYZ -LAB -LCH -lab -XYZ(-RGB)转换只是为了改变色调,是正常的,到处都是,尽管很难在网上找到项目 /代码,特别是在线说他们在“更改”在CIE色彩空间中的色调”,甚至根本没有“色调”一词。奇怪的是,您在GitHub上找不到任何可以直接转换为从XYZ转换为LCH或HSV到LCH的任何项目,鉴于有多少个项目链中的中间步骤融合了CIE颜色,并且Web是过渡到使用LCH颜色空间。
我在搜索Lablch时发现了这个出色的阴影: https://wwww.shadertoy.com/view/view/view/lsdgzn < /a>,可为LCH和LCH提供有效且合并的XYZ,以供XYZ转换。 ❤️
它中有很多魔术数字,因此,通过使用它,我仍然没有弄清楚我的代码/端口有什么问题,但是其他人也遇到问题。我正在做Atan2正确,浮动,矩阵Mults正确等等。qus
CIE color has a lot of representations and subrepresentations, and it's not visualized or explained technically or consistently around the internets.. After reading many sources and checking many projects to converge on a clear picture, and as Giacomo said in the comments, yes, it seems the only way to change hue is to go from CIE XYZ to CIE LAB and then into a cylindrical hue shiftable representation which is CIE LCH.
The conversion from (RGB -) XYZ - LAB - LCH - LAB - XYZ (- RGB) just to change the hue, is normal and done everywhere, although it's very hard to find projects / code online that specifically say they're "changing hue in CIE color space" or that even have the word "hue" in them at all. It's also strange that you cannot find anything on github that converts straight up from XYZ to LCH or HSV to LCH given how many projects chain the intermediate steps to blend CIE colors, and the fact that the web is transitioning to using LCH color space.
I found this brilliant shadertoy while searching for lablch: https://www.shadertoy.com/view/lsdGzN which offers efficient and merged XYZ to LCH and LCH to XYZ conversions. ❤️
It has a lot of magic numbers in it though so by using it, I still haven't figured out what was wrong with my code/ports, but others are having issues too. I'm doing atan2 right, floats right, matrix mults right etc. ????♂️ I'll update my answer when I get around to figuring it out.
[Edit] It seems the problem here is there is loss of information going through all these color spaces and a lot of assumptions or approximations must happen to make a round trip. Shadertoy person prolly did some magic. Have to investigate further when I need to.