diff --git a/pages/colour-science-for-python.ipynb b/pages/colour-science-for-python.ipynb index 042dcafd..dcf631ac 100644 --- a/pages/colour-science-for-python.ipynb +++ b/pages/colour-science-for-python.ipynb @@ -40,7 +40,7 @@ } ], "source": [ - "sd = colour.SDS_ILLUMINANTS.get('FL2')\n", + "sd = colour.SDS_ILLUMINANTS.get(\"FL2\")\n", "colour.colour_fidelity_index(sd)" ] }, @@ -68,8 +68,8 @@ } ], "source": [ - "il = colour.CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50']\n", - "colour.xy_to_CCT(il, method='Hernandez 1999')" + "il = colour.CCS_ILLUMINANTS[\"CIE 1931 2 Degree Standard Observer\"][\"D50\"]\n", + "colour.xy_to_CCT(il, method=\"Hernandez 1999\")" ] }, { diff --git a/posts/a-plea-for-colour-analysis-tools-in-dcc-applications.ipynb b/posts/a-plea-for-colour-analysis-tools-in-dcc-applications.ipynb index 83f911d9..3c8f8faf 100644 --- a/posts/a-plea-for-colour-analysis-tools-in-dcc-applications.ipynb +++ b/posts/a-plea-for-colour-analysis-tools-in-dcc-applications.ipynb @@ -77,27 +77,28 @@ " image = ImageInput.open(path)\n", " specification = image.spec()\n", "\n", - " return np.array(image.read_image(FLOAT)).reshape((specification.height,\n", - " specification.width,\n", - " specification.nchannels))\n", + " return np.array(image.read_image(FLOAT)).reshape(\n", + " (specification.height, specification.width, specification.nchannels)\n", + " )\n", "\n", "\n", - "def image_plot(image,\n", - " OECF=colour.sRGB_COLOURSPACE.OECF):\n", + "def image_plot(image, OECF=colour.sRGB_COLOURSPACE.OECF):\n", " vectorised_oecf = np.vectorize(OECF)\n", " image = np.clip(vectorised_oecf(image), 0, 1)\n", " pylab.imshow(image)\n", "\n", - " settings = {'no_ticks': True,\n", - " 'bounding_box': [0, 1, 0, 1],\n", - " 'bbox_inches': 'tight',\n", - " 'pad_inches': 0}\n", + " settings = {\n", + " \"no_ticks\": True,\n", + " \"bounding_box\": [0, 1, 0, 1],\n", + " \"bbox_inches\": \"tight\",\n", + " \"pad_inches\": 0,\n", + " }\n", "\n", " aspect(**settings)\n", " display(**settings)\n", "\n", "\n", - "ACES_image = exr_image_as_array('resources/images/SonyF35.StillLife_medium.exr')\n", + "ACES_image = exr_image_as_array(\"resources/images/SonyF35.StillLife_medium.exr\")\n", "image_plot(ACES_image)" ] }, @@ -152,10 +153,10 @@ "\n", "message_box('Computing \"ACES RGB\" colourspace to \"sRGB\" colourspace matrix.')\n", "\n", - "cat = colour.chromatic_adaptation_matrix(colour.xy_to_XYZ(ACES_w),\n", - " colour.xy_to_XYZ(sRGB_w))\n", - "ACES_RGB_to_sRGB_matrix = np.dot(sRGB_XYZ_to_RGB,\n", - " np.dot(cat, ACES_RGB_to_XYZ))\n", + "cat = colour.chromatic_adaptation_matrix(\n", + " colour.xy_to_XYZ(ACES_w), colour.xy_to_XYZ(sRGB_w)\n", + ")\n", + "ACES_RGB_to_sRGB_matrix = np.dot(sRGB_XYZ_to_RGB, np.dot(cat, ACES_RGB_to_XYZ))\n", "\n", "print(ACES_RGB_to_sRGB_matrix)" ] @@ -187,7 +188,9 @@ ], "source": [ "ACES_image_shape = ACES_image.shape\n", - "sRGB_image = np.array([np.dot(ACES_RGB_to_sRGB_matrix, RGB) for RGB in ACES_image.reshape((-1, 3))])\n", + "sRGB_image = np.array(\n", + " [np.dot(ACES_RGB_to_sRGB_matrix, RGB) for RGB in ACES_image.reshape((-1, 3))]\n", + ")\n", "sRGB_image = sRGB_image.reshape(ACES_image_shape)\n", "image_plot(sRGB_image)" ] @@ -240,23 +243,18 @@ "\n", "\n", "def ACES_to_xy(RGB):\n", - " return colour.XYZ_to_xy(\n", - " colour.RGB_to_XYZ(RGB,\n", - " ACES_w,\n", - " ACES_w,\n", - " ACES_RGB_to_XYZ))\n", + " return colour.XYZ_to_xy(colour.RGB_to_XYZ(RGB, ACES_w, ACES_w, ACES_RGB_to_XYZ))\n", "\n", "\n", "def image_chromaticities_plot(image, to_xy=ACES_to_xy):\n", " colourspaces_CIE_1931_chromaticity_diagram_plot(\n", - " ['Pointer Gamut', 'sRGB', 'Rec. 2020', 'ACES RGB'],\n", - " standalone=False)\n", + " [\"Pointer Gamut\", \"sRGB\", \"Rec. 2020\", \"ACES RGB\"], standalone=False\n", + " )\n", "\n", - " alpha_p, colour_p = 0.85, 'black'\n", + " alpha_p, colour_p = 0.85, \"black\"\n", "\n", " xy = np.array([to_xy(RGB) for RGB in image.reshape((-1, 3))])\n", - " pylab.scatter(xy[:, 0], xy[:, 1], alpha=alpha_p / 2, color=colour_p,\n", - " marker='+')\n", + " pylab.scatter(xy[:, 0], xy[:, 1], alpha=alpha_p / 2, color=colour_p, marker=\"+\")\n", "\n", " display(standalone=True)\n", "\n", @@ -296,14 +294,12 @@ "def sRGB_to_xy(RGB):\n", " RGB_key = tuple(RGB)\n", " if not RGB_key in sRGB_CHROMATICITIES_CACHE:\n", - " sRGB_CHROMATICITIES_CACHE[RGB_key] = (\n", - " colour.XYZ_to_xy(\n", - " colour.RGB_to_XYZ(RGB,\n", - " sRGB_w,\n", - " sRGB_w,\n", - " sRGB_RGB_to_XYZ)))\n", + " sRGB_CHROMATICITIES_CACHE[RGB_key] = colour.XYZ_to_xy(\n", + " colour.RGB_to_XYZ(RGB, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ)\n", + " )\n", " return sRGB_CHROMATICITIES_CACHE[RGB_key]\n", "\n", + "\n", "image_chromaticities_plot(sRGB_image, sRGB_to_xy)" ] }, @@ -363,9 +359,8 @@ " triangulation = Delaunay(points)\n", " image_illegal = np.copy(image).reshape((-1, 3))\n", " legal_colours_mask = np.array(\n", - " [within_boundaries(to_xy(RGB), triangulation)\n", - " for RGB in\n", - " image_illegal])\n", + " [within_boundaries(to_xy(RGB), triangulation) for RGB in image_illegal]\n", + " )\n", " image_illegal[legal_colours_mask] = 0\n", " return image_illegal.reshape(image.shape)\n", "\n", @@ -414,30 +409,25 @@ "\n", "# Computing *sRGB* to *Rec. 2020* colourspace transformation matrix.\n", "cat = colour.chromatic_adaptation_matrix(\n", - " colour.xy_to_XYZ(sRGB_w),\n", - " colour.xy_to_XYZ(Rec_2020_w))\n", - "Rec_2020_to_sRGB_matrix = (\n", - " np.dot(Rec_2020_XYZ_to_RGB,\n", - " np.dot(cat, sRGB_RGB_to_XYZ)))\n", + " colour.xy_to_XYZ(sRGB_w), colour.xy_to_XYZ(Rec_2020_w)\n", + ")\n", + "Rec_2020_to_sRGB_matrix = np.dot(Rec_2020_XYZ_to_RGB, np.dot(cat, sRGB_RGB_to_XYZ))\n", "\n", "\n", "def Rec_2020_to_xy(RGB):\n", " return colour.XYZ_to_xy(\n", - " colour.RGB_to_XYZ(RGB,\n", - " Rec_2020_w,\n", - " Rec_2020_w,\n", - " Rec_2020_RGB_to_XYZ))\n", + " colour.RGB_to_XYZ(RGB, Rec_2020_w, Rec_2020_w, Rec_2020_RGB_to_XYZ)\n", + " )\n", "\n", "\n", - "Rec_2020_image = np.array([np.dot(Rec_2020_to_sRGB_matrix, RGB)\n", - " for RGB in\n", - " sRGB_image.reshape((-1, 3))])\n", + "Rec_2020_image = np.array(\n", + " [np.dot(Rec_2020_to_sRGB_matrix, RGB) for RGB in sRGB_image.reshape((-1, 3))]\n", + ")\n", "Rec_2020_image = Rec_2020_image.reshape(ACES_image_shape)\n", "\n", - "Rec_2020_image_illegal = (\n", - " mask_legal_colours(np.copy(Rec_2020_image), \n", - " Rec_2020_p, \n", - " Rec_2020_to_xy))\n", + "Rec_2020_image_illegal = mask_legal_colours(\n", + " np.copy(Rec_2020_image), Rec_2020_p, Rec_2020_to_xy\n", + ")\n", "\n", "# Scaling the data to make it more obvious.\n", "Rec_2020_image_illegal *= 100\n", @@ -477,7 +467,9 @@ } ], "source": [ - "pointer_gamut_illegal_image = mask_legal_colours(sRGB_image, colour.POINTER_GAMUT_BOUNDARIES)\n", + "pointer_gamut_illegal_image = mask_legal_colours(\n", + " sRGB_image, colour.POINTER_GAMUT_BOUNDARIES\n", + ")\n", "\n", "# Scaling the data to make it more obvious.\n", "pointer_gamut_illegal_image *= 100\n", @@ -519,7 +511,7 @@ } ], "source": [ - "cmfs = colour.CMFS.get('CIE 1931 2 Degree Standard Observer')\n", + "cmfs = colour.CMFS.get(\"CIE 1931 2 Degree Standard Observer\")\n", "spectral_locus_xy = np.array([colour.XYZ_to_xy(x) for x in cmfs.values])\n", "\n", "spectral_locus_illegal_image = mask_legal_colours(sRGB_image, spectral_locus_xy)\n", diff --git a/posts/about-reflectance-recovery.ipynb b/posts/about-reflectance-recovery.ipynb index 89c5a68a..39f0ba11 100644 --- a/posts/about-reflectance-recovery.ipynb +++ b/posts/about-reflectance-recovery.ipynb @@ -2736,19 +2736,17 @@ "\n", "import colour\n", "from colour.plotting import *\n", - "from colour.recovery.smits1999 import (\n", - " SMITS1999_WHITEPOINT,\n", - " XYZ_to_RGB_Smits1999)\n", + "from colour.recovery.smits1999 import SMITS1999_WHITEPOINT, XYZ_to_RGB_Smits1999\n", "from colour.utilities.verbose import message_box\n", "\n", - "TEST_ILLUMINANTS = ('A', 'C', 'D65', 'F1', 'F7', 'F10', 'FL3.1', 'FL3.15')\n", + "TEST_ILLUMINANTS = (\"A\", \"C\", \"D65\", \"F1\", \"F7\", \"F10\", \"FL3.1\", \"FL3.15\")\n", "\n", - "CAT = 'Bradford'\n", + "CAT = \"Bradford\"\n", "\n", "\n", "def batch(iterable, k=3):\n", " for i in range(0, len(iterable), k):\n", - " yield iterable[i:i + k]\n", + " yield iterable[i : i + k]\n", "\n", "\n", "def clamp(RGB):\n", @@ -2756,74 +2754,93 @@ "\n", "\n", "def reflectance_recovery_plot(samples):\n", - " message_box('\"{0}\" - Reflectance Recovery'.format(', '.join(samples)))\n", + " message_box('\"{0}\" - Reflectance Recovery'.format(\", \".join(samples)))\n", "\n", " spds = []\n", " colour_parameters_data = []\n", " for sample in samples:\n", - " spd_r = colour.COLOURCHECKERS_SPDS['ColorChecker N Ohta'][sample]\n", - " XYZ_r = colour.spectral_to_XYZ(\n", - " spd_r,\n", - " illuminant=colour.ILLUMINANTS_RELATIVE_SPDS['E']) / 100\n", + " spd_r = colour.COLOURCHECKERS_SPDS[\"ColorChecker N Ohta\"][sample]\n", + " XYZ_r = (\n", + " colour.spectral_to_XYZ(\n", + " spd_r, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[\"E\"]\n", + " )\n", + " / 100\n", + " )\n", " sRGB_r = XYZ_to_RGB_Smits1999(XYZ_r)\n", " Lab_r = colour.XYZ_to_Lab(XYZ_r, SMITS1999_WHITEPOINT)\n", "\n", " spd_m = colour.RGB_to_spectral_Smits1999(sRGB_r).align(spd_r.shape)\n", - " XYZ_m = colour.spectral_to_XYZ(\n", - " spd_m,\n", - " illuminant=colour.ILLUMINANTS_RELATIVE_SPDS['E']) / 100\n", - " sRGB_m = colour.XYZ_to_sRGB(XYZ_m,\n", - " SMITS1999_WHITEPOINT,\n", - " CAT)\n", + " XYZ_m = (\n", + " colour.spectral_to_XYZ(\n", + " spd_m, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[\"E\"]\n", + " )\n", + " / 100\n", + " )\n", + " sRGB_m = colour.XYZ_to_sRGB(XYZ_m, SMITS1999_WHITEPOINT, CAT)\n", " Lab_m = colour.XYZ_to_Lab(XYZ_m, SMITS1999_WHITEPOINT)\n", "\n", " delta_E = colour.delta_E_CIE2000(Lab_r, Lab_m)\n", "\n", - " spd_m.name = '{0} - Smits (1999)'.format(sample)\n", + " spd_m.name = \"{0} - Smits (1999)\".format(sample)\n", " spds.append((spd_r, spd_m))\n", "\n", " colour_parameters_data.append(\n", - " ('E - Reference',\n", - " spd_r.name,\n", - " [colour.sRGB_COLOURSPACE.transfer_function(c) for c in sRGB_r],\n", - " spd_m.name,\n", - " sRGB_m,\n", - " delta_E))\n", + " (\n", + " \"E - Reference\",\n", + " spd_r.name,\n", + " [colour.sRGB_COLOURSPACE.transfer_function(c) for c in sRGB_r],\n", + " spd_m.name,\n", + " sRGB_m,\n", + " delta_E,\n", + " )\n", + " )\n", "\n", " for illuminant in TEST_ILLUMINANTS:\n", - " xy = colour.ILLUMINANTS['cie_2_1931'][illuminant]\n", - " XYZ_r = colour.spectral_to_XYZ(\n", - " spd_r,\n", - " illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]) / 100\n", + " xy = colour.ILLUMINANTS[\"cie_2_1931\"][illuminant]\n", + " XYZ_r = (\n", + " colour.spectral_to_XYZ(\n", + " spd_r, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]\n", + " )\n", + " / 100\n", + " )\n", " sRGB_r = colour.XYZ_to_sRGB(XYZ_r, xy, CAT)\n", " Lab_r = colour.XYZ_to_Lab(XYZ_r, xy)\n", "\n", - " XYZ_m = colour.spectral_to_XYZ(\n", - " spd_m,\n", - " illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]) / 100\n", + " XYZ_m = (\n", + " colour.spectral_to_XYZ(\n", + " spd_m, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]\n", + " )\n", + " / 100\n", + " )\n", " sRGB_m = colour.XYZ_to_sRGB(XYZ_m, xy, CAT)\n", " Lab_m = colour.XYZ_to_Lab(XYZ_m, xy)\n", "\n", " delta_E = colour.delta_E_CIE2000(Lab_r, Lab_m)\n", "\n", " colour_parameters_data.append(\n", - " (illuminant, spd_r.name, sRGB_r, spd_m.name, sRGB_m, delta_E))\n", + " (illuminant, spd_r.name, sRGB_r, spd_m.name, sRGB_m, delta_E)\n", + " )\n", "\n", - " multi_spd_plot(chain.from_iterable(spds), legend_location='upper right')\n", + " multi_spd_plot(chain.from_iterable(spds), legend_location=\"upper right\")\n", " for data in colour_parameters_data:\n", " illuminant, name_r, sRGB_r, name_m, sRGB_m, delta_E = data\n", " multi_colour_plot(\n", - " [colour_parameter(name_r,\n", - " clamp(sRGB_r)),\n", - " colour_parameter(\n", - " \"Delta E: {0}\\n{1}\".format(np.around(delta_E, 4), name_m),\n", - " clamp(sRGB_m))],\n", - " title='Illuminant {0}'.format(illuminant),\n", - " text_size=24)\n", + " [\n", + " colour_parameter(name_r, clamp(sRGB_r)),\n", + " colour_parameter(\n", + " \"Delta E: {0}\\n{1}\".format(np.around(delta_E, 4), name_m),\n", + " clamp(sRGB_m),\n", + " ),\n", + " ],\n", + " title=\"Illuminant {0}\".format(illuminant),\n", + " text_size=24,\n", + " )\n", "\n", "\n", - "samples = [sample for _, sample in\n", - " sorted(colour.COLOURCHECKER_INDEXES_TO_NAMES_MAPPING.items())]\n", + "samples = [\n", + " sample\n", + " for _, sample in sorted(colour.COLOURCHECKER_INDEXES_TO_NAMES_MAPPING.items())\n", + "]\n", "for samples_batch in batch(samples, 1):\n", " reflectance_recovery_plot(samples_batch)" ] diff --git a/posts/about-rendering-engines-colourspace-agnosticism.ipynb b/posts/about-rendering-engines-colourspace-agnosticism.ipynb index ba322376..48db02dc 100644 --- a/posts/about-rendering-engines-colourspace-agnosticism.ipynb +++ b/posts/about-rendering-engines-colourspace-agnosticism.ipynb @@ -110,7 +110,7 @@ "import colour\n", "from colour.utilities.verbose import message_box\n", "\n", - "name, data, illuminant = colour.COLOURCHECKERS['ColorChecker 2005']\n", + "name, data, illuminant = colour.COLOURCHECKERS[\"ColorChecker 2005\"]\n", "\n", "sRGB_w = colour.sRGB_COLOURSPACE.whitepoint\n", "sRGB_XYZ_to_RGB = colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix\n", @@ -127,28 +127,22 @@ "sRGB_rd1 = colour.XYZ_to_sRGB(XYZ_r1, illuminant)\n", "\n", "# *sRGB* colourspace linear values.\n", - "sRGB_r1 = colour.XYZ_to_RGB(XYZ_r1,\n", - " illuminant,\n", - " sRGB_w,\n", - " sRGB_XYZ_to_RGB)\n", + "sRGB_r1 = colour.XYZ_to_RGB(XYZ_r1, illuminant, sRGB_w, sRGB_XYZ_to_RGB)\n", "\n", "# *Adobe RGB 1998* colourspace linear values.\n", - "adobe98_r1 = colour.XYZ_to_RGB(XYZ_r1,\n", - " illuminant,\n", - " adobe98_w,\n", - " adobe98_XYZ_to_RGB)\n", - "\n", - "message_box(('Reference \"dark skin\" \"CIE XYZ\" colourspace tristimulus '\n", - " 'values:\\n'\n", - " '\\t{0}\\n'\n", - " '\\n\"sRGB\" colourspace values (OETF):\\n'\n", - " '\\n\\t{1}\\n'\n", - " '\\n\"sRGB\" and \"Adobe RGB 1998\" colourspaces (Linear):\\n'\n", - " '\\tsRGB: {2}\\n\\tAdobe RGB 1998: {3}').format(\n", - " XYZ_r1,\n", - " np.around(sRGB_rd1 * 255),\n", - " sRGB_r1,\n", - " adobe98_r1))\n", + "adobe98_r1 = colour.XYZ_to_RGB(XYZ_r1, illuminant, adobe98_w, adobe98_XYZ_to_RGB)\n", + "\n", + "message_box(\n", + " (\n", + " 'Reference \"dark skin\" \"CIE XYZ\" colourspace tristimulus '\n", + " \"values:\\n\"\n", + " \"\\t{0}\\n\"\n", + " '\\n\"sRGB\" colourspace values (OETF):\\n'\n", + " \"\\n\\t{1}\\n\"\n", + " '\\n\"sRGB\" and \"Adobe RGB 1998\" colourspaces (Linear):\\n'\n", + " \"\\tsRGB: {2}\\n\\tAdobe RGB 1998: {3}\"\n", + " ).format(XYZ_r1, np.around(sRGB_rd1 * 255), sRGB_r1, adobe98_r1)\n", + ")\n", "\n", "# Preparing *green* colour in various colourspaces.\n", "index, name, x, y, Y = data[13]\n", @@ -158,28 +152,22 @@ "sRGB_rd2 = colour.XYZ_to_sRGB(XYZ_r2, illuminant)\n", "\n", "# *sRGB* colourspace linear values.\n", - "sRGB_r2 = colour.XYZ_to_RGB(XYZ_r2,\n", - " illuminant,\n", - " sRGB_w,\n", - " sRGB_XYZ_to_RGB)\n", + "sRGB_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, sRGB_w, sRGB_XYZ_to_RGB)\n", "\n", "# *Adobe RGB 1998* colourspace linear values.\n", - "adobe98_r2 = colour.XYZ_to_RGB(XYZ_r2,\n", - " illuminant,\n", - " adobe98_w,\n", - " adobe98_XYZ_to_RGB)\n", - "\n", - "message_box(('Reference \"green\" \"CIE XYZ\" colourspace tristimulus '\n", - " 'values:\\n'\n", - " '\\t{0}\\n'\n", - " '\\n\"sRGB\" colourspace values (OETF):\\n'\n", - " '\\t{1}\\n'\n", - " '\\n\"sRGB\" and \"Adobe RGB 1998\" colourspaces (Linear):\\n'\n", - " '\\tsRGB: {2}\\n\\tAdobe RGB 1998: {3}').format(\n", - " XYZ_r2,\n", - " np.around(sRGB_rd2 * 255),\n", - " sRGB_r2,\n", - " adobe98_r2))" + "adobe98_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, adobe98_w, adobe98_XYZ_to_RGB)\n", + "\n", + "message_box(\n", + " (\n", + " 'Reference \"green\" \"CIE XYZ\" colourspace tristimulus '\n", + " \"values:\\n\"\n", + " \"\\t{0}\\n\"\n", + " '\\n\"sRGB\" colourspace values (OETF):\\n'\n", + " \"\\t{1}\\n\"\n", + " '\\n\"sRGB\" and \"Adobe RGB 1998\" colourspaces (Linear):\\n'\n", + " \"\\tsRGB: {2}\\n\\tAdobe RGB 1998: {3}\"\n", + " ).format(XYZ_r2, np.around(sRGB_rd2 * 255), sRGB_r2, adobe98_r2)\n", + ")" ] }, { @@ -222,22 +210,19 @@ } ], "source": [ - "XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1,\n", - " sRGB_w,\n", - " illuminant,\n", - " sRGB_RGB_to_XYZ)\n", - "\n", - "XYZ_adobe981 = colour.RGB_to_XYZ(adobe98_r1,\n", - " adobe98_w,\n", - " illuminant,\n", - " adobe98_RGB_to_XYZ)\n", - "\n", - "message_box(('Converting back \"dark skin\" \"CIE XYZ\" colourspace '\n", - " 'tristimulus values from \"sRGB\" and \"Adobe RGB 1998\" '\n", - " 'colourspaces:\\n'\n", - " '\\tFrom sRGB: {0}\\n\\tFrom Adobe RGB 1998: {1}\\n'\n", - " '\\nEverything looks fine!').format(\n", - " XYZ_sRGB1, XYZ_adobe981))" + "XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1, sRGB_w, illuminant, sRGB_RGB_to_XYZ)\n", + "\n", + "XYZ_adobe981 = colour.RGB_to_XYZ(adobe98_r1, adobe98_w, illuminant, adobe98_RGB_to_XYZ)\n", + "\n", + "message_box(\n", + " (\n", + " 'Converting back \"dark skin\" \"CIE XYZ\" colourspace '\n", + " 'tristimulus values from \"sRGB\" and \"Adobe RGB 1998\" '\n", + " \"colourspaces:\\n\"\n", + " \"\\tFrom sRGB: {0}\\n\\tFrom Adobe RGB 1998: {1}\\n\"\n", + " \"\\nEverything looks fine!\"\n", + " ).format(XYZ_sRGB1, XYZ_adobe981)\n", + ")" ] }, { @@ -309,34 +294,25 @@ "source": [ "k = np.array([500, 500, 500])\n", "\n", - "sRGB_k = colour.XYZ_to_RGB(k,\n", - " illuminant,\n", - " sRGB_w,\n", - " sRGB_XYZ_to_RGB)\n", - "adobe98_k = colour.XYZ_to_RGB(k,\n", - " illuminant,\n", - " adobe98_w,\n", - " adobe98_XYZ_to_RGB)\n", + "sRGB_k = colour.XYZ_to_RGB(k, illuminant, sRGB_w, sRGB_XYZ_to_RGB)\n", + "adobe98_k = colour.XYZ_to_RGB(k, illuminant, adobe98_w, adobe98_XYZ_to_RGB)\n", "\n", "sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * sRGB_k\n", "adobe98_m = adobe98_r1 * adobe98_r2 * adobe98_r2 * adobe98_r2 * adobe98_k\n", "\n", - "XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m,\n", - " sRGB_w,\n", - " sRGB_w,\n", - " sRGB_RGB_to_XYZ)\n", - "\n", - "XYZ_adobe98_m1 = colour.RGB_to_XYZ(adobe98_m,\n", - " adobe98_w,\n", - " adobe98_w,\n", - " adobe98_RGB_to_XYZ)\n", - "\n", - "message_box(('Multiplying \"dark skin\" with \"green\" and converting back to '\n", - " '\"CIE XYZ\" colourspace tristimulus values from \"sRGB\" and '\n", - " '\"Adobe RGB 1998\" colourspaces:\\n'\n", - " '\\tFrom sRGB: {0}\\n\\tFrom Adobe RGB 1998: {1}\\n'\n", - " '\\nHouston? We have a problem!').format(\n", - " XYZ_sRGB_m1, XYZ_adobe98_m1))" + "XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ)\n", + "\n", + "XYZ_adobe98_m1 = colour.RGB_to_XYZ(adobe98_m, adobe98_w, adobe98_w, adobe98_RGB_to_XYZ)\n", + "\n", + "message_box(\n", + " (\n", + " 'Multiplying \"dark skin\" with \"green\" and converting back to '\n", + " '\"CIE XYZ\" colourspace tristimulus values from \"sRGB\" and '\n", + " '\"Adobe RGB 1998\" colourspaces:\\n'\n", + " \"\\tFrom sRGB: {0}\\n\\tFrom Adobe RGB 1998: {1}\\n\"\n", + " \"\\nHouston? We have a problem!\"\n", + " ).format(XYZ_sRGB_m1, XYZ_adobe98_m1)\n", + ")" ] }, { @@ -388,7 +364,9 @@ "# remaining data should illustrate the effect.\n", "sRGB_difference = np.clip(sRGB_difference, 0, 1)\n", "\n", - "single_colour_plot(colour_parameter('sRGB - Adobe RGB 1998', sRGB_difference), text_size=24)" + "single_colour_plot(\n", + " colour_parameter(\"sRGB - Adobe RGB 1998\", sRGB_difference), text_size=24\n", + ")" ] }, { @@ -426,22 +404,24 @@ ], "source": [ "colourspaces_CIE_1931_chromaticity_diagram_plot(\n", - " ['sRGB', 'Adobe RGB 1998'],\n", - "standalone=False,\n", - "title='\"dark skin\" Colour Computation')\n", - "\n", - "for name, XYZ in (('\"dark skin\"', XYZ_r1),\n", - " ('\"dark skin\" * \"green\" - sRGB', XYZ_sRGB_m1),\n", - " ('\"dark skin\" * \"green\" - Adobe RGB 1998', XYZ_adobe98_m1)):\n", - " \n", + " [\"sRGB\", \"Adobe RGB 1998\"], standalone=False, title='\"dark skin\" Colour Computation'\n", + ")\n", + "\n", + "for name, XYZ in (\n", + " ('\"dark skin\"', XYZ_r1),\n", + " ('\"dark skin\" * \"green\" - sRGB', XYZ_sRGB_m1),\n", + " ('\"dark skin\" * \"green\" - Adobe RGB 1998', XYZ_adobe98_m1),\n", + "):\n", " xy = colour.XYZ_to_xy(XYZ)\n", "\n", - " pylab.plot(xy[0], xy[1], 'o', color='white')\n", - " pylab.annotate(name,\n", - " xy=xy,\n", - " xytext=(50, 30),\n", - " textcoords='offset points',\n", - " arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=0.2'))\n", + " pylab.plot(xy[0], xy[1], \"o\", color=\"white\")\n", + " pylab.annotate(\n", + " name,\n", + " xy=xy,\n", + " xytext=(50, 30),\n", + " textcoords=\"offset points\",\n", + " arrowprops=dict(arrowstyle=\"->\", connectionstyle=\"arc3, rad=0.2\"),\n", + " )\n", "\n", "display(standalone=True)" ] @@ -561,40 +541,24 @@ "aces_XYZ_to_RGB = colour.ACES_RGB_COLOURSPACE.XYZ_to_RGB_matrix\n", "aces_RGB_to_XYZ = colour.ACES_RGB_COLOURSPACE.RGB_to_XYZ_matrix\n", "\n", - "aces_r2 = colour.XYZ_to_RGB(XYZ_r2,\n", - " illuminant,\n", - " aces_w,\n", - " aces_XYZ_to_RGB)\n", - "aces_k = colour.XYZ_to_RGB(k,\n", - " illuminant,\n", - " aces_w,\n", - " aces_XYZ_to_RGB)\n", + "aces_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, aces_w, aces_XYZ_to_RGB)\n", + "aces_k = colour.XYZ_to_RGB(k, illuminant, aces_w, aces_XYZ_to_RGB)\n", "\n", "XYZs_m = []\n", "for index, name, x, y, Y in data:\n", " xyY = np.array([x, y, Y])\n", " sRGB_r1 = colour.XYZ_to_RGB(\n", - " colour.xyY_to_XYZ(xyY),\n", - " illuminant,\n", - " sRGB_w,\n", - " sRGB_XYZ_to_RGB)\n", + " colour.xyY_to_XYZ(xyY), illuminant, sRGB_w, sRGB_XYZ_to_RGB\n", + " )\n", " sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * sRGB_k\n", "\n", " aces_r1 = colour.XYZ_to_RGB(\n", - " colour.xyY_to_XYZ(xyY),\n", - " illuminant,\n", - " aces_w,\n", - " aces_XYZ_to_RGB)\n", + " colour.xyY_to_XYZ(xyY), illuminant, aces_w, aces_XYZ_to_RGB\n", + " )\n", " aces_m = aces_r1 * aces_r2 * aces_r2 * aces_r2 * aces_k\n", - " \n", - " XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m,\n", - " sRGB_w,\n", - " sRGB_w,\n", - " sRGB_RGB_to_XYZ)\n", - " XYZ_aces_m1 = colour.RGB_to_XYZ(aces_m,\n", - " aces_w,\n", - " aces_w,\n", - " aces_RGB_to_XYZ)\n", + "\n", + " XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ)\n", + " XYZ_aces_m1 = colour.RGB_to_XYZ(aces_m, aces_w, aces_w, aces_RGB_to_XYZ)\n", " XYZs_m.append((XYZ_sRGB_m1, XYZ_aces_m1))\n", "\n", "pprint(XYZs_m)" @@ -761,39 +725,25 @@ "rec2020_XYZ_to_RGB = colour.REC_2020_COLOURSPACE.XYZ_to_RGB_matrix\n", "rec2020_RGB_to_XYZ = colour.REC_2020_COLOURSPACE.RGB_to_XYZ_matrix\n", "\n", - "rec2020_r2 = colour.XYZ_to_RGB(XYZ_r2,\n", - " illuminant,\n", - " rec2020_w,\n", - " rec2020_XYZ_to_RGB)\n", - "rec2020_k = colour.XYZ_to_RGB(k,\n", - " illuminant,\n", - " aces_w,\n", - " aces_XYZ_to_RGB)\n", + "rec2020_r2 = colour.XYZ_to_RGB(XYZ_r2, illuminant, rec2020_w, rec2020_XYZ_to_RGB)\n", + "rec2020_k = colour.XYZ_to_RGB(k, illuminant, aces_w, aces_XYZ_to_RGB)\n", "XYZs_m = []\n", "for index, name, x, y, Y in data:\n", " xyY = np.array([x, y, Y])\n", " sRGB_r1 = colour.XYZ_to_RGB(\n", - " colour.xyY_to_XYZ(xyY),\n", - " illuminant,\n", - " sRGB_w,\n", - " sRGB_XYZ_to_RGB)\n", + " colour.xyY_to_XYZ(xyY), illuminant, sRGB_w, sRGB_XYZ_to_RGB\n", + " )\n", " sRGB_m = sRGB_r1 * sRGB_r2 * sRGB_r2 * sRGB_r2 * sRGB_k\n", "\n", " rec2020_r1 = colour.XYZ_to_RGB(\n", - " colour.xyY_to_XYZ(xyY),\n", - " illuminant,\n", - " rec2020_w,\n", - " rec2020_XYZ_to_RGB)\n", + " colour.xyY_to_XYZ(xyY), illuminant, rec2020_w, rec2020_XYZ_to_RGB\n", + " )\n", " rec2020_m = rec2020_r1 * rec2020_r2 * rec2020_r2 * rec2020_r2 * rec2020_k\n", "\n", - " XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m,\n", - " sRGB_w,\n", - " sRGB_w,\n", - " sRGB_RGB_to_XYZ)\n", - " XYZ_rec2020_m1 = colour.RGB_to_XYZ(rec2020_m,\n", - " rec2020_w,\n", - " rec2020_w,\n", - " rec2020_RGB_to_XYZ)\n", + " XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ)\n", + " XYZ_rec2020_m1 = colour.RGB_to_XYZ(\n", + " rec2020_m, rec2020_w, rec2020_w, rec2020_RGB_to_XYZ\n", + " )\n", " XYZs_m.append((XYZ_sRGB_m1, XYZ_rec2020_m1))\n", "\n", "pprint(XYZs_m)" @@ -988,17 +938,19 @@ "X_sRGB = lambda x: 0.41238656 * x + 0.35759149 * x + 0.18045049 * x\n", "X_ACES = lambda x: 0.9525524 * x + 0.00009368 * x\n", "\n", - "pylab.plot(k, tuple(map(X_sRGB, k)), 'o-', color='red', label='X - sRGB')\n", - "pylab.plot(k, tuple(map(X_ACES, k)), 'o-', color='green', label='X - ACES RGB')\n", - "\n", - "settings = {'title': 'sRGB - ACES RGB - Uniformly Spaced Incrementing RGB',\n", - " 'x_label': 'k',\n", - " 'y_label': 'X',\n", - " 'x_tighten': True,\n", - " 'legend': True,\n", - " 'legend_location': 'upper left',\n", - " 'x_ticker': True,\n", - " 'y_ticker': True}\n", + "pylab.plot(k, tuple(map(X_sRGB, k)), \"o-\", color=\"red\", label=\"X - sRGB\")\n", + "pylab.plot(k, tuple(map(X_ACES, k)), \"o-\", color=\"green\", label=\"X - ACES RGB\")\n", + "\n", + "settings = {\n", + " \"title\": \"sRGB - ACES RGB - Uniformly Spaced Incrementing RGB\",\n", + " \"x_label\": \"k\",\n", + " \"y_label\": \"X\",\n", + " \"x_tighten\": True,\n", + " \"legend\": True,\n", + " \"legend_location\": \"upper left\",\n", + " \"x_ticker\": True,\n", + " \"y_ticker\": True,\n", + "}\n", "decorate(**settings)\n", "display(**settings)" ] @@ -1041,17 +993,19 @@ "X_sRGB = lambda x: 0.41238656 * x\n", "X_ACES = lambda x: 0.9525524 * x\n", "\n", - "pylab.plot(k, tuple(map(X_sRGB, k)), 'o-', color='red', label='X - sRGB')\n", - "pylab.plot(k, tuple(map(X_ACES, k)), 'o-', color='green', label='X - ACES RGB')\n", - "\n", - "settings = {'title': 'sRGB - ACES RGB - Uniformly Spaced Incrementing R',\n", - " 'x_label': 'k',\n", - " 'y_label': 'X',\n", - " 'x_tighten': True,\n", - " 'legend': True,\n", - " 'legend_location': 'upper left',\n", - " 'x_ticker': True,\n", - " 'y_ticker': True}\n", + "pylab.plot(k, tuple(map(X_sRGB, k)), \"o-\", color=\"red\", label=\"X - sRGB\")\n", + "pylab.plot(k, tuple(map(X_ACES, k)), \"o-\", color=\"green\", label=\"X - ACES RGB\")\n", + "\n", + "settings = {\n", + " \"title\": \"sRGB - ACES RGB - Uniformly Spaced Incrementing R\",\n", + " \"x_label\": \"k\",\n", + " \"y_label\": \"X\",\n", + " \"x_tighten\": True,\n", + " \"legend\": True,\n", + " \"legend_location\": \"upper left\",\n", + " \"x_ticker\": True,\n", + " \"y_ticker\": True,\n", + "}\n", "decorate(**settings)\n", "display(**settings)" ] @@ -1092,16 +1046,30 @@ } ], "source": [ - "pylab.plot(X_sRGB(0.172906) * X_sRGB(0.05440562), 0, 'o', color='red', label='X - \"dark skin\" * \"green\" sRGB')\n", - "pylab.plot(X_ACES(0.11758989) * X_ACES(0.15129818), 0, 'o', color='green', label='X - \"dark skin\" * \"green\" ACES RGB')\n", - "\n", - "settings = {'title': 'sRGB - ACES RGB - X Value - \"dark skin\" * \"green\"',\n", - " 'x_label': 'X Value',\n", - " 'x_tighten': True,\n", - " 'legend': True,\n", - " 'legend_location': 'upper left',\n", - " 'x_ticker': True,\n", - " 'y_ticker': True}\n", + "pylab.plot(\n", + " X_sRGB(0.172906) * X_sRGB(0.05440562),\n", + " 0,\n", + " \"o\",\n", + " color=\"red\",\n", + " label='X - \"dark skin\" * \"green\" sRGB',\n", + ")\n", + "pylab.plot(\n", + " X_ACES(0.11758989) * X_ACES(0.15129818),\n", + " 0,\n", + " \"o\",\n", + " color=\"green\",\n", + " label='X - \"dark skin\" * \"green\" ACES RGB',\n", + ")\n", + "\n", + "settings = {\n", + " \"title\": 'sRGB - ACES RGB - X Value - \"dark skin\" * \"green\"',\n", + " \"x_label\": \"X Value\",\n", + " \"x_tighten\": True,\n", + " \"legend\": True,\n", + " \"legend_location\": \"upper left\",\n", + " \"x_ticker\": True,\n", + " \"y_ticker\": True,\n", + "}\n", "decorate(**settings)\n", "display(**settings)" ] @@ -1141,7 +1109,8 @@ ], "source": [ "colourspaces_CIE_1931_chromaticity_diagram_plot(\n", - " ['Pointer Gamut', 'sRGB', 'Rec. 2020', 'ACES RGB'])" + " [\"Pointer Gamut\", \"sRGB\", \"Rec. 2020\", \"ACES RGB\"]\n", + ")" ] }, { @@ -1199,10 +1168,7 @@ }, "outputs": [], "source": [ - "XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1,\n", - " sRGB_w,\n", - " illuminant,\n", - " sRGB_RGB_to_XYZ)" + "XYZ_sRGB1 = colour.RGB_to_XYZ(sRGB_r1, sRGB_w, illuminant, sRGB_RGB_to_XYZ)" ] }, { @@ -1220,10 +1186,7 @@ }, "outputs": [], "source": [ - "XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m,\n", - " sRGB_w,\n", - " illuminant,\n", - " sRGB_RGB_to_XYZ)" + "XYZ_sRGB_m1 = colour.RGB_to_XYZ(sRGB_m, sRGB_w, illuminant, sRGB_RGB_to_XYZ)" ] }, { diff --git a/posts/red-colourspaces-derivation.ipynb b/posts/red-colourspaces-derivation.ipynb index 766478a0..a7731e3d 100644 --- a/posts/red-colourspaces-derivation.ipynb +++ b/posts/red-colourspaces-derivation.ipynb @@ -73,10 +73,11 @@ "\n", "warnings.simplefilter(\"ignore\")\n", "\n", - "# Plotting a few selected *RGB* colourspaces in \n", + "# Plotting a few selected *RGB* colourspaces in\n", "# *CIE 1931 Chromaticity Diagram*.\n", "RGB_colourspaces_CIE_1931_chromaticity_diagram_plot(\n", - " ['ACES2065-1', 'ACEScg', 'Rec. 2020', 'Rec. 709'])" + " [\"ACES2065-1\", \"ACEScg\", \"Rec. 2020\", \"Rec. 709\"]\n", + ")" ] }, { @@ -188,13 +189,17 @@ ], "source": [ "# Computing *ACES2065-1* primaries and whitepoint.\n", - "npm = np.array([[9.52552396e-01, 0.00000000e+00, 9.36786317e-05],\n", - " [3.43966450e-01, 7.28166097e-01, -7.21325464e-02],\n", - " [0.00000000e+00, 0.00000000e+00, 1.00882518e+00]])\n", + "npm = np.array(\n", + " [\n", + " [9.52552396e-01, 0.00000000e00, 9.36786317e-05],\n", + " [3.43966450e-01, 7.28166097e-01, -7.21325464e-02],\n", + " [0.00000000e00, 0.00000000e00, 1.00882518e00],\n", + " ]\n", + ")\n", "\n", "print(colour.primaries_whitepoint(npm))\n", - "print(colour.RGB_COLOURSPACES['ACES2065-1'].primaries)\n", - "print(colour.RGB_COLOURSPACES['ACES2065-1'].whitepoint)" + "print(colour.RGB_COLOURSPACES[\"ACES2065-1\"].primaries)\n", + "print(colour.RGB_COLOURSPACES[\"ACES2065-1\"].whitepoint)" ] }, { @@ -278,52 +283,75 @@ ], "source": [ "DRAGONCOLOR_TO_ACES_2065_1 = np.array(\n", - " [[0.532279, 0.376648, 0.091073],\n", - " [0.046344, 0.974513, -0.020860],\n", - " [-0.053976, -0.000320, 1.054267]])\n", + " [\n", + " [0.532279, 0.376648, 0.091073],\n", + " [0.046344, 0.974513, -0.020860],\n", + " [-0.053976, -0.000320, 1.054267],\n", + " ]\n", + ")\n", "\n", "DRAGONCOLOR2_TO_ACES_2065_1 = np.array(\n", - " [[0.468452, 0.331484, 0.200064],\n", - " [0.040787, 0.857658, 0.101553],\n", - " [-0.047504, -0.000282, 1.047756]])\n", + " [\n", + " [0.468452, 0.331484, 0.200064],\n", + " [0.040787, 0.857658, 0.101553],\n", + " [-0.047504, -0.000282, 1.047756],\n", + " ]\n", + ")\n", "\n", "REDCOLOR_TO_ACES_2065_1 = np.array(\n", - " [[0.451464, 0.388498, 0.160038],\n", - " [0.062716, 0.866790, 0.070491],\n", - " [-0.017541, 0.086921, 0.930590]])\n", + " [\n", + " [0.451464, 0.388498, 0.160038],\n", + " [0.062716, 0.866790, 0.070491],\n", + " [-0.017541, 0.086921, 0.930590],\n", + " ]\n", + ")\n", "\n", "REDCOLOR2_TO_ACES_2065_1 = np.array(\n", - " [[0.480997, 0.402289, 0.116714],\n", - " [-0.004938, 1.000154, 0.004781],\n", - " [-0.105257, 0.025320, 1.079907]])\n", + " [\n", + " [0.480997, 0.402289, 0.116714],\n", + " [-0.004938, 1.000154, 0.004781],\n", + " [-0.105257, 0.025320, 1.079907],\n", + " ]\n", + ")\n", "\n", "REDCOLOR3_TO_ACES_2065_1 = np.array(\n", - " [[0.512136, 0.360370, 0.127494],\n", - " [0.070377, 0.903884, 0.025737],\n", - " [-0.020824, 0.017671, 1.003123]])\n", + " [\n", + " [0.512136, 0.360370, 0.127494],\n", + " [0.070377, 0.903884, 0.025737],\n", + " [-0.020824, 0.017671, 1.003123],\n", + " ]\n", + ")\n", "\n", "REDCOLOR4_TO_ACES_2065_1 = np.array(\n", - " [[0.474202, 0.333677, 0.192121],\n", - " [0.065164, 0.836932, 0.097901],\n", - " [-0.019281, 0.016362, 1.002889]])\n", + " [\n", + " [0.474202, 0.333677, 0.192121],\n", + " [0.065164, 0.836932, 0.097901],\n", + " [-0.019281, 0.016362, 1.002889],\n", + " ]\n", + ")\n", "\n", "ACES2065_1_TO_sRGB = np.array(\n", - " [[2.5217167, -1.1341655, -0.3875512],\n", - " [-0.276476, 1.3727113, -0.0962348],\n", - " [-0.015382, -0.1529940, 1.1683768]])\n", + " [\n", + " [2.5217167, -1.1341655, -0.3875512],\n", + " [-0.276476, 1.3727113, -0.0962348],\n", + " [-0.015382, -0.1529940, 1.1683768],\n", + " ]\n", + ")\n", "\n", "RED_TO_ACES_2065_1_MATRICES = {\n", - " 'DRAGONcolor': DRAGONCOLOR_TO_ACES_2065_1,\n", - " 'DRAGONcolor2': DRAGONCOLOR2_TO_ACES_2065_1,\n", - " 'REDcolor': REDCOLOR_TO_ACES_2065_1,\n", - " 'REDcolor2': REDCOLOR2_TO_ACES_2065_1,\n", - " 'REDcolor3': REDCOLOR3_TO_ACES_2065_1,\n", - " 'REDcolor4': REDCOLOR4_TO_ACES_2065_1}\n", + " \"DRAGONcolor\": DRAGONCOLOR_TO_ACES_2065_1,\n", + " \"DRAGONcolor2\": DRAGONCOLOR2_TO_ACES_2065_1,\n", + " \"REDcolor\": REDCOLOR_TO_ACES_2065_1,\n", + " \"REDcolor2\": REDCOLOR2_TO_ACES_2065_1,\n", + " \"REDcolor3\": REDCOLOR3_TO_ACES_2065_1,\n", + " \"REDcolor4\": REDCOLOR4_TO_ACES_2065_1,\n", + "}\n", "\n", "\n", - "def RGB_to_RGB_matrix_to_normalised_primary_matrix(RGB_to_RGB_matrix,\n", - " XYZ_to_RGB_matrix):\n", - " M = np.einsum('...ij,...jk->...ik', RGB_to_RGB_matrix, XYZ_to_RGB_matrix)\n", + "def RGB_to_RGB_matrix_to_normalised_primary_matrix(\n", + " RGB_to_RGB_matrix, XYZ_to_RGB_matrix\n", + "):\n", + " M = np.einsum(\"...ij,...jk->...ik\", RGB_to_RGB_matrix, XYZ_to_RGB_matrix)\n", "\n", " M = np.linalg.inv(M)\n", "\n", @@ -335,7 +363,8 @@ " for name, RGB_to_RGB_matrix in RED_TO_ACES_2065_1_MATRICES.items():\n", " NPM = RGB_to_RGB_matrix_to_normalised_primary_matrix(\n", " np.linalg.inv(RGB_to_RGB_matrix),\n", - " colour.RGB_COLOURSPACES['ACES2065-1'].XYZ_to_RGB_matrix)\n", + " colour.RGB_COLOURSPACES[\"ACES2065-1\"].XYZ_to_RGB_matrix,\n", + " )\n", "\n", " P, W = colour.primaries_whitepoint(NPM)\n", "\n", @@ -343,30 +372,31 @@ " name,\n", " primaries=P,\n", " whitepoint=W,\n", - " illuminant='D60',\n", + " illuminant=\"D60\",\n", " RGB_to_XYZ_matrix=NPM,\n", - " XYZ_to_RGB_matrix=np.linalg.inv(NPM))\n", + " XYZ_to_RGB_matrix=np.linalg.inv(NPM),\n", + " )\n", " return RED_colourspaces\n", "\n", "\n", "RED_COLOURSPACES = RED_colourspaces_derivation()\n", "colour.RGB_COLOURSPACES.update(RED_COLOURSPACES)\n", "\n", - "# Computing a derived *sRGB* colourspace as methodology \n", + "# Computing a derived *sRGB* colourspace as methodology\n", "# validation. Notice that the derived primaries are not exactly\n", - "# the same, which is likely to be the result of the input \n", + "# the same, which is likely to be the result of the input\n", "# matrices being rounded and chromatic adaptation precision.\n", "NPM = RGB_to_RGB_matrix_to_normalised_primary_matrix(\n", - " ACES2065_1_TO_sRGB,\n", - " colour.RGB_COLOURSPACES['ACES2065-1'].XYZ_to_RGB_matrix)\n", + " ACES2065_1_TO_sRGB, colour.RGB_COLOURSPACES[\"ACES2065-1\"].XYZ_to_RGB_matrix\n", + ")\n", "P, W = colour.primaries_whitepoint(NPM)\n", - "colour.RGB_COLOURSPACES['sRGB Derived'] = colour.RGB_Colourspace(\n", - " 'sRGB Derived',\n", - " primaries=P,\n", - " whitepoint=W)\n", + "colour.RGB_COLOURSPACES[\"sRGB Derived\"] = colour.RGB_Colourspace(\n", + " \"sRGB Derived\", primaries=P, whitepoint=W\n", + ")\n", "\n", "RGB_colourspaces_CIE_1931_chromaticity_diagram_plot(\n", - " ['sRGB', 'sRGB Derived'] + sorted(RED_COLOURSPACES.keys()))" + " [\"sRGB\", \"sRGB Derived\"] + sorted(RED_COLOURSPACES.keys())\n", + ")" ] }, { @@ -434,14 +464,15 @@ } ], "source": [ - "IMAGES_BASENAME = ('A014_C018_1227WK', 'A028_C158_09065U')\n", + "IMAGES_BASENAME = (\"A014_C018_1227WK\", \"A028_C158_09065U\")\n", "\n", - "OECF = colour.RGB_COLOURSPACES['sRGB'].transfer_function\n", + "OECF = colour.RGB_COLOURSPACES[\"sRGB\"].transfer_function\n", "\n", "for basename in IMAGES_BASENAME:\n", - " image_plot(OECF(colour.read_image(\n", - " 'resources/images/red/{0}_XYZ.exr'.format(basename))),\n", - " label='{0} - CIE XYZ Reference'.format(basename))" + " image_plot(\n", + " OECF(colour.read_image(\"resources/images/red/{0}_XYZ.exr\".format(basename))),\n", + " label=\"{0} - CIE XYZ Reference\".format(basename),\n", + " )" ] }, { @@ -566,83 +597,102 @@ } ], "source": [ - "D60 = colour.ILLUMINANTS['cie_2_1931']['D60']\n", + "D60 = colour.ILLUMINANTS[\"cie_2_1931\"][\"D60\"]\n", "\n", "# *VideoVillage* set of primaries solved through\n", "# image analysis and used for comparison.\n", "VV_PRIMARIES = {\n", - " 'REDcolor': np.array([\n", - " [0.682235759294, 0.320973856307],\n", - " [0.295705729612, 0.613311106957],\n", - " [0.134524597085, 0.034410956920]]),\n", - " 'REDcolor2': np.array([\n", - " [0.858485322390, 0.316594954144],\n", - " [0.292084791425, 0.667838655872],\n", - " [0.097651412967, 0.026565653796]]),\n", - " 'REDcolor3': np.array([\n", - " [0.682450885401, 0.320302618634],\n", - " [0.291813306036, 0.672642663443],\n", - " [0.109533374066, 0.006916855752]]),\n", - " 'REDcolor4': np.array([\n", - " [0.682432347, 0.320314427],\n", - " [0.291815909, 0.672638769],\n", - " [0.144290202, 0.050547336]]),\n", - " 'DRAGONcolor': np.array([\n", - " [0.733696621349, 0.319213119879],\n", - " [0.290807268864, 0.689667987865],\n", - " [0.083009416684, 0.050780628080]]),\n", - " 'DRAGONcolor2': np.array([\n", - " [0.733671536367, 0.319227712042],\n", - " [0.290804815281, 0.689668775507],\n", - " [0.143989704285, 0.050047743857]])}\n", + " \"REDcolor\": np.array(\n", + " [\n", + " [0.682235759294, 0.320973856307],\n", + " [0.295705729612, 0.613311106957],\n", + " [0.134524597085, 0.034410956920],\n", + " ]\n", + " ),\n", + " \"REDcolor2\": np.array(\n", + " [\n", + " [0.858485322390, 0.316594954144],\n", + " [0.292084791425, 0.667838655872],\n", + " [0.097651412967, 0.026565653796],\n", + " ]\n", + " ),\n", + " \"REDcolor3\": np.array(\n", + " [\n", + " [0.682450885401, 0.320302618634],\n", + " [0.291813306036, 0.672642663443],\n", + " [0.109533374066, 0.006916855752],\n", + " ]\n", + " ),\n", + " \"REDcolor4\": np.array(\n", + " [\n", + " [0.682432347, 0.320314427],\n", + " [0.291815909, 0.672638769],\n", + " [0.144290202, 0.050547336],\n", + " ]\n", + " ),\n", + " \"DRAGONcolor\": np.array(\n", + " [\n", + " [0.733696621349, 0.319213119879],\n", + " [0.290807268864, 0.689667987865],\n", + " [0.083009416684, 0.050780628080],\n", + " ]\n", + " ),\n", + " \"DRAGONcolor2\": np.array(\n", + " [\n", + " [0.733671536367, 0.319227712042],\n", + " [0.290804815281, 0.689668775507],\n", + " [0.143989704285, 0.050047743857],\n", + " ]\n", + " ),\n", + "}\n", "\n", "\n", "def RGB_colourspace_RMSE(colourspace):\n", " for basename in IMAGES_BASENAME:\n", " XYZ_image = colour.read_image(\n", - " 'resources/images/red/{0}_XYZ.exr'.format(basename))\n", + " \"resources/images/red/{0}_XYZ.exr\".format(basename)\n", + " )\n", "\n", " RGB_image = colour.read_image(\n", - " 'resources/images/red/{0}_{1}.exr'.format(basename,\n", - " colourspace))\n", + " \"resources/images/red/{0}_{1}.exr\".format(basename, colourspace)\n", + " )\n", "\n", " RGB_image_d = colour.XYZ_to_RGB(\n", " XYZ_image,\n", " D60,\n", " colour.RGB_COLOURSPACES[colourspace].whitepoint,\n", - " colour.RGB_COLOURSPACES[colourspace].XYZ_to_RGB_matrix)\n", + " colour.RGB_COLOURSPACES[colourspace].XYZ_to_RGB_matrix,\n", + " )\n", "\n", " rmse = np.std(np.ravel(RGB_image - RGB_image_d))\n", "\n", - " npm_vv = colour.normalised_primary_matrix(\n", - " VV_PRIMARIES[colourspace], D60)\n", + " npm_vv = colour.normalised_primary_matrix(VV_PRIMARIES[colourspace], D60)\n", "\n", - " RGB_image_vv = colour.XYZ_to_RGB(\n", - " XYZ_image,\n", - " D60,\n", - " D60,\n", - " np.linalg.inv(npm_vv))\n", + " RGB_image_vv = colour.XYZ_to_RGB(XYZ_image, D60, D60, np.linalg.inv(npm_vv))\n", "\n", " rmse_vv = np.std(np.ravel(RGB_image - RGB_image_vv))\n", "\n", - " image_plot(OECF(RGB_image),\n", - " label='{0} - {1} Reference'.format(basename,\n", - " colourspace))\n", - " image_plot(OECF(RGB_image_d),\n", - " label='{0} - {1} Derived'.format(basename,\n", - " colourspace))\n", - " image_plot(OECF(RGB_image_vv),\n", - " label='{0} - {1} VideoVillage'.format(basename,\n", - " colourspace))\n", + " image_plot(\n", + " OECF(RGB_image), label=\"{0} - {1} Reference\".format(basename, colourspace)\n", + " )\n", + " image_plot(\n", + " OECF(RGB_image_d), label=\"{0} - {1} Derived\".format(basename, colourspace)\n", + " )\n", + " image_plot(\n", + " OECF(RGB_image_vv),\n", + " label=\"{0} - {1} VideoVillage\".format(basename, colourspace),\n", + " )\n", "\n", - " colour.message_box(('{0}\\n\\n'\n", - " 'rmse : {1}\\n\\n'\n", - " 'rmse VV: {2}').format(basename, rmse, rmse_vv))\n", + " colour.message_box(\n", + " (\"{0}\\n\\n\" \"rmse : {1}\\n\\n\" \"rmse VV: {2}\").format(\n", + " basename, rmse, rmse_vv\n", + " )\n", + " )\n", "\n", - " print('\\n')\n", + " print(\"\\n\")\n", "\n", "\n", - "RGB_colourspace_RMSE('REDcolor')" + "RGB_colourspace_RMSE(\"REDcolor\")" ] }, { @@ -766,7 +816,7 @@ } ], "source": [ - "RGB_colourspace_RMSE('REDcolor2')" + "RGB_colourspace_RMSE(\"REDcolor2\")" ] }, { @@ -890,7 +940,7 @@ } ], "source": [ - "RGB_colourspace_RMSE('REDcolor3')" + "RGB_colourspace_RMSE(\"REDcolor3\")" ] }, { @@ -1015,7 +1065,7 @@ } ], "source": [ - "RGB_colourspace_RMSE('DRAGONcolor')" + "RGB_colourspace_RMSE(\"DRAGONcolor\")" ] }, { @@ -1056,12 +1106,13 @@ } ], "source": [ - "IMAGES_BASENAME = ('A007_L006_0101RQ.0000000F',)\n", + "IMAGES_BASENAME = (\"A007_L006_0101RQ.0000000F\",)\n", "\n", "for basename in IMAGES_BASENAME:\n", - " image_plot(OECF(colour.read_image(\n", - " 'resources/images/red/{0}_XYZ.exr'.format(basename))),\n", - " label='{0} - CIE XYZ Reference'.format(basename))" + " image_plot(\n", + " OECF(colour.read_image(\"resources/images/red/{0}_XYZ.exr\".format(basename))),\n", + " label=\"{0} - CIE XYZ Reference\".format(basename),\n", + " )" ] }, { @@ -1137,7 +1188,7 @@ } ], "source": [ - "RGB_colourspace_RMSE('REDcolor4')" + "RGB_colourspace_RMSE(\"REDcolor4\")" ] }, { @@ -1213,7 +1264,7 @@ } ], "source": [ - "RGB_colourspace_RMSE('DRAGONcolor2')" + "RGB_colourspace_RMSE(\"DRAGONcolor2\")" ] }, { @@ -1247,6 +1298,7 @@ "source": [ "from IPython.display import HTML\n", "\n", + "\n", "def HTML_format_matrix(M, precision=7):\n", " # Handling whitepoint tuples.\n", " M = np.asarray(M)\n", @@ -1259,50 +1311,55 @@ " html += ''\n", " for j in range(shape[1]):\n", " v = M[i][j]\n", - " pretty = '{{: 0.{}f}}'.format(precision).format(\n", - " v) if precision is not None else v\n", + " pretty = (\n", + " \"{{: 0.{}f}}\".format(precision).format(v)\n", + " if precision is not None\n", + " else v\n", + " )\n", " html += '{0}'.format(pretty)\n", - " html += ''\n", - " html += ''\n", + " html += \"\"\n", + " html += \"\"\n", " return html\n", "\n", "\n", "def html_format_colourspaces(colourspaces):\n", - " html = (''\n", - " ''\n", - " ''\n", - " ''\n", - " ''\n", - " ''\n", - "# ''\n", - "# ''\n", - "# ''\n", - " ''\n", - " ''\n", - " '')\n", + " html = (\n", + " '
PrimariesWhitepointIlluminantXYZ to RGBRGB to XYZ
'\n", + " ''\n", + " ''\n", + " ''\n", + " ''\n", + " ''\n", + " # ''\n", + " # ''\n", + " # ''\n", + " \"\"\n", + " \"\"\n", + " \"\"\n", + " )\n", " for i, colourspace in enumerate(colourspaces):\n", " html += ''.format(\n", - " 'table-row-odd' if i % 2 == 0 else '')\n", - " html += ''.format(\n", - " colourspace.name)\n", + " \"table-row-odd\" if i % 2 == 0 else \"\"\n", + " )\n", + " html += ''.format(colourspace.name)\n", " html += ''.format(\n", - " HTML_format_matrix(colourspace.primaries, precision=None))\n", + " HTML_format_matrix(colourspace.primaries, precision=None)\n", + " )\n", " html += ''.format(\n", - " HTML_format_matrix(colourspace.whitepoint, precision=None))\n", - "# html += ''.format(\n", - "# colourspace.illuminant)\n", - "# html += ''.format(\n", - "# HTML_format_matrix(colourspace.XYZ_to_RGB_matrix, precision=None))\n", - "# html += ''.format(\n", - "# HTML_format_matrix(colourspace.RGB_to_XYZ_matrix, precision=None))\n", - " html += ''\n", - " html += (''\n", - " '
PrimariesWhitepointIlluminantXYZ to RGBRGB to XYZ
{0}{0}{0}{0}{0}{0}{0}
')\n", + " HTML_format_matrix(colourspace.whitepoint, precision=None)\n", + " )\n", + " # html += '{0}'.format(\n", + " # colourspace.illuminant)\n", + " # html += '{0}'.format(\n", + " # HTML_format_matrix(colourspace.XYZ_to_RGB_matrix, precision=None))\n", + " # html += '{0}'.format(\n", + " # HTML_format_matrix(colourspace.RGB_to_XYZ_matrix, precision=None))\n", + " html += \"\"\n", + " html += \"\" \"\"\n", " return html\n", "\n", "\n", - "HTML(html_format_colourspaces(\n", - " (v for k, v in sorted(RED_COLOURSPACES.items()))))" + "HTML(html_format_colourspaces((v for k, v in sorted(RED_COLOURSPACES.items()))))" ] }, { @@ -1360,7 +1417,7 @@ } ], "source": [ - "HTML(\"\".format(open('style.css','r').read()))" + "HTML(\"\".format(open(\"style.css\", \"r\").read()))" ] }, {