%matplotlib inline import numpy as np import pylab import colour from colour.utilities.verbose import message_box name, data, illuminant = colour.COLOURCHECKERS['ColorChecker 2005'] sRGB_w = colour.sRGB_COLOURSPACE.whitepoint sRGB_XYZ_to_RGB = colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix sRGB_RGB_to_XYZ = colour.sRGB_COLOURSPACE.RGB_to_XYZ_matrix adobe98_w = colour.ADOBE_RGB_1998_COLOURSPACE.whitepoint adobe98_XYZ_to_RGB = colour.ADOBE_RGB_1998_COLOURSPACE.XYZ_to_RGB_matrix adobe98_RGB_to_XYZ = colour.ADOBE_RGB_1998_COLOURSPACE.RGB_to_XYZ_matrix # Preparing *dark skin* colour in various colourspaces. index, name, x, y, Y = data[0] XYZ_r1 = colour.xyY_to_XYZ((x, y, Y)) # *sRGB* colourspace 0-255 values with OETF applied. sRGB_rd1 = colour.XYZ_to_sRGB(XYZ_r1, illuminant) # *sRGB* colourspace linear values. sRGB_r1 = colour.XYZ_to_RGB(XYZ_r1, illuminant, sRGB_w, sRGB_XYZ_to_RGB) # *Adobe RGB 1998* colourspace linear values. adobe98_r1 = colour.XYZ_to_RGB(XYZ_r1, illuminant, adobe98_w, adobe98_XYZ_to_RGB) message_box(('Reference "dark skin" "CIE XYZ" colourspace tristimulus ' 'values:\n' '\t{0}\n' '\n"sRGB" colourspace values (OETF):\n' '\n\t{1}\n' '\n"sRGB" and "Adobe RGB 1998" colourspaces (Linear):\n' '\tsRGB: {2}\n\tAdobe RGB 1998: {3}').format( XYZ_r1, np.around(sRGB_rd1 * 255), sRGB_r1, adobe98_r1)) # Preparing *green* colour in various colourspaces. index, name, x, y, Y = data[13] XYZ_r2 = colour.xyY_to_XYZ((x, y, Y)) # *sRGB* colourspace 0-255 values with OETF applied. sRGB_rd2 = colour.XYZ_to_sRGB(XYZ_r2, illuminant) # *sRGB* colourspace linear values. sRGB_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, sRGB_w, sRGB_XYZ_to_RGB) # *Adobe RGB 1998* colourspace linear values. adobe98_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, adobe98_w, adobe98_XYZ_to_RGB) message_box(('Reference "green" "CIE XYZ" colourspace tristimulus ' 'values:\n' '\t{0}\n' '\n"sRGB" colourspace values (OETF):\n' '\t{1}\n' '\n"sRGB" and "Adobe RGB 1998" colourspaces (Linear):\n' '\tsRGB: {2}\n\tAdobe RGB 1998: {3}').format( XYZ_r2, np.around(sRGB_rd2 * 255), sRGB_r2, adobe98_r2)) XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1, sRGB_w, illuminant, sRGB_RGB_to_XYZ) XYZ_adobe981 = colour.RGB_to_XYZ(adobe98_r1, adobe98_w, illuminant, adobe98_RGB_to_XYZ) message_box(('Converting back "dark skin" "CIE XYZ" colourspace ' 'tristimulus values from "sRGB" and "Adobe RGB 1998" ' 'colourspaces:\n' '\tFrom sRGB: {0}\n\tFrom Adobe RGB 1998: {1}\n' '\nEverything looks fine!').format( XYZ_sRGB1, XYZ_adobe981)) k = np.array([500, 500, 500]) sRGB_k = colour.XYZ_to_RGB(k, illuminant, sRGB_w, sRGB_XYZ_to_RGB) adobe98_k = colour.XYZ_to_RGB(k, illuminant, adobe98_w, adobe98_XYZ_to_RGB) sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * sRGB_k adobe98_m = adobe98_r1 * adobe98_r2 * adobe98_r2 * adobe98_r2 * adobe98_k XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ) XYZ_adobe98_m1 = colour.RGB_to_XYZ(adobe98_m, adobe98_w, adobe98_w, adobe98_RGB_to_XYZ) message_box(('Multiplying "dark skin" with "green" and converting back to ' '"CIE XYZ" colourspace tristimulus values from "sRGB" and ' '"Adobe RGB 1998" colourspaces:\n' '\tFrom sRGB: {0}\n\tFrom Adobe RGB 1998: {1}\n' '\nHouston? We have a problem!').format( XYZ_sRGB_m1, XYZ_adobe98_m1)) from colour.plotting import * sRGB_m1 = colour.XYZ_to_sRGB(XYZ_sRGB_m1) adobe98_m1 = colour.XYZ_to_sRGB(XYZ_adobe98_m1) sRGB_difference = sRGB_m1 - adobe98_m1 # The difference is producing negative values thus we clip the result, although the # remaining data should illustrate the effect. sRGB_difference = np.clip(sRGB_difference, 0, 1) single_colour_plot(colour_parameter('sRGB - Adobe RGB 1998', sRGB_difference), text_size=24) colourspaces_CIE_1931_chromaticity_diagram_plot( ['sRGB', 'Adobe RGB 1998'], standalone=False, title='"dark skin" Colour Computation') for name, XYZ in (('"dark skin"', XYZ_r1), ('"dark skin" * "green" - sRGB', XYZ_sRGB_m1), ('"dark skin" * "green" - Adobe RGB 1998', XYZ_adobe98_m1)): xy = colour.XYZ_to_xy(XYZ) pylab.plot(xy[0], xy[1], 'o', color='white') pylab.annotate(name, xy=xy, xytext=(50, 30), textcoords='offset points', arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=0.2')) display(standalone=True) Lab1 = colour.XYZ_to_Lab(XYZ_sRGB_m1, illuminant) Lab2 = colour.XYZ_to_Lab(XYZ_adobe98_m1, illuminant) print(colour.delta_E_CIE2000(Lab1, Lab2)) from pprint import pprint aces_w = colour.ACES_RGB_COLOURSPACE.whitepoint aces_XYZ_to_RGB = colour.ACES_RGB_COLOURSPACE.XYZ_to_RGB_matrix aces_RGB_to_XYZ = colour.ACES_RGB_COLOURSPACE.RGB_to_XYZ_matrix aces_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, aces_w, aces_XYZ_to_RGB) aces_k = colour.XYZ_to_RGB(k, illuminant, aces_w, aces_XYZ_to_RGB) XYZs_m = [] for index, name, x, y, Y in data: xyY = np.array([x, y, Y]) sRGB_r1 = colour.XYZ_to_RGB( colour.xyY_to_XYZ(xyY), illuminant, sRGB_w, sRGB_XYZ_to_RGB) sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * sRGB_k aces_r1 = colour.XYZ_to_RGB( colour.xyY_to_XYZ(xyY), illuminant, aces_w, aces_XYZ_to_RGB) aces_m = aces_r1 * aces_r2 * aces_r2 * aces_r2 * aces_k XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ) XYZ_aces_m1 = colour.RGB_to_XYZ(aces_m, aces_w, aces_w, aces_RGB_to_XYZ) XYZs_m.append((XYZ_sRGB_m1, XYZ_aces_m1)) pprint(XYZs_m) deltas_E = [] for i, (XYZ1, XYZ2) in enumerate(XYZs_m): Lab1 = colour.XYZ_to_Lab(XYZ1, illuminant) Lab2 = colour.XYZ_to_Lab(XYZ2, illuminant) deltas_E.append((data[i][1], colour.delta_E_CIE2000(Lab1, Lab2))) pprint(deltas_E) np.average([delta_E[1] for delta_E in deltas_E]) from pprint import pprint rec2020_w = colour.REC_2020_COLOURSPACE.whitepoint rec2020_XYZ_to_RGB = colour.REC_2020_COLOURSPACE.XYZ_to_RGB_matrix rec2020_RGB_to_XYZ = colour.REC_2020_COLOURSPACE.RGB_to_XYZ_matrix rec2020_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, rec2020_w, rec2020_XYZ_to_RGB) rec2020_k = colour.XYZ_to_RGB(k, illuminant, aces_w, aces_XYZ_to_RGB) XYZs_m = [] for index, name, x, y, Y in data: xyY = np.array([x, y, Y]) sRGB_r1 = colour.XYZ_to_RGB( colour.xyY_to_XYZ(xyY), illuminant, sRGB_w, sRGB_XYZ_to_RGB) sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * sRGB_k rec2020_r1 = colour.XYZ_to_RGB( colour.xyY_to_XYZ(xyY), illuminant, rec2020_w, rec2020_XYZ_to_RGB) rec2020_m = rec2020_r1 * rec2020_r2 * rec2020_r2 * rec2020_r2 * rec2020_k XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ) XYZ_rec2020_m1 = colour.RGB_to_XYZ(rec2020_m, rec2020_w, rec2020_w, rec2020_RGB_to_XYZ) XYZs_m.append((XYZ_sRGB_m1, XYZ_rec2020_m1)) pprint(XYZs_m) deltas_E = [] for i, (XYZ1, XYZ2) in enumerate(XYZs_m): Lab1 = colour.XYZ_to_Lab(XYZ1, illuminant) Lab2 = colour.XYZ_to_Lab(XYZ2, illuminant) deltas_E.append((data[i][1], colour.delta_E_CIE2000(Lab1, Lab2, l=1))) pprint(deltas_E) np.average(np.average([delta_E[1] for delta_E in deltas_E])) k = np.linspace(0, 1, 10) X_sRGB = lambda x: 0.41238656 * x + 0.35759149 * x + 0.18045049 * x X_ACES = lambda x: 0.9525524 * x + 0.00009368 * x pylab.plot(k, tuple(map(X_sRGB, k)), 'o-', color='red', label='X - sRGB') pylab.plot(k, tuple(map(X_ACES, k)), 'o-', color='green', label='X - ACES RGB') settings = {'title': 'sRGB - ACES RGB - Uniformly Spaced Incrementing RGB', 'x_label': 'k', 'y_label': 'X', 'x_tighten': True, 'legend': True, 'legend_location': 'upper left', 'x_ticker': True, 'y_ticker': True} decorate(**settings) display(**settings) k = np.linspace(0, 1, 10) X_sRGB = lambda x: 0.41238656 * x X_ACES = lambda x: 0.9525524 * x pylab.plot(k, tuple(map(X_sRGB, k)), 'o-', color='red', label='X - sRGB') pylab.plot(k, tuple(map(X_ACES, k)), 'o-', color='green', label='X - ACES RGB') settings = {'title': 'sRGB - ACES RGB - Uniformly Spaced Incrementing R', 'x_label': 'k', 'y_label': 'X', 'x_tighten': True, 'legend': True, 'legend_location': 'upper left', 'x_ticker': True, 'y_ticker': True} decorate(**settings) display(**settings) pylab.plot(X_sRGB(0.172906) * X_sRGB(0.05440562), 0, 'o', color='red', label='X - "dark skin" * "green" sRGB') pylab.plot(X_ACES(0.11758989) * X_ACES(0.15129818), 0, 'o', color='green', label='X - "dark skin" * "green" ACES RGB') settings = {'title': 'sRGB - ACES RGB - X Value - "dark skin" * "green"', 'x_label': 'X Value', 'x_tighten': True, 'legend': True, 'legend_location': 'upper left', 'x_ticker': True, 'y_ticker': True} decorate(**settings) display(**settings) colourspaces_CIE_1931_chromaticity_diagram_plot( ['Pointer Gamut', 'sRGB', 'Rec. 2020', 'ACES RGB']) XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1, sRGB_w, illuminant, sRGB_RGB_to_XYZ) XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, illuminant, sRGB_RGB_to_XYZ)