2

Here is my problem:

I have a set of 'n' colors including the primary colors and their codes in hexadecimal. Now given another color 'x' I wonder if it's actually possible to come up with a mix between two or more of the colors of the set that will produce 'x'. The mix should be subtractive.

Here is an example of the result of the algorithm:

My set of colors is: c1, c2, c3, c4, c5, c6. I am trying to find the mix to produce the color x. The result could be: 50% of c1, 25% of c4 and 25% of c5.

If anyone could point me in the right direction (or at least tell me if it is unfeasible), any help would be gladly appreciated!

Tom
  • 309
  • 1
  • 9
Duom
  • 121
  • 3
  • 2
    Since you did not write if you mean additive or subtractive mixing, I guess you should first have a look here: http://en.wikipedia.org/wiki/Color_mixing – Doc Brown Sep 02 '13 at 20:04
  • 1
    Related question (possibly a duplicate of) [What class of problem is this, and what math do I need to know to solve it?](http://programmers.stackexchange.com/questions/204431/what-class-of-problem-is-this-and-what-math-do-i-need-to-know-to-solve-it) –  Sep 02 '13 at 20:30
  • @MichaelT: It seems to be related, but I don't think it's a duplicate, this one here requires some color theory. – Doc Brown Sep 03 '13 at 11:40
  • 1
    A related old SO post - [Mixing two RGB color vectors to get resultant](http://stackoverflow.com/questions/1892020/mixing-two-rgb-color-vectors-to-get-resultant) –  Sep 03 '13 at 16:02
  • 1
    [Paul Saski's answer](http://stackoverflow.com/a/1892069/377657) contains a link to [Color Models](http://www.booksmartstudio.com/color_tutorial/colortheory4.html) which is a recommended read. – rwong Sep 04 '13 at 06:07
  • 1
    More recommended reads: [Stanford CS178](http://graphics.stanford.edu/courses/cs178-11/applets/colormixing.html), and [Gamut on Wikipedia](http://en.wikipedia.org/wiki/Gamut) – rwong Sep 04 '13 at 06:14
  • [This interactive demo](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) explains why simple RGB algebra will not work for intuitive color mixing that is agreeable to the human eyes. More on [L*a*b* on Wikipedia](http://en.wikipedia.org/wiki/Lab_color_space). – rwong Sep 10 '13 at 07:40

1 Answers1

1

This is a basic linear algebra problem. Let b = [ b1, b2, b3 ] be your mixed colour, x = [ x1, x2, ... xn ] be your solution, I = [ 1, 1, 1 ] (or whatever your white value is), and A = [ c1, c2, ..., cn ] be your colour set where each ci is a column vector in the matrix A. You must solve for x in the the equation I - Ax = b or Ax = I - b. You can check out the Khan Academy video about how to do that here if you do not already know how.

If there is no solution to this equation there is also no subtractive mix (obviously), but there is also no subtractive mix if there is a value in x, xi, that is negative or greater than one. If there is a negative value then you are actually adding the colour, and if there is one greater than one, you are subtracting the colour more than once. Otherwise your solution is the vector x.

Chewy Gumball
  • 1,383
  • 1
  • 10
  • 12