Welcome

Guest

Log out

Subscription valid until 2017-02-25



















 

Color delta/comparison math

These are the formulas to calculate color differences. All of them refers to the CIE-L*ab color space.
Each formula is written as a "neutral programming function", easy to be translate in any specific computer language.
We did not post obvious deltas which involve a simple subtraction of two values.

Please keep in mind that implementing complex delta calculation (CMC, 1994, 2000) in your code may involve a lot of attention about the math itself and also the coding syntax.

Delta C*

Delta H*

Delta E*

Delta E 1994

Delta E 2000

CIE-L*1, CIE-a*1, CIE-b*1          //Color #1 CIE-L*ab values
CIE-L*2, CIE-a*2, CIE-b*2          //Color #2 CIE-L*ab values

WHT-L, WHT-C, WHT-H                //Wheight factor


xC1 = sqrt( CIE-a*1 * CIE-a*1 + CIE-b*1 * CIE-b*1 )
xC2 = sqrt( CIE-a*2 * CIE-a*2 + CIE-b*2 * CIE-b*2 )
xCX = ( xC1 + xC2 ) / 2
xGX = 0.5 * ( 1 - sqrt( ( xCX ^ 7 ) / ( ( xCX ^ 7 ) + ( 25 ^ 7 ) ) ) )
xNN = ( 1 + xGX ) * CIE-a*1
xC1 = sqrt( xNN * xNN + CIE-b*1 * CIE-b*1 )
xH1 = CieLab2Hue( xNN, CIE-b*1 )
xNN = ( 1 + xGX ) * CIE-a*2
xC2 = sqrt( xNN * xNN + CIE-b*2 * CIE-b*2 )
xH2 = CieLab2Hue( xNN, CIE-b*2 )
xDL = CIE-L*2 - CIE-L*1
xDC = xC2 - xC1
if ( ( xC1 * xC2 ) == 0 ) {
   xDH = 0
}
else {
   xNN = round( xH2 - xH1, 12 )
   if ( abs( xNN ) <= 180 ) {
      xDH = xH2 - xH1
   }
   else {
      if ( xNN > 180 ) xDH = xH2 - xH1 - 360
      else             xDH = xH2 - xH1 + 360
   }
}
xDH = 2 * sqrt( xC1 * xC2 ) * sin( dtor( xDH / 2 ) )
xLX = ( CIE-L*1 + CIE-L*2 ) / 2
xCY = ( xC1 + xC2 ) / 2
if ( ( xC1 *  xC2 ) == 0 ) {
   xHX = xH1 + xH2
}
else {
   xNN = abs( round( xH1 - xH2, 12 ) )
   if ( xNN >  180 ) {
      if ( ( xH2 + xH1 ) <  360 ) xHX = xH1 + xH2 + 360
      else                        xHX = xH1 + xH2 - 360
   }
   else {
      xHX = xH1 + xH2
   }
   xHX /= 2
}
xTX = 1 - 0.17 * cos( dtor( xHX - 30 ) ) + 0.24
               * cos( deg2rad( 2 * xHX ) ) + 0.32
               * cos( deg2rad( 3 * xHX + 6 ) ) - 0.20
               * cos( dtor( 4 * xHX - 63 ) )
xPH = 30 * exp( - ( ( xHX  - 275 ) / 25 ) * ( ( xHX  - 275 ) / 25 ) )
xRC = 2 * sqrt( ( xCY ^ 7 ) / ( ( xCY ^ 7 ) + ( 25 ^ 7 ) ) )
xSL = 1 + ( ( 0.015 * ( ( xLX - 50 ) * ( xLX - 50 ) ) )
        / sqrt( 20 + ( ( xLX - 50 ) * ( xLX - 50 ) ) ) )
xSC = 1 + 0.045 * xCY
xSH = 1 + 0.015 * xCY * xTX
xRT = - sin( deg2rad( 2 * xPH ) ) * xRC
xDL = xDL / ( WHT-L * xSL )
xDC = xDC / ( WHT-C * xSC )
xDH = xDH / ( WHT-H * xSH )
Delta E00 = sqrt( xDL ^ 2 + xDC ^ 2 + xDH ^ 2 + xRT * xDC * xDH )


CieLab2Hue( var_a, var_b )          //Function returns CIE-H value
{
   var_bias = 0
   if ( var_a >= 0 && var_b == 0 ) return 0
   if ( var_a <  0 && var_b == 0 ) return 180
   if ( var_a == 0 && var_b >  0 ) return 90
   if ( var_a == 0 && var_b <  0 ) return 270
   if ( var_a >  0 && var_b >  0 ) var_bias = 0
   if ( var_a <  0               ) var_bias = 180
   if ( var_a >  0 && var_b <  0 ) var_bias = 360
   return ( rad2deg( atan( var_b / var_a ) ) + var_bias )
}

Top

Delta CMC