Code
from colorchecker2cielab import extract_color_patchesExtracting the RGB values for all color patches from the TIF image of the Digital Colorchecker target has been straightforward. Now we get to the gory details of color management…
While developing this python package I learned about several tricky details that I needed to grasp in order to compute accurate CIELAB color coordinates. These lessons learned are implemented in the RGBs_to_LABs() function as follows:
ECI_RGB_V2 = colour.models.RGB_COLOURSPACE_ECI_RGB_V2
illuminant = ECI_RGB_V2.whitepoint # D50
ECI_RGB_V2.use_derived_transformation_matrices = True
XYZs = colour.RGB_to_XYZ(RGBs, ECI_RGB_V2, apply_cctf_decoding=True)
LABs = colour.XYZ_to_Lab(XYZs, illuminant=illuminant) Let’s discuss these code lines one by one. Line 1 instantiates the ECI RGB v2 color space whose properties (RGB primaries etc.) we need to calculate CIELAB color coordinates from RGB values. In line 2 we extract the chromaticity coordinates (x, y) for the D50 white point that we will need below.
In line 3 we set the color space attribute .use_derived_transformation_matrices to True. This is related to the following issue described in the colour-science package documentation:
Colour science literature related to RGB colourspaces and encodings defines their dataset using different degree of precision or rounding. While instances where a whitepoint is being defined with a value different from its canonical agreed one are rare, it is however very common to have normalised primary matrices rounded at different decimals. This can yield large discrepancies in computations.*
The default for this option is False. We will want to maximize the precision, therefore we explicitly need to set this attribute to True.
In line 4 we first calculate the CIE XYZ tristimulus color coordinates with the RGB_to_XYZ() function. To do this correctly we need to set the apply_cctf_decoding option to True because the non-linear RGB coordinates in the TIFF need to be decoded (=linearized) as a first step. This is is done with the CIE L* luminance function as prescribed by the ECI RGB v2 color model.
In line 5 we convert the XYZ tristimulus values into CIELAB coordinates with the XYZ_to_Lab() function. The default illuminant for the function is D65. Therefore we explicitly need to set the illuminant option to the D50 white point. I now understand that CIELAB coordinates are defined relative to a white point!
ref_L* ref_a* ref_b* L* a* b* dE_2000 dE_1976
A1 95.35 -0.75 2.56 95.56 -0.76 2.22 0.33 0.40
B1 49.51 -0.53 0.38 49.37 -0.39 0.36 0.24 0.20
C1 8.59 0.26 -0.70 7.72 0.42 0.26 1.11 1.30
D1 95.62 -0.80 2.35 95.96 -0.89 1.92 0.46 0.55
E1 49.53 -0.54 0.41 49.36 -0.41 0.37 0.26 0.22
F1 8.47 0.16 -0.86 7.41 0.45 0.24 1.34 1.56
G1 95.50 -0.82 2.40 95.85 -0.95 1.88 0.56 0.64
H1 49.53 -0.54 0.44 49.37 -0.44 0.34 0.24 0.22
I1 8.44 0.27 -0.82 7.38 0.17 0.26 1.26 1.52
J1 95.63 -0.81 2.34 95.91 -0.92 1.84 0.52 0.59
K1 49.46 -0.55 0.34 49.38 -0.42 0.28 0.21 0.16
L1 9.55 0.36 -0.45 7.58 0.50 0.63 1.63 2.25
M1 49.37 -0.53 0.33 49.43 -0.45 0.21 0.18 0.16
N1 95.34 -0.80 2.46 95.71 -0.90 1.94 0.55 0.64
A2 9.05 0.24 -0.89 7.52 0.31 0.18 1.42 1.87
B2 33.06 51.60 -10.48 34.13 50.45 -7.86 1.49 3.06
C2 19.99 20.10 -18.86 20.85 18.47 -17.83 1.11 2.11
D2 83.60 -2.18 -8.35 84.09 -2.00 -8.32 0.40 0.52
E2 32.14 19.46 22.48 31.60 17.65 20.30 1.33 2.88
F2 63.36 20.01 19.98 64.88 19.02 18.97 1.42 2.08
G2 45.82 -3.99 -25.32 46.09 -3.78 -24.90 0.39 0.54
H2 38.10 -16.74 29.18 37.79 -17.03 27.62 0.87 1.62
I2 51.22 9.39 -27.35 51.38 9.44 -26.60 0.53 0.77
J2 68.08 -35.24 -0.89 69.01 -34.89 -0.23 0.86 1.19
K2 84.76 10.96 17.84 84.98 11.28 18.18 0.31 0.52
L2 21.66 35.94 9.72 22.84 34.82 11.15 1.39 2.17
M2 42.18 63.63 11.97 43.59 62.58 12.20 1.34 1.77
N2 49.42 -0.54 0.39 49.47 -0.43 0.20 0.26 0.23
A3 49.49 -0.56 0.33 49.29 -0.40 0.34 0.30 0.25
B3 60.96 26.65 -18.39 61.06 26.19 -17.85 0.32 0.71
C3 41.38 18.14 -36.85 41.20 18.23 -35.79 0.68 1.08
D3 84.50 14.49 0.52 84.97 14.12 0.33 0.44 0.63
E3 61.35 37.18 68.91 61.62 37.39 65.87 1.15 3.06
F3 34.80 11.99 -51.74 34.65 12.62 -49.61 1.36 2.23
G3 47.29 53.15 22.33 48.88 53.23 23.29 1.64 1.86
H3 21.60 32.81 -28.91 21.54 31.19 -27.46 0.75 2.17
I3 70.39 -25.76 64.39 70.01 -23.55 58.67 1.57 6.14
J3 69.68 18.58 78.96 68.86 17.67 75.18 1.06 3.97
K3 88.42 -17.05 6.35 89.22 -16.52 5.53 0.80 1.26
L3 44.00 66.29 51.04 46.04 67.03 52.94 2.04 2.89
M3 19.20 34.85 -7.48 19.14 33.14 -8.78 1.08 2.15
N3 8.69 0.32 -0.71 7.62 0.68 0.36 1.34 1.55
A4 95.57 -0.80 2.24 95.97 -0.85 1.79 0.49 0.60
B4 29.88 50.17 -41.86 29.55 48.09 -39.77 0.81 2.96
C4 21.10 -1.20 -34.33 21.61 -2.32 -33.02 0.68 1.80
D4 83.97 -19.35 -1.10 84.45 -19.22 -1.21 0.34 0.51
E4 19.29 23.34 -59.46 18.40 20.23 -53.94 1.48 6.39
F4 51.70 -44.14 39.12 53.49 -42.45 35.84 2.10 4.10
G4 37.28 65.62 42.67 39.18 64.81 43.00 1.68 2.09
H4 80.85 2.30 88.86 80.49 3.73 82.02 1.70 6.99
I4 48.07 56.26 -14.81 48.52 54.36 -12.03 1.31 3.40
J4 46.67 -32.13 -30.93 48.59 -31.13 -31.06 1.94 2.17
K4 83.82 5.10 -6.02 84.21 5.12 -6.56 0.50 0.66
L4 60.42 35.97 3.89 61.20 35.36 4.75 0.90 1.31
M4 41.17 65.74 33.22 42.97 65.42 33.08 1.63 1.83
N4 95.60 -0.82 2.23 96.19 -0.95 1.47 0.82 0.97
A5 8.47 0.30 -0.70 7.59 0.16 -0.00 0.90 1.13
B5 49.04 -13.81 -49.04 49.95 -12.06 -47.67 1.42 2.40
C5 59.80 -17.93 -31.89 60.48 -16.87 -32.28 0.87 1.32
D5 84.45 13.18 7.80 84.68 12.86 7.75 0.29 0.40
E5 95.65 -0.85 2.11 95.99 -0.95 1.40 0.71 0.79
F5 78.75 -0.08 0.35 78.58 0.00 0.17 0.25 0.26
G5 64.83 -0.45 -0.33 64.67 -0.41 -0.22 0.18 0.19
H5 49.28 -0.54 0.35 49.27 -0.39 0.28 0.22 0.16
I5 34.37 -0.44 0.00 34.78 -0.45 0.12 0.36 0.43
J5 15.18 -0.88 -1.12 15.77 -0.66 -0.92 0.53 0.66
K5 82.98 -12.66 -8.83 83.65 -12.44 -8.77 0.48 0.71
L5 61.75 37.11 17.62 62.59 35.89 18.50 1.16 1.72
M5 53.63 67.17 50.15 55.30 70.03 54.01 1.98 5.08
N5 49.37 -0.52 0.33 49.44 -0.40 0.25 0.20 0.16
A6 49.44 -0.54 0.31 49.24 -0.43 0.27 0.26 0.24
B6 60.10 -30.10 -26.67 60.91 -29.73 -26.49 0.72 0.91
C6 21.55 -17.05 -17.59 23.25 -17.86 -17.08 1.38 1.95
D6 83.32 -11.78 26.26 83.06 -10.21 25.52 1.08 1.75
E6 8.76 0.43 -0.29 8.76 0.81 0.95 1.32 1.30
F6 29.30 0.13 0.28 29.94 0.09 0.28 0.49 0.64
G6 39.19 -0.49 0.25 39.58 -0.39 0.31 0.38 0.41
H6 59.75 -0.17 -0.19 59.96 -0.06 -0.18 0.25 0.24
I6 74.59 0.21 -0.09 74.20 0.21 -0.17 0.30 0.40
J6 87.36 -0.86 -0.35 87.36 -0.86 -0.84 0.47 0.49
K6 69.99 -0.24 -0.52 69.72 -0.21 -0.53 0.21 0.27
L6 63.63 51.26 79.10 65.14 51.87 77.47 1.47 2.31
M6 81.85 22.67 85.56 80.28 24.14 84.24 1.48 2.52
N6 8.88 0.37 -0.59 8.09 0.90 0.92 1.72 1.78
A7 95.44 -0.85 2.37 95.57 -0.90 1.86 0.49 0.53
B7 18.23 -25.24 -7.58 22.34 -25.77 -7.94 2.87 4.16
C7 59.96 -5.50 -32.60 60.17 -4.92 -32.26 0.52 0.70
D7 61.97 29.60 36.28 61.91 30.33 34.64 1.15 1.80
E7 75.73 19.54 22.65 75.54 20.72 23.54 0.68 1.49
F7 62.78 13.06 26.02 63.35 13.04 24.48 0.95 1.64
G7 43.65 15.72 26.96 39.72 15.07 24.95 3.67 4.46
H7 66.86 13.99 16.71 67.28 13.96 15.60 0.81 1.18
I7 44.81 25.79 40.65 45.34 25.45 39.99 0.55 0.91
J7 63.42 25.00 26.80 63.03 24.93 26.02 0.54 0.87
K7 44.45 -0.12 0.63 45.10 -0.13 0.68 0.61 0.65
L7 72.21 -11.41 87.21 70.15 -11.09 81.78 1.94 5.81
M7 81.23 5.33 95.11 79.20 6.09 92.96 1.54 3.06
N7 95.64 -0.80 2.24 95.94 -0.82 1.61 0.61 0.70
A8 8.42 0.29 -0.77 7.68 -0.02 0.21 1.17 1.27
B8 59.18 -40.97 -13.40 60.90 -41.98 -13.15 1.58 2.01
C8 49.75 -48.87 -11.43 52.91 -49.89 -11.48 3.16 3.32
D8 63.44 20.85 18.90 64.82 19.63 17.65 1.40 2.23
E8 73.40 29.02 25.35 73.02 29.96 25.73 0.50 1.08
F8 63.79 13.74 17.48 64.05 13.40 17.53 0.36 0.43
G8 64.25 15.57 16.61 64.97 15.46 16.35 0.61 0.77
H8 64.35 16.61 18.82 65.40 15.95 17.88 1.03 1.56
I8 35.64 16.70 27.67 36.08 14.89 25.93 1.21 2.55
J8 65.83 21.96 28.22 65.88 21.92 27.22 0.54 1.00
K8 20.24 -0.10 0.42 20.88 -0.41 0.33 0.65 0.72
L8 61.58 2.86 56.24 60.77 2.51 53.26 1.12 3.11
M8 71.57 -18.77 77.61 69.84 -17.60 74.36 1.54 3.86
N8 49.31 -0.53 0.35 49.37 -0.42 0.24 0.20 0.17
A9 49.34 -0.54 0.35 49.04 -0.43 0.19 0.38 0.36
B9 19.10 1.60 12.31 20.06 0.29 13.53 2.03 2.03
C9 59.68 -40.69 19.57 60.68 -40.05 19.59 0.91 1.19
D9 50.40 -53.33 13.94 52.14 -52.38 14.36 1.78 2.02
E9 20.57 -23.24 5.67 22.38 -22.94 5.39 1.29 1.85
F9 59.26 -43.65 7.36 60.87 -43.06 7.34 1.43 1.72
G9 59.79 -29.07 39.25 59.38 -27.68 38.72 0.69 1.55
H9 50.73 -49.58 43.54 51.37 -49.13 43.81 0.68 0.83
I9 60.99 -54.10 46.27 61.26 -52.41 45.63 0.53 1.83
J9 61.30 16.26 51.36 60.56 16.21 49.58 0.88 1.92
K9 61.68 -14.73 53.90 60.35 -13.93 52.70 1.25 1.96
L9 72.26 -29.51 71.44 70.34 -28.77 72.57 1.57 2.35
M9 20.74 13.45 16.79 22.94 12.77 19.35 2.52 3.44
N9 9.18 0.36 -0.68 8.01 0.43 0.53 1.39 1.68
A10 95.45 -0.82 2.31 95.19 -0.91 1.87 0.46 0.52
B10 49.47 -0.54 0.33 49.12 -0.47 0.27 0.37 0.36
C10 8.50 0.31 -0.47 7.77 -0.01 0.37 1.06 1.15
D10 95.59 -0.82 2.21 95.44 -0.90 1.63 0.57 0.61
E10 49.31 -0.53 0.32 49.16 -0.44 0.21 0.23 0.21
F10 8.48 0.35 -0.61 7.87 0.16 0.44 1.14 1.23
G10 95.49 -0.80 2.27 95.41 -0.82 1.71 0.52 0.57
H10 49.36 -0.54 0.36 49.24 -0.40 0.24 0.26 0.21
I10 9.01 0.38 -0.30 8.06 0.22 0.74 1.21 1.42
J10 95.59 -0.81 2.19 95.70 -0.85 1.49 0.65 0.70
K10 49.38 -0.50 0.35 49.25 -0.39 0.25 0.23 0.20
L10 9.15 0.49 -0.35 8.08 0.19 0.81 1.39 1.60
M10 49.43 -0.54 0.31 49.29 -0.41 0.16 0.27 0.24
N10 95.36 -0.79 2.31 95.48 -0.79 1.65 0.61 0.67
compute_deltaEs (target_LABs, tif_LABs)
Computes color differences according to CIE2000 and CIE1976.
RGBs_to_LABs (RGBs, use_derived_transformation_matrices=True)
*Convert RGB values dataframe into CIELAB values dataframe assuming ECI_RGB_v2 colour space.
If the option use_derived_transformation_matricesis true (default) then high precision matrices are used for the computation. If set to false, matrices values as described in the standards are used.*
read_target_data (target_txt_file, verbose=False)
Read measured CIELAB values from text file for specific Colorchecker target.