Conversion between RGB and RYB color spaces

混江龙づ霸主 提交于 2019-11-27 19:54:10
Ben

I managed to solve it in the end.

Take the equations for a trilinear interpolation: wikipedia

Substitute the first equations into the last, the expand and collect the coefficients for: Xd, Yd, Zd, XdYd, XdZd, YdZd, ZdYdZd and the constant.

Then find the partial differentiation of the equation in each of the 3 dimensions each in respect to Xd, Yd and Zd. Use these new equations to populate the (3x3) Jacobian matrix and then use Newton's method to solve in software.

Newton-Raphson Method

Here is a category on UIColor that does the same thing, returning elements between RGB, RYB, and CMYK. Further, you can mix any number of colors in the respective color space (they mix differently, of course, depending).

https://github.com/ddelruss/UIColor-Mixing

Enjoy,

Damien

I found this JavaScript implementation of RYB->RGB conversion based on cubic splines. Here is my Lua port (all values lie in the interval 0-1):

local ryb2rgb = function( R, Y, B ) 
  local R, Y, B = R*R*(3-R-R), Y*Y*(3-Y-Y), B*B*(3-B-B)
  return 1.0 + B * ( R * (0.337 + Y * -0.137) + (-0.837 + Y * -0.163) ),
    1.0 + B * ( -0.627 + Y * 0.287) + R * (-1.0 + Y * (0.5 + B * -0.693) - B * (-0.627) ),
    1.0 + B * (-0.4 + Y * 0.6) - Y + R * ( -1.0 + B * (0.9 + Y * -1.1) + Y )
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!