Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 10, 2024
1 parent f7cb83c commit f3cc598
Show file tree
Hide file tree
Showing 5 changed files with 458 additions and 429 deletions.
6 changes: 3 additions & 3 deletions pages/colour-science-for-python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
],
"source": [
"sd = colour.SDS_ILLUMINANTS.get('FL2')\n",
"sd = colour.SDS_ILLUMINANTS.get(\"FL2\")\n",
"colour.colour_fidelity_index(sd)"
]
},
Expand Down Expand Up @@ -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\")"
]
},
{
Expand Down
96 changes: 44 additions & 52 deletions posts/a-plea-for-colour-analysis-tools-in-dcc-applications.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
Expand Down Expand Up @@ -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)"
]
Expand Down Expand Up @@ -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)"
]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
101 changes: 59 additions & 42 deletions posts/about-reflectance-recovery.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2736,94 +2736,111 @@
"\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",
" return np.clip(RGB, 0, 1)\n",
"\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)"
]
Expand Down
Loading

0 comments on commit f3cc598

Please sign in to comment.