Conversion between RGB and RYB color spaces
Asked Answered
R

3

16

I am currently trying to convert colours between RGB (red, green, blue) colour space and RYB (red, yellow, blue) colour space and back again.

Based on the details in the following paper, I am able to convert from RYB to RGB using trilinear interpolation - where the parametric weightings (s, t, u) are the RYB colors, and the vertices of the cube are 3d points in RGB space.

Paint Inspired Color Mixing and Compositing for Visualisation - Gossett and Chen - Section 2.1 - Realization Details

My difficulties are in reversing the conversion process.

A second paper references the use of this technique and also indicates that the reverse conversion was achieved using Newton's Method. But provides no further details. This would probably indicate root finding in solving the trilinear interpolation equations.

On the Transfer of Painting Style to Photographic Images through Attention to Colour Contrast - Xiaoyan Zhang; Constable, M.; Ying He;

Before I expand on this question with the equations, has anybody seen, or solved this in a language such as Java/C/C++/C#?

My current approach is to take the forward equations of the trilinear interpolation (RYB to RGB), expand and rearrange to provide 3 simultaneous equations for 3 unknowns (the parametric weightings: s, t, and u) then work out how to find the roots using the Newton-Raphson method. Am I going about this in the right way?

Rodenticide answered 9/2, 2011 at 13:25 Comment(9)
Have you tried mathoverflow.com?Mayce
@sje397: I've had a look on mathoverflow.com, but can't see anything regarding trilinear interpolation or its reverse process. - Just realised you could also mean to try asking the question on there.Rodenticide
Note that trilinear interpolation tends to be a terribly POOR choice for interpolation where RGB coordinates are concerned. This is because the neutrals live on the main diagonal of the cube in RGB space. You often see large interpolation errors, exactly on the set of colors that your brain can see subtle errors in color.Pawpaw
@woodchips: I can see how that would happen, however I'm not intending to use the trilinear interpolation to interpolate between two colours in the RGB space as such. It's just to convert from one point in RGB space to another in RYB space. Would trilinear interpolation be a poor choice for this conversion? Do you have any suggestions for alternative methods? Thanks.Rodenticide
The paper you linked for Gossett and Chen appears to have a typo on the interpolation coordinates. Here is a later version of the paper: web.siat.ac.cn/~baoquan/papers/ryb_TR.pdfTreharne
@PegLeg3941 : Thanks for the link to the paper. There is indeed a difference in coordinates between the two versions.Rodenticide
There's some more exposition here: math.stackexchange.com/questions/305395/…Oleaster
I’m voting to close this question because it is out of the scope of this network.Eozoic
I sketched out a (hopefully) valid solution in the answer here: math.stackexchange.com/a/4370750/1020517 (partially verified with the code)Howells
R
7

I managed to solve it in the end.

Take the equations for a trilinear interpolation: wikipedia Edit: Wikipedia revision at the time

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

Rodenticide answered 19/2, 2011 at 14:37 Comment(2)
The linked information seems to be gone. Which equations are you referring to?Illgotten
Wiki holds all the past revisions. Guessing by the date of the post, this is probably the revision I saw and used at the time: en.wikipedia.org/w/… Afraid I can't remember what the steps were. But hopefully it makes more sense to you.Rodenticide
A
3

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

Andaman answered 3/5, 2012 at 20:22 Comment(0)
D
3

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
Deductive answered 25/11, 2013 at 11:13 Comment(2)
As he stated, the problem is doing the inverse, rgb -> rybNikkinikkie
nishitalab.org/user/UEI/publication/Sugita_IWAIT2015.pdf nishitalab.org/user/UEI/publication/Sugita_SIG2015.pdfGeldens

© 2022 - 2024 — McMap. All rights reserved.