Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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!

share|improve this question
2  
Since you did not write if you mean additive or subtractive mixing, I guess you should first have a look here: en.wikipedia.org/wiki/Color_mixing –  Doc Brown Sep 2 '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? –  MichaelT Sep 2 '13 at 20:30
1  
A related old SO post - Mixing two RGB color vectors to get resultant –  MichaelT Sep 3 '13 at 16:02
1  
Paul Saski's answer contains a link to Color Models which is a recommended read. –  rwong Sep 4 '13 at 6:07
1  
More recommended reads: Stanford CS178, and Gamut on Wikipedia –  rwong Sep 4 '13 at 6:14

1 Answer 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.