Skip to content

Commit d1df97d

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5044440 commit d1df97d

5 files changed

+458
-429
lines changed

pages/colour-science-for-python.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
}
4141
],
4242
"source": [
43-
"sd = colour.SDS_ILLUMINANTS.get('FL2')\n",
43+
"sd = colour.SDS_ILLUMINANTS.get(\"FL2\")\n",
4444
"colour.colour_fidelity_index(sd)"
4545
]
4646
},
@@ -68,8 +68,8 @@
6868
}
6969
],
7070
"source": [
71-
"il = colour.CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50']\n",
72-
"colour.xy_to_CCT(il, method='Hernandez 1999')"
71+
"il = colour.CCS_ILLUMINANTS[\"CIE 1931 2 Degree Standard Observer\"][\"D50\"]\n",
72+
"colour.xy_to_CCT(il, method=\"Hernandez 1999\")"
7373
]
7474
},
7575
{

posts/a-plea-for-colour-analysis-tools-in-dcc-applications.ipynb

+44-52
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,28 @@
7777
" image = ImageInput.open(path)\n",
7878
" specification = image.spec()\n",
7979
"\n",
80-
" return np.array(image.read_image(FLOAT)).reshape((specification.height,\n",
81-
" specification.width,\n",
82-
" specification.nchannels))\n",
80+
" return np.array(image.read_image(FLOAT)).reshape(\n",
81+
" (specification.height, specification.width, specification.nchannels)\n",
82+
" )\n",
8383
"\n",
8484
"\n",
85-
"def image_plot(image,\n",
86-
" OECF=colour.sRGB_COLOURSPACE.OECF):\n",
85+
"def image_plot(image, OECF=colour.sRGB_COLOURSPACE.OECF):\n",
8786
" vectorised_oecf = np.vectorize(OECF)\n",
8887
" image = np.clip(vectorised_oecf(image), 0, 1)\n",
8988
" pylab.imshow(image)\n",
9089
"\n",
91-
" settings = {'no_ticks': True,\n",
92-
" 'bounding_box': [0, 1, 0, 1],\n",
93-
" 'bbox_inches': 'tight',\n",
94-
" 'pad_inches': 0}\n",
90+
" settings = {\n",
91+
" \"no_ticks\": True,\n",
92+
" \"bounding_box\": [0, 1, 0, 1],\n",
93+
" \"bbox_inches\": \"tight\",\n",
94+
" \"pad_inches\": 0,\n",
95+
" }\n",
9596
"\n",
9697
" aspect(**settings)\n",
9798
" display(**settings)\n",
9899
"\n",
99100
"\n",
100-
"ACES_image = exr_image_as_array('resources/images/SonyF35.StillLife_medium.exr')\n",
101+
"ACES_image = exr_image_as_array(\"resources/images/SonyF35.StillLife_medium.exr\")\n",
101102
"image_plot(ACES_image)"
102103
]
103104
},
@@ -152,10 +153,10 @@
152153
"\n",
153154
"message_box('Computing \"ACES RGB\" colourspace to \"sRGB\" colourspace matrix.')\n",
154155
"\n",
155-
"cat = colour.chromatic_adaptation_matrix(colour.xy_to_XYZ(ACES_w),\n",
156-
" colour.xy_to_XYZ(sRGB_w))\n",
157-
"ACES_RGB_to_sRGB_matrix = np.dot(sRGB_XYZ_to_RGB,\n",
158-
" np.dot(cat, ACES_RGB_to_XYZ))\n",
156+
"cat = colour.chromatic_adaptation_matrix(\n",
157+
" colour.xy_to_XYZ(ACES_w), colour.xy_to_XYZ(sRGB_w)\n",
158+
")\n",
159+
"ACES_RGB_to_sRGB_matrix = np.dot(sRGB_XYZ_to_RGB, np.dot(cat, ACES_RGB_to_XYZ))\n",
159160
"\n",
160161
"print(ACES_RGB_to_sRGB_matrix)"
161162
]
@@ -187,7 +188,9 @@
187188
],
188189
"source": [
189190
"ACES_image_shape = ACES_image.shape\n",
190-
"sRGB_image = np.array([np.dot(ACES_RGB_to_sRGB_matrix, RGB) for RGB in ACES_image.reshape((-1, 3))])\n",
191+
"sRGB_image = np.array(\n",
192+
" [np.dot(ACES_RGB_to_sRGB_matrix, RGB) for RGB in ACES_image.reshape((-1, 3))]\n",
193+
")\n",
191194
"sRGB_image = sRGB_image.reshape(ACES_image_shape)\n",
192195
"image_plot(sRGB_image)"
193196
]
@@ -240,23 +243,18 @@
240243
"\n",
241244
"\n",
242245
"def ACES_to_xy(RGB):\n",
243-
" return colour.XYZ_to_xy(\n",
244-
" colour.RGB_to_XYZ(RGB,\n",
245-
" ACES_w,\n",
246-
" ACES_w,\n",
247-
" ACES_RGB_to_XYZ))\n",
246+
" return colour.XYZ_to_xy(colour.RGB_to_XYZ(RGB, ACES_w, ACES_w, ACES_RGB_to_XYZ))\n",
248247
"\n",
249248
"\n",
250249
"def image_chromaticities_plot(image, to_xy=ACES_to_xy):\n",
251250
" colourspaces_CIE_1931_chromaticity_diagram_plot(\n",
252-
" ['Pointer Gamut', 'sRGB', 'Rec. 2020', 'ACES RGB'],\n",
253-
" standalone=False)\n",
251+
" [\"Pointer Gamut\", \"sRGB\", \"Rec. 2020\", \"ACES RGB\"], standalone=False\n",
252+
" )\n",
254253
"\n",
255-
" alpha_p, colour_p = 0.85, 'black'\n",
254+
" alpha_p, colour_p = 0.85, \"black\"\n",
256255
"\n",
257256
" xy = np.array([to_xy(RGB) for RGB in image.reshape((-1, 3))])\n",
258-
" pylab.scatter(xy[:, 0], xy[:, 1], alpha=alpha_p / 2, color=colour_p,\n",
259-
" marker='+')\n",
257+
" pylab.scatter(xy[:, 0], xy[:, 1], alpha=alpha_p / 2, color=colour_p, marker=\"+\")\n",
260258
"\n",
261259
" display(standalone=True)\n",
262260
"\n",
@@ -296,14 +294,12 @@
296294
"def sRGB_to_xy(RGB):\n",
297295
" RGB_key = tuple(RGB)\n",
298296
" if not RGB_key in sRGB_CHROMATICITIES_CACHE:\n",
299-
" sRGB_CHROMATICITIES_CACHE[RGB_key] = (\n",
300-
" colour.XYZ_to_xy(\n",
301-
" colour.RGB_to_XYZ(RGB,\n",
302-
" sRGB_w,\n",
303-
" sRGB_w,\n",
304-
" sRGB_RGB_to_XYZ)))\n",
297+
" sRGB_CHROMATICITIES_CACHE[RGB_key] = colour.XYZ_to_xy(\n",
298+
" colour.RGB_to_XYZ(RGB, sRGB_w, sRGB_w, sRGB_RGB_to_XYZ)\n",
299+
" )\n",
305300
" return sRGB_CHROMATICITIES_CACHE[RGB_key]\n",
306301
"\n",
302+
"\n",
307303
"image_chromaticities_plot(sRGB_image, sRGB_to_xy)"
308304
]
309305
},
@@ -363,9 +359,8 @@
363359
" triangulation = Delaunay(points)\n",
364360
" image_illegal = np.copy(image).reshape((-1, 3))\n",
365361
" legal_colours_mask = np.array(\n",
366-
" [within_boundaries(to_xy(RGB), triangulation)\n",
367-
" for RGB in\n",
368-
" image_illegal])\n",
362+
" [within_boundaries(to_xy(RGB), triangulation) for RGB in image_illegal]\n",
363+
" )\n",
369364
" image_illegal[legal_colours_mask] = 0\n",
370365
" return image_illegal.reshape(image.shape)\n",
371366
"\n",
@@ -414,30 +409,25 @@
414409
"\n",
415410
"# Computing *sRGB* to *Rec. 2020* colourspace transformation matrix.\n",
416411
"cat = colour.chromatic_adaptation_matrix(\n",
417-
" colour.xy_to_XYZ(sRGB_w),\n",
418-
" colour.xy_to_XYZ(Rec_2020_w))\n",
419-
"Rec_2020_to_sRGB_matrix = (\n",
420-
" np.dot(Rec_2020_XYZ_to_RGB,\n",
421-
" np.dot(cat, sRGB_RGB_to_XYZ)))\n",
412+
" colour.xy_to_XYZ(sRGB_w), colour.xy_to_XYZ(Rec_2020_w)\n",
413+
")\n",
414+
"Rec_2020_to_sRGB_matrix = np.dot(Rec_2020_XYZ_to_RGB, np.dot(cat, sRGB_RGB_to_XYZ))\n",
422415
"\n",
423416
"\n",
424417
"def Rec_2020_to_xy(RGB):\n",
425418
" return colour.XYZ_to_xy(\n",
426-
" colour.RGB_to_XYZ(RGB,\n",
427-
" Rec_2020_w,\n",
428-
" Rec_2020_w,\n",
429-
" Rec_2020_RGB_to_XYZ))\n",
419+
" colour.RGB_to_XYZ(RGB, Rec_2020_w, Rec_2020_w, Rec_2020_RGB_to_XYZ)\n",
420+
" )\n",
430421
"\n",
431422
"\n",
432-
"Rec_2020_image = np.array([np.dot(Rec_2020_to_sRGB_matrix, RGB)\n",
433-
" for RGB in\n",
434-
" sRGB_image.reshape((-1, 3))])\n",
423+
"Rec_2020_image = np.array(\n",
424+
" [np.dot(Rec_2020_to_sRGB_matrix, RGB) for RGB in sRGB_image.reshape((-1, 3))]\n",
425+
")\n",
435426
"Rec_2020_image = Rec_2020_image.reshape(ACES_image_shape)\n",
436427
"\n",
437-
"Rec_2020_image_illegal = (\n",
438-
" mask_legal_colours(np.copy(Rec_2020_image), \n",
439-
" Rec_2020_p, \n",
440-
" Rec_2020_to_xy))\n",
428+
"Rec_2020_image_illegal = mask_legal_colours(\n",
429+
" np.copy(Rec_2020_image), Rec_2020_p, Rec_2020_to_xy\n",
430+
")\n",
441431
"\n",
442432
"# Scaling the data to make it more obvious.\n",
443433
"Rec_2020_image_illegal *= 100\n",
@@ -477,7 +467,9 @@
477467
}
478468
],
479469
"source": [
480-
"pointer_gamut_illegal_image = mask_legal_colours(sRGB_image, colour.POINTER_GAMUT_BOUNDARIES)\n",
470+
"pointer_gamut_illegal_image = mask_legal_colours(\n",
471+
" sRGB_image, colour.POINTER_GAMUT_BOUNDARIES\n",
472+
")\n",
481473
"\n",
482474
"# Scaling the data to make it more obvious.\n",
483475
"pointer_gamut_illegal_image *= 100\n",
@@ -519,7 +511,7 @@
519511
}
520512
],
521513
"source": [
522-
"cmfs = colour.CMFS.get('CIE 1931 2 Degree Standard Observer')\n",
514+
"cmfs = colour.CMFS.get(\"CIE 1931 2 Degree Standard Observer\")\n",
523515
"spectral_locus_xy = np.array([colour.XYZ_to_xy(x) for x in cmfs.values])\n",
524516
"\n",
525517
"spectral_locus_illegal_image = mask_legal_colours(sRGB_image, spectral_locus_xy)\n",

posts/about-reflectance-recovery.ipynb

+59-42
Original file line numberDiff line numberDiff line change
@@ -2736,94 +2736,111 @@
27362736
"\n",
27372737
"import colour\n",
27382738
"from colour.plotting import *\n",
2739-
"from colour.recovery.smits1999 import (\n",
2740-
" SMITS1999_WHITEPOINT,\n",
2741-
" XYZ_to_RGB_Smits1999)\n",
2739+
"from colour.recovery.smits1999 import SMITS1999_WHITEPOINT, XYZ_to_RGB_Smits1999\n",
27422740
"from colour.utilities.verbose import message_box\n",
27432741
"\n",
2744-
"TEST_ILLUMINANTS = ('A', 'C', 'D65', 'F1', 'F7', 'F10', 'FL3.1', 'FL3.15')\n",
2742+
"TEST_ILLUMINANTS = (\"A\", \"C\", \"D65\", \"F1\", \"F7\", \"F10\", \"FL3.1\", \"FL3.15\")\n",
27452743
"\n",
2746-
"CAT = 'Bradford'\n",
2744+
"CAT = \"Bradford\"\n",
27472745
"\n",
27482746
"\n",
27492747
"def batch(iterable, k=3):\n",
27502748
" for i in range(0, len(iterable), k):\n",
2751-
" yield iterable[i:i + k]\n",
2749+
" yield iterable[i : i + k]\n",
27522750
"\n",
27532751
"\n",
27542752
"def clamp(RGB):\n",
27552753
" return np.clip(RGB, 0, 1)\n",
27562754
"\n",
27572755
"\n",
27582756
"def reflectance_recovery_plot(samples):\n",
2759-
" message_box('\"{0}\" - Reflectance Recovery'.format(', '.join(samples)))\n",
2757+
" message_box('\"{0}\" - Reflectance Recovery'.format(\", \".join(samples)))\n",
27602758
"\n",
27612759
" spds = []\n",
27622760
" colour_parameters_data = []\n",
27632761
" for sample in samples:\n",
2764-
" spd_r = colour.COLOURCHECKERS_SPDS['ColorChecker N Ohta'][sample]\n",
2765-
" XYZ_r = colour.spectral_to_XYZ(\n",
2766-
" spd_r,\n",
2767-
" illuminant=colour.ILLUMINANTS_RELATIVE_SPDS['E']) / 100\n",
2762+
" spd_r = colour.COLOURCHECKERS_SPDS[\"ColorChecker N Ohta\"][sample]\n",
2763+
" XYZ_r = (\n",
2764+
" colour.spectral_to_XYZ(\n",
2765+
" spd_r, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[\"E\"]\n",
2766+
" )\n",
2767+
" / 100\n",
2768+
" )\n",
27682769
" sRGB_r = XYZ_to_RGB_Smits1999(XYZ_r)\n",
27692770
" Lab_r = colour.XYZ_to_Lab(XYZ_r, SMITS1999_WHITEPOINT)\n",
27702771
"\n",
27712772
" spd_m = colour.RGB_to_spectral_Smits1999(sRGB_r).align(spd_r.shape)\n",
2772-
" XYZ_m = colour.spectral_to_XYZ(\n",
2773-
" spd_m,\n",
2774-
" illuminant=colour.ILLUMINANTS_RELATIVE_SPDS['E']) / 100\n",
2775-
" sRGB_m = colour.XYZ_to_sRGB(XYZ_m,\n",
2776-
" SMITS1999_WHITEPOINT,\n",
2777-
" CAT)\n",
2773+
" XYZ_m = (\n",
2774+
" colour.spectral_to_XYZ(\n",
2775+
" spd_m, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[\"E\"]\n",
2776+
" )\n",
2777+
" / 100\n",
2778+
" )\n",
2779+
" sRGB_m = colour.XYZ_to_sRGB(XYZ_m, SMITS1999_WHITEPOINT, CAT)\n",
27782780
" Lab_m = colour.XYZ_to_Lab(XYZ_m, SMITS1999_WHITEPOINT)\n",
27792781
"\n",
27802782
" delta_E = colour.delta_E_CIE2000(Lab_r, Lab_m)\n",
27812783
"\n",
2782-
" spd_m.name = '{0} - Smits (1999)'.format(sample)\n",
2784+
" spd_m.name = \"{0} - Smits (1999)\".format(sample)\n",
27832785
" spds.append((spd_r, spd_m))\n",
27842786
"\n",
27852787
" colour_parameters_data.append(\n",
2786-
" ('E - Reference',\n",
2787-
" spd_r.name,\n",
2788-
" [colour.sRGB_COLOURSPACE.transfer_function(c) for c in sRGB_r],\n",
2789-
" spd_m.name,\n",
2790-
" sRGB_m,\n",
2791-
" delta_E))\n",
2788+
" (\n",
2789+
" \"E - Reference\",\n",
2790+
" spd_r.name,\n",
2791+
" [colour.sRGB_COLOURSPACE.transfer_function(c) for c in sRGB_r],\n",
2792+
" spd_m.name,\n",
2793+
" sRGB_m,\n",
2794+
" delta_E,\n",
2795+
" )\n",
2796+
" )\n",
27922797
"\n",
27932798
" for illuminant in TEST_ILLUMINANTS:\n",
2794-
" xy = colour.ILLUMINANTS['cie_2_1931'][illuminant]\n",
2795-
" XYZ_r = colour.spectral_to_XYZ(\n",
2796-
" spd_r,\n",
2797-
" illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]) / 100\n",
2799+
" xy = colour.ILLUMINANTS[\"cie_2_1931\"][illuminant]\n",
2800+
" XYZ_r = (\n",
2801+
" colour.spectral_to_XYZ(\n",
2802+
" spd_r, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]\n",
2803+
" )\n",
2804+
" / 100\n",
2805+
" )\n",
27982806
" sRGB_r = colour.XYZ_to_sRGB(XYZ_r, xy, CAT)\n",
27992807
" Lab_r = colour.XYZ_to_Lab(XYZ_r, xy)\n",
28002808
"\n",
2801-
" XYZ_m = colour.spectral_to_XYZ(\n",
2802-
" spd_m,\n",
2803-
" illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]) / 100\n",
2809+
" XYZ_m = (\n",
2810+
" colour.spectral_to_XYZ(\n",
2811+
" spd_m, illuminant=colour.ILLUMINANTS_RELATIVE_SPDS[illuminant]\n",
2812+
" )\n",
2813+
" / 100\n",
2814+
" )\n",
28042815
" sRGB_m = colour.XYZ_to_sRGB(XYZ_m, xy, CAT)\n",
28052816
" Lab_m = colour.XYZ_to_Lab(XYZ_m, xy)\n",
28062817
"\n",
28072818
" delta_E = colour.delta_E_CIE2000(Lab_r, Lab_m)\n",
28082819
"\n",
28092820
" colour_parameters_data.append(\n",
2810-
" (illuminant, spd_r.name, sRGB_r, spd_m.name, sRGB_m, delta_E))\n",
2821+
" (illuminant, spd_r.name, sRGB_r, spd_m.name, sRGB_m, delta_E)\n",
2822+
" )\n",
28112823
"\n",
2812-
" multi_spd_plot(chain.from_iterable(spds), legend_location='upper right')\n",
2824+
" multi_spd_plot(chain.from_iterable(spds), legend_location=\"upper right\")\n",
28132825
" for data in colour_parameters_data:\n",
28142826
" illuminant, name_r, sRGB_r, name_m, sRGB_m, delta_E = data\n",
28152827
" multi_colour_plot(\n",
2816-
" [colour_parameter(name_r,\n",
2817-
" clamp(sRGB_r)),\n",
2818-
" colour_parameter(\n",
2819-
" \"Delta E: {0}\\n{1}\".format(np.around(delta_E, 4), name_m),\n",
2820-
" clamp(sRGB_m))],\n",
2821-
" title='Illuminant {0}'.format(illuminant),\n",
2822-
" text_size=24)\n",
2828+
" [\n",
2829+
" colour_parameter(name_r, clamp(sRGB_r)),\n",
2830+
" colour_parameter(\n",
2831+
" \"Delta E: {0}\\n{1}\".format(np.around(delta_E, 4), name_m),\n",
2832+
" clamp(sRGB_m),\n",
2833+
" ),\n",
2834+
" ],\n",
2835+
" title=\"Illuminant {0}\".format(illuminant),\n",
2836+
" text_size=24,\n",
2837+
" )\n",
28232838
"\n",
28242839
"\n",
2825-
"samples = [sample for _, sample in\n",
2826-
" sorted(colour.COLOURCHECKER_INDEXES_TO_NAMES_MAPPING.items())]\n",
2840+
"samples = [\n",
2841+
" sample\n",
2842+
" for _, sample in sorted(colour.COLOURCHECKER_INDEXES_TO_NAMES_MAPPING.items())\n",
2843+
"]\n",
28272844
"for samples_batch in batch(samples, 1):\n",
28282845
" reflectance_recovery_plot(samples_batch)"
28292846
]

0 commit comments

Comments
 (0)