|
77 | 77 | " image = ImageInput.open(path)\n",
|
78 | 78 | " specification = image.spec()\n",
|
79 | 79 | "\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", |
83 | 83 | "\n",
|
84 | 84 | "\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", |
87 | 86 | " vectorised_oecf = np.vectorize(OECF)\n",
|
88 | 87 | " image = np.clip(vectorised_oecf(image), 0, 1)\n",
|
89 | 88 | " pylab.imshow(image)\n",
|
90 | 89 | "\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", |
95 | 96 | "\n",
|
96 | 97 | " aspect(**settings)\n",
|
97 | 98 | " display(**settings)\n",
|
98 | 99 | "\n",
|
99 | 100 | "\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", |
101 | 102 | "image_plot(ACES_image)"
|
102 | 103 | ]
|
103 | 104 | },
|
|
152 | 153 | "\n",
|
153 | 154 | "message_box('Computing \"ACES RGB\" colourspace to \"sRGB\" colourspace matrix.')\n",
|
154 | 155 | "\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", |
159 | 160 | "\n",
|
160 | 161 | "print(ACES_RGB_to_sRGB_matrix)"
|
161 | 162 | ]
|
|
187 | 188 | ],
|
188 | 189 | "source": [
|
189 | 190 | "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", |
191 | 194 | "sRGB_image = sRGB_image.reshape(ACES_image_shape)\n",
|
192 | 195 | "image_plot(sRGB_image)"
|
193 | 196 | ]
|
|
240 | 243 | "\n",
|
241 | 244 | "\n",
|
242 | 245 | "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", |
248 | 247 | "\n",
|
249 | 248 | "\n",
|
250 | 249 | "def image_chromaticities_plot(image, to_xy=ACES_to_xy):\n",
|
251 | 250 | " 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", |
254 | 253 | "\n",
|
255 |
| - " alpha_p, colour_p = 0.85, 'black'\n", |
| 254 | + " alpha_p, colour_p = 0.85, \"black\"\n", |
256 | 255 | "\n",
|
257 | 256 | " 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", |
260 | 258 | "\n",
|
261 | 259 | " display(standalone=True)\n",
|
262 | 260 | "\n",
|
|
296 | 294 | "def sRGB_to_xy(RGB):\n",
|
297 | 295 | " RGB_key = tuple(RGB)\n",
|
298 | 296 | " 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", |
305 | 300 | " return sRGB_CHROMATICITIES_CACHE[RGB_key]\n",
|
306 | 301 | "\n",
|
| 302 | + "\n", |
307 | 303 | "image_chromaticities_plot(sRGB_image, sRGB_to_xy)"
|
308 | 304 | ]
|
309 | 305 | },
|
|
363 | 359 | " triangulation = Delaunay(points)\n",
|
364 | 360 | " image_illegal = np.copy(image).reshape((-1, 3))\n",
|
365 | 361 | " 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", |
369 | 364 | " image_illegal[legal_colours_mask] = 0\n",
|
370 | 365 | " return image_illegal.reshape(image.shape)\n",
|
371 | 366 | "\n",
|
|
414 | 409 | "\n",
|
415 | 410 | "# Computing *sRGB* to *Rec. 2020* colourspace transformation matrix.\n",
|
416 | 411 | "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", |
422 | 415 | "\n",
|
423 | 416 | "\n",
|
424 | 417 | "def Rec_2020_to_xy(RGB):\n",
|
425 | 418 | " 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", |
430 | 421 | "\n",
|
431 | 422 | "\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", |
435 | 426 | "Rec_2020_image = Rec_2020_image.reshape(ACES_image_shape)\n",
|
436 | 427 | "\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", |
441 | 431 | "\n",
|
442 | 432 | "# Scaling the data to make it more obvious.\n",
|
443 | 433 | "Rec_2020_image_illegal *= 100\n",
|
|
477 | 467 | }
|
478 | 468 | ],
|
479 | 469 | "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", |
481 | 473 | "\n",
|
482 | 474 | "# Scaling the data to make it more obvious.\n",
|
483 | 475 | "pointer_gamut_illegal_image *= 100\n",
|
|
519 | 511 | }
|
520 | 512 | ],
|
521 | 513 | "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", |
523 | 515 | "spectral_locus_xy = np.array([colour.XYZ_to_xy(x) for x in cmfs.values])\n",
|
524 | 516 | "\n",
|
525 | 517 | "spectral_locus_illegal_image = mask_legal_colours(sRGB_image, spectral_locus_xy)\n",
|
|
0 commit comments