Compare RGB colors in c#

前端 未结 8 2010
予麋鹿
予麋鹿 2020-11-29 04:38

I\'m trying to find a way to compare two colors to find out how much they are alike. I can\'t seem to find any resources about the subject so I\'m hoping to get some pointer

相关标签:
8条回答
  • 2020-11-29 05:26

    There's an open-source .net library that lets you do this easily: https://github.com/hvalidi/ColorMine

    The most common method for comparing colors is CIE76:

    var a = new Rgb { R = 149, G = 13, B = 12 }
    var b = new Rgb { R = 255, G = 13, B = 12 }
    
    var deltaE = a.Compare(b,new Cie1976Comparison());
    
    0 讨论(0)
  • 2020-11-29 05:27

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

    0 讨论(0)
提交回复
热议问题