12,447,227 members (52,101 online)
Rate this:
See more:
Dear Experts

I need to build a simple application to match a color with a reference standard. to be more specific i will scan a tagged color palate of 36 colors (will serve as a reference standard) I will scan the test color on the same scanner (to avoid inter-device variations). The application should compare the color to the standard palette and alert if there is a match. I wonder if visual studio has a tool to do the color comparison.

Posted 16-Feb-13 20:32pm
Updated 16-Feb-13 22:38pm
v4

Rate this:

## Solution 1

Color comparison can never be very accurate since there are a number of factors like capability of the scanner to capture brightness, the surrounding light etc involved. You also have factors like alpha correction etc, which although calculable, can make the calculations quite complex.

An easy solution, thought not always accurate, is to use hue, saturation and luminosity[^] to compare and contrast pixel colors.

Comparing based on HSL is described here[^] and it forms an interesting read.
Color Difference[^] provides some explanations.
v2
MohamedKamalPharm 17-Feb-13 5:09am

thanks Abhinav S.
Rate this:

## Solution 2

To my knowledge there is no built-in component to do that.
You would have to compare the encoding of the colour at a given point in the test image and find the same colour in an array of the colours in the standard.

You might want to look at, Manipulating colors in .NET - Part 1[^], it's not what you want but has some stuff in it that you might find useful.

You may also want to consider doing the matching with a colour space such as CIE XYZ[^] rather than using colour models, like .Net RGB, which is harder since conversions between models and spaces is not necessarily easy, however spaces represent real colours, models are just that, models and what colour a given point is depends on the output device.

Mike
MohamedKamalPharm 17-Feb-13 5:39am

thanks Mike
Rate this:

## Solution 3

In an article I wrote [^], there is a section on color difference equations. I think the Delta E 2000 equation may be helpful.
v2
MohamedKamalPharm 18-Feb-13 6:02am

Excellent Sir !
this is ALMOST what I need
I just need to use my own color palette
How can i use my own set of colors ?
gggustafson 18-Feb-13 11:13am

Note that the delta_e_2000 method expects two CLILab colors for comparison. I am going to assume that your 36 colors are GDI Colors. What I would suggest:

1. Convert your 36 GDI colors into a List of Extended_Color, calling the list, say, reference colors. The definition for Extended_Color is found in the article. You will need to convert a GDI Color into an XYZ color and then convert the XYZ color into a CIELab color.
2. Convert the GDI color of interest into a CIELab Color (the algorithm in the article stores the value in a class global variable).
3. The method nearest_known_color_name in the class Known_Colors_Palette provides the way in which the comparison might work. Simply, a record of the "shortest distance" is kept and at its conclusion, the closest matching color name is returned. You can modify the method to return whatever you want. For your case, assuming that the delta_e_2000 method is chosen, the foreach loop can be made quite simple.

If you have problems, you can contact me through email (gggustafson at gmail dot com).

Please remember to mark one of the answers as the accepted solution.

Top Experts
Last 24hrsThis month
 OriginalGriff 375 Richard Deeming 345 ppolymorphe 275 CPallini 165 njammy 80
 OriginalGriff 5,543 Karthik Bangalore 3,272 ppolymorphe 3,147 Maciej Los 2,832 Richard Deeming 2,580