Skip to content

Instantly share code, notes, and snippets.

@KelSolaar
Created October 13, 2017 22:20
Show Gist options
  • Save KelSolaar/79332e327533e463a222736fa7b610d4 to your computer and use it in GitHub Desktop.
Save KelSolaar/79332e327533e463a222736fa7b610d4 to your computer and use it in GitHub Desktop.
CIE Lab - Colour Difference
import colour
# The two RGB triplets we want to measure the colour difference:
RGB = [(0.26, 0.42, 0.78), (0.25, 0.41, 0.79)]
# The reference illuminant/whitepoint.
D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
# Assuming sRGB IEC61966-2.1 encoded colours.
# - sRGB/BT.709 Primaries
# - D65 Whitepoint
# - sRGB OETF
XYZ = colour.sRGB_to_XYZ(RGB)
# Conversion to CIE Lab.
Lab = colour.XYZ_to_Lab(XYZ, D65)
Lab_1, Lab_2 = Lab
# Delta E ab computation.
d_E = {
'CIE 1976': colour.delta_E_CIE1976(Lab_1, Lab_2),
'CIE 1994': colour.delta_E_CIE1994(Lab_1, Lab_2),
'CIE 2000': colour.delta_E_CIE2000(Lab_1, Lab_2)
}
print(d_E)
"""
{
'CIE 1976': 34.986732014969455,
'CIE 1994': 15.911944863134869,
'CIE 2000': 11.722013662850278
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment