I am working on a project where I need to convert colors defined in RGB (Red, Green, Blue) color space to RYB (Red Yellow Blue).
I managed to solve converting a color from RYB to RGB space based on the article - Paint Inspired Color Mixing and Compositing for Visualization.
I convert a color from RYB to RGB with this "algorithm":
So the values of r (red), y (yellow), and b (blue) are known, also these arrays/sets are constants:
white: [1, 1, 1]
red: [1, 0, 0]
yellow: [1, 1, 0]
blue: [0.163, 0.373, 0.6]
violet: [0.5, 0, 0.5]
green: [0, 0.66, 0.2]
orange: [1, 0.5, 0]
black: [0.2, 0.094, 0.0]
here is how I calculate the value of red for the RGB space based on the parameters above:
i = 1;
rgb_red = white[i] * (1 - r) * (1 - b) * (1 - y) +
red[i] * r * (1 - b) * (1 - y) +
blue[i] * (1 - r) * b * (1 - y) +
violet[i] * r * b * (1 - y) +
yellow[i] * (1 - r) * (1 - b) * y +
orange[i] * r * (1 - b) * y +
green[i] * (1 - r) * b * y +
black[i] * r * b * y);
for rgb_green exactly the same thing but for i=2, and i=3 for rgb_blue.
My problem is that now I want to convert from RGB to RYB back. In other words, knowing the values of rgb_red, rgb_green and rgb_blue I want to calculate the values of r, y, and b. So I need a kind of inverse function for this, but I don't know how to get it.
Any help is appreciated.
When i wrote a program to convert between all majorly used color formats, i used the following algorithms for $RYB \rightarrow RGB$ and $RGB \rightarrow RYB$ conversion: http://www.insanit.net/tag/rgb-to-ryb/ (link to archive.org, original site is gone)
Now I don't know if this solution works perfectly with the conversion you already have, it looks like some kind of matrix multiplication. If we split $(1-r)(1-b)(1-y) = 1 - r - b - y + rb + ry + by -ryb$ we have 8 components. Also we have 8 components white[i], red[i], orange[i], yellow[i], ... so you can make it a matrix multiplication and add the values of the resulting vector to obtain $r$ (when $i=1$). Now to make an inverse matrix we need more information about the resulting vector. If we just add everything that is in the vector, we lose that information. I still think it is possible to do it with a matrix, but i dont know how to create one, other than making some assumptions like $\text{white}[i]=[1,1,1]$ (which i think will be for inverse as well), and explain why that would be true.