The Colourful library contains a range of algorithms that can be used to compute a difference between colors, i.e. provide a certain metric that can be used as a distance between two colors in a color space.
The color difference is commonly denoted as delta E, or ΔE. Some of the algorithms operate on specific color spaces. If you want to use them in other color spaces, you can do so if you convert your colors into the required space beforehand.
The CIE76 algorithm operates in the Lab color space.
var labColor1 = new LabColor(55, 80, 50);
var labColor2 = new LabColor(18, 36, -60);
double difference = new CIE76ColorDifference().ComputeDifference(labColor1, labColor2); // 124.1169
- http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CIE76.html
- https://en.wikipedia.org/wiki/Color_difference#CIE76
The CMC algorithm operates in the Lab color space and has two modes: Acceptability
and Imperceptibility
.
var differenceThreshold = CMCColorDifferenceThreshold.Acceptability; // or "Imperceptibility"
var differenceCalculator = new CMCColorDifference(differenceThreshold);
var labColor1 = new LabColor(55, 80, 50);
var labColor2 = new LabColor(18, 36, -60);
double difference = differenceCalculator.ComputeDifference(in labColor1, in labColor2); // 69.7388
- http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CMC.html
- https://en.wikipedia.org/wiki/Color_difference#CMC_l:c_(1984)
The CIE94 algorithm operates in the Lab color space and has two modes: GraphicArts
and Textiles
.
var application = CIE94ColorDifferenceApplication.GraphicArts; // or "Textiles"
var differenceCalculator = new CIE94ColorDifference(application);
var labColor1 = new LabColor(55, 80, 50);
var labColor2 = new LabColor(18, 36, -60);
double difference = differenceCalculator.ComputeDifference(in labColor1, in labColor2); // 60.7882
- http://www.brucelindbloom.com/Eqn_DeltaE_CIE94.html
- https://en.wikipedia.org/wiki/Color_difference#CIE94
The CIEDE2000 algorithm operates in the Lab color space.
var differenceCalculator = new CIEDE2000ColorDifference();
var labColor1 = new LabColor(55, 80, 50);
var labColor2 = new LabColor(18, 36, -60);
double difference = differenceCalculator.ComputeDifference(in labColor1, in labColor2); // 52.2320
- http://www.brucelindbloom.com/Eqn_DeltaE_CIE2000.html
- https://en.wikipedia.org/wiki/Color_difference#CIEDE2000
The ΔEz algorithm operates on the JzCzhz color space, a cylindrical variant of Jzazbz.
var differenceCalculator = new JzCzhzDEzColorDifference();
var color1 = new JzCzhzColor(0.3, 0.4, 165);
var color2 = new JzCzhzColor(0.8, 0.6, 25);
double difference = differenceCalculator.ComputeDifference(in color1, in color2); // 1.0666
The Euclidean distance is a generic algorithm that can operate in any color space.
// example for euclidean distance in the XYZ color space
var differenceCalculator = new EuclideanDistanceColorDifference<XYZColor>();
var color1 = new XYZColor(0.5, 0.5, 0.5);
var color2 = new XYZColor(0.2, 0.4, 0.6);
double difference = differenceCalculator.ComputeDifference(in color1, in color2); // 0.3317