48

I have to mix some colors in a natural way. This means

blue + yellow = green 
blue + red = purple

And so on. I got the colors as RGB-Values. When I try to mix them I got the right "RGB"-results like

green + red = yellow
yellow + blue = white

But not the right "natural-wet-paint"-results. Any good idea how to mix RGB in a natural way?

It would be great if someone knew a solution within the Microsoft.Xna.Framework.Graphics namespace but a generic solution would also help :)


@Jay Bazuzi:

Please post a code sample that shows what you're trying to do.

Sure - this is my function for mixing the two RGB-Colors.

public Color colorMixer(Color c1, Color c2)
{

    int _r = Math.Min((c1.R + c2.R),255);
    int _g = Math.Min((c1.G + c2.G),255);
    int _b = Math.Min((c1.B + c2.B),255);

    return new Color(Convert.ToByte(_r),
                     Convert.ToByte(_g),
                     Convert.ToByte(_b));
}

What I have read so far in this thread is very promising - I will convert C1 and C2 to Lab*, mix them - convert it back to RGB and return that color.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
crono
  • 3,603
  • 3
  • 27
  • 24
  • Please post a code sample that shows what you're trying to do. – Jay Bazuzi Dec 29 '08 at 18:18
  • See [stackoverflow.com/questions/10254022/](http://stackoverflow.com/questions/10254022/implementing-kubelka-munk-like-krita-to-mix-colours-color-like-paint/29967630#29967630), where this question is discussed in more detail. – Scott Burns May 08 '15 at 17:15
  • great question! Your colourMixer method helped me a lot too! – K-Dawg Feb 13 '16 at 14:07

2 Answers2

47

"Natural wet paint" is a little ambiguous; the mixing of CMYK as suggested won't work because you're still adding colors.

If you want results like in Photoshop (as Jon B checked) you need to use L*a*b* space. Formulas for converting RGB to/from Lab and a description is here.

Lab space was specifically designed so that linear changes correspond to what the human eye perceives as a certain amount of color change. This is important because e.g. we are more sensitive to green than other colors, because we perceive changes differently depending both on hue and lightness, etc..

Trying any other methods currently being suggested will not only result in colors you don't want, but also won't represent a "constant-looking" change in color, especially if you use this for something where constant-change matters like a gradient.

Jason Cohen
  • 81,399
  • 26
  • 107
  • 114
  • Promising idea, but how I mix the two colors after converting them to LAB? See my question: http://stackoverflow.com/q/14819058/240324 – Tamás Pap Feb 11 '13 at 19:10
  • @TamasPap The same way you'd "mix" any other quantities. For example, average their components together. – Quuxplusone Feb 11 '13 at 19:18
3

You get cmyk<->rgb conversion for free with WIC. but it's .NET 3.0 only

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
Bart
  • 10,873
  • 7
  • 29
  • 23