How to Mix Colors "Naturally" with C#

How to mix colors naturally with C#?

"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.

Is there an easy way to blend two System.Drawing.Color values?

I wrote a utility method for exactly this purpose. :)

/// <summary>Blends the specified colors together.</summary>
/// <param name="color">Color to blend onto the background color.</param>
/// <param name="backColor">Color to blend the other color onto.</param>
/// <param name="amount">How much of <paramref name="color"/> to keep,
/// “on top of” <paramref name="backColor"/>.</param>
/// <returns>The blended colors.</returns>
public static Color Blend(this Color color, Color backColor, double amount)
{
byte r = (byte) (color.R * amount + backColor.R * (1 - amount));
byte g = (byte) (color.G * amount + backColor.G * (1 - amount));
byte b = (byte) (color.B * amount + backColor.B * (1 - amount));
return Color.FromRgb(r, g, b);
}

Programmatically Change Colors in C#

The best thing to do for this kind of problem is use HSL or HSV values and vary just the hue.
Then convert back to RGB.

See this link for more information.

Is there an algorithm for color mixing that works like mixing real colors?

There is a novel (Feb 2022) technique showcased in 2 minute papers.

Autors call it the "Mixbox", and the technique is open source (algorithm can be found on github, mind the license though). Currently Rebelle 5 is implementing this color mixing technique, more programs may follow in the nearest future.

Imo the strongest point of this is its simplicity in implementation and how easily you can use it out of the box. Their paper is also (supposedly -- I didn't read it) well written.

How to add 2 System.Drawing.Color?

If you need to consider color context too it's a little bit long to write in an answer. You may use Reflector (for example) to disassemble System.Windows.Media.Color.op_Addition method (stripping what you do not need in your implementation).

Compare RGB colors in c#

What you are looking for is called Delta-E.

http://www.colorwiki.com/wiki/Delta_E:_The_Color_Difference

It is the distance between two colors in LAB color space. It is said that the human eye cannot distinguish colors below 1 DeltaE (I find that my eyes can find differences in colors below 1 DeltaE, each person is different.)

There are 4 formulas for 'color difference'.

  • Delta E (CIE 1976)
  • Delta E (CIE 1994)
  • Delta E (CIE 2000)
  • Delta E (CMC)

Check the math link on this site:

  • http://www.brucelindbloom.com/

So the proper answer is to convert your RGB to LAB using the formula given, then use DeltaE 1976 to determine the 'difference' in your colors. A result of 0 would indicate identical colors. Any value higher than 0 could be judged by the rule 'A delta e of 1 or less is indistinguishable by most people'.



Related Topics



Leave a reply



Submit