Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conversion between RGB and RYB color spaces

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?

like image 608
Ben Avatar asked Feb 09 '11 13:02

Ben


People also ask

What is difference between RGB and RYB?

RGB are the primary colors of light, since it is additive, meaning the more you add, the closer you get to white. RYB are the primary colors of paint, since it is subtractive, meaning the more you add, the closer you get to black.

What is color space conversion?

Color space conversion is the translation of the representation of a color from one basis to another. This typically occurs in the context of converting an image that is represented in one color space to another color space, the goal being to make the translated image look as similar as possible to the original.

Why is light RGB but paint RYB?

The more colors you add, the darker it gets because pigment on printed material absorbs light. Mixing paint results in darker colors, whereas mixing light results in lighter colors. In painting, primary colors are Red Yellow Blue (or “Cyan”,”Magenta” & “Yellow”). But for light, the primary colors are Red Green Blue.


1 Answers

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

like image 81
Ben Avatar answered Sep 21 '22 23:09

Ben