Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 78ea0b2

Browse files
committed
Implement support for "Colour" 0.3.16.
1 parent e8d7039 commit 78ea0b2

File tree

8 files changed

+129
-99
lines changed

8 files changed

+129
-99
lines changed

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
FROM python:3.6
1+
FROM python:3.8
22

33
WORKDIR /tmp
44
COPY ./requirements.txt /tmp
55
RUN pip install -r requirements.txt \
6-
&& rm /tmp/requirements.txt
6+
&& rm /tmp/requirements.txt \
7+
&& python -c "import imageio;imageio.plugins.freeimage.download()"
78

89
ARG CACHE_DATE
910

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
import json
1010
import os
11+
from cachelib import SimpleCache
1112
from flask import Flask, Response, render_template, request
1213
from flask_caching import Cache
1314
from flask_compress import Compress
14-
from werkzeug.contrib.cache import SimpleCache
1515

1616
from colour.utilities import domain_range_scale
1717

colour_analysis.py

Lines changed: 77 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,18 @@
77
loaded by "Three.js".
88
"""
99

10-
from __future__ import division
11-
1210
import json
1311
import numpy as np
1412
import os
1513
import re
16-
from werkzeug.contrib.cache import SimpleCache
14+
from cachelib import SimpleCache
1715

18-
from colour import (ILLUMINANTS, CCTF_DECODINGS, Lab_to_XYZ, LCHab_to_Lab,
19-
POINTER_GAMUT_DATA, POINTER_GAMUT_ILLUMINANT,
16+
from colour import (CCS_ILLUMINANTS, CCTF_DECODINGS, Lab_to_XYZ, LCHab_to_Lab,
2017
RGB_COLOURSPACES, RGB_to_RGB, RGB_to_XYZ, XYZ_to_RGB,
2118
XYZ_to_JzAzBz, XYZ_to_OSA_UCS, convert,
2219
is_within_pointer_gamut, read_image)
23-
from colour.models import linear_function
20+
from colour.models import (CCS_ILLUMINANT_POINTER_GAMUT,
21+
DATA_POINTER_GAMUT_VOLUME, linear_function)
2422
from colour.plotting import filter_cmfs, filter_RGB_colourspaces
2523
from colour.utilities import (CaseInsensitiveMapping, as_float_array,
2624
first_item, normalise_maximum, tsplit, tstack)
@@ -88,16 +86,16 @@
8886
COLOURSPACE_MODELS = ('CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD',
8987
'CAM16SCD', 'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab',
9088
'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99', 'Hunter Lab',
91-
'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
92-
'hdr-CIELAB', 'hdr-IPT')
89+
'Hunter Rdab', 'ICTCP', 'IGPGTG', 'IPT', 'JzAzBz',
90+
'OSA UCS', 'hdr-CIELAB', 'hdr-IPT')
9391
"""
9492
Reference colourspace models defining available colour transformations from
9593
CIE XYZ tristimulus values.
9694
9795
COLOURSPACE_MODELS : tuple
9896
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD', 'CAM16UCS',
9997
'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99',
100-
'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
98+
'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG', 'IPT', 'JzAzBz', 'OSA UCS',
10199
'hdr-CIELAB', 'hdr-IPT'}**
102100
"""
103101

@@ -118,6 +116,7 @@
118116
'Hunter Lab': ('a', 'L', 'b'),
119117
'Hunter Rdab': ('a', 'Rd', 'b'),
120118
'ICTCP': ('CT', 'I', 'CP'),
119+
'IGPGTG': ('PG', 'IG', 'TG'),
121120
'IPT': ('P', 'I', 'T'),
122121
'JzAzBz': ('Az', 'Jz', 'Bz'),
123122
'OSA UCS': ('j', 'J', 'g'),
@@ -131,7 +130,7 @@
131130
COLOURSPACE_MODELS : dict
132131
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD', 'CAM16UCS',
133132
'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99',
134-
'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
133+
'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG', 'IPT', 'JzAzBz', 'OSA UCS',
135134
'hdr-CIELAB', 'hdr-IPT'}**
136135
"""
137136

@@ -174,16 +173,16 @@
174173
COLOURSPACE_MODEL : unicode
175174
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD', 'CAM16UCS',
176175
'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW', 'DIN 99',
177-
'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT', 'JzAzBz', 'OSA UCS',
176+
'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG', 'IPT', 'JzAzBz', 'OSA UCS',
178177
'hdr-CIELAB', 'hdr-IPT'}**
179178
"""
180179

181-
POINTER_GAMUT_DATA = Lab_to_XYZ(
182-
LCHab_to_Lab(POINTER_GAMUT_DATA), POINTER_GAMUT_ILLUMINANT)
180+
DATA_POINTER_GAMUT = Lab_to_XYZ(
181+
LCHab_to_Lab(DATA_POINTER_GAMUT_VOLUME), CCS_ILLUMINANT_POINTER_GAMUT)
183182
"""
184183
Pointer's Gamut data converted to *CIE XYZ* tristimulus values.
185184
186-
POINTER_GAMUT_DATA : ndarray
185+
DATA_POINTER_GAMUT : ndarray
187186
"""
188187

189188
IMAGE_CACHE = SimpleCache(default_timeout=60 * 24 * 7)
@@ -246,8 +245,8 @@ def XYZ_to_colourspace_model(XYZ, illuminant, model, **kwargs):
246245
model : unicode
247246
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
248247
'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS',
249-
'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT',
250-
'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
248+
'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG',
249+
'IPT', 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
251250
Colourspace model to convert the *CIE XYZ* tristimulus values to.
252251
253252
Other Parameters
@@ -289,8 +288,8 @@ def colourspace_model_axis_reorder(a, model=None):
289288
model : unicode, optional
290289
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
291290
'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS',
292-
'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT',
293-
'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
291+
'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG',
292+
'IPT', 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
294293
Colourspace model.
295294
296295
Returns
@@ -306,8 +305,8 @@ def colourspace_model_axis_reorder(a, model=None):
306305
a = tstack([j, k, i])
307306
elif model in ('CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
308307
'CAM16UCS', 'CIE Lab', 'CIE LCHab', 'CIE Luv', 'CIE LCHuv',
309-
'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT',
310-
'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'):
308+
'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG',
309+
'IPT', 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'):
311310
a = tstack([k, i, j])
312311

313312
return a
@@ -324,8 +323,8 @@ def colourspace_model_faces_reorder(a, model=None):
324323
model : unicode, optional
325324
**{'CAM02LCD', 'CAM02SCD', 'CAM02UCS', 'CAM16LCD', 'CAM16SCD',
326325
'CAM16UCS', 'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS',
327-
'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IPT',
328-
'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
326+
'CIE UVW', 'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'ICTCP', 'IGPGTG',
327+
'IPT', 'JzAzBz', 'OSA UCS', 'hdr-CIELAB', 'hdr-IPT'}**,
329328
Colourspace model.
330329
331330
Returns
@@ -644,7 +643,8 @@ def create_box(width=1,
644643
colors = np.hstack([
645644
np.reshape(
646645
np.interp(colors, (np.min(colors), np.max(colors)), (0, 1)),
647-
positions.shape),
646+
positions.shape,
647+
),
648648
np.ones((positions.shape[0], 1))
649649
])
650650

@@ -733,8 +733,12 @@ def image_data(path,
733733

734734
if out_of_pointer_gamut:
735735
O_PG = is_within_pointer_gamut(
736-
RGB_to_XYZ(RGB, colourspace.whitepoint, colourspace.whitepoint,
737-
colourspace.RGB_to_XYZ_matrix)).astype(np.int_)
736+
RGB_to_XYZ(
737+
RGB,
738+
colourspace.whitepoint,
739+
colourspace.whitepoint,
740+
colourspace.matrix_RGB_to_XYZ,
741+
)).astype(np.int_)
738742
O_PG = 1 - O_PG
739743
RGB[O_PG != 1] = 0
740744
RGB[O_PG == 1] = 1
@@ -788,11 +792,18 @@ def RGB_colourspace_volume_visual(colourspace=PRIMARY_COLOURSPACE,
788792
np.reshape(cube[1], (-1, 1)), colourspace_model)
789793
RGB = cube[0]['colour']
790794

791-
XYZ = RGB_to_XYZ(vertices, colourspace.whitepoint, colourspace.whitepoint,
792-
colourspace.RGB_to_XYZ_matrix)
795+
XYZ = RGB_to_XYZ(
796+
vertices,
797+
colourspace.whitepoint,
798+
colourspace.whitepoint,
799+
colourspace.matrix_RGB_to_XYZ,
800+
)
793801
vertices = colourspace_model_axis_reorder(
794-
XYZ_to_colourspace_model(XYZ, colourspace.whitepoint,
795-
colourspace_model), colourspace_model)
802+
XYZ_to_colourspace_model(
803+
XYZ,
804+
colourspace.whitepoint,
805+
colourspace_model,
806+
), colourspace_model)
796807

797808
return buffer_geometry(position=vertices, color=RGB, index=faces)
798809

@@ -884,17 +895,28 @@ def RGB_image_scatter_visual(path,
884895

885896
if out_of_pointer_gamut:
886897
O_PG = is_within_pointer_gamut(
887-
RGB_to_XYZ(RGB, colourspace.whitepoint, colourspace.whitepoint,
888-
colourspace.RGB_to_XYZ_matrix)).astype(np.int_)
898+
RGB_to_XYZ(
899+
RGB,
900+
colourspace.whitepoint,
901+
colourspace.whitepoint,
902+
colourspace.matrix_RGB_to_XYZ,
903+
)).astype(np.int_)
889904
O_PG = 1 - O_PG
890905
RGB = RGB[O_PG == 1]
891906

892-
XYZ = RGB_to_XYZ(RGB, colourspace.whitepoint, colourspace.whitepoint,
893-
colourspace.RGB_to_XYZ_matrix)
907+
XYZ = RGB_to_XYZ(
908+
RGB,
909+
colourspace.whitepoint,
910+
colourspace.whitepoint,
911+
colourspace.matrix_RGB_to_XYZ,
912+
)
894913

895914
vertices = colourspace_model_axis_reorder(
896-
XYZ_to_colourspace_model(XYZ, colourspace.whitepoint,
897-
colourspace_model), colourspace_model)
915+
XYZ_to_colourspace_model(
916+
XYZ,
917+
colourspace.whitepoint,
918+
colourspace_model,
919+
), colourspace_model)
898920

899921
if (out_of_primary_colourspace_gamut or
900922
out_of_secondary_colourspace_gamut or out_of_pointer_gamut):
@@ -934,12 +956,19 @@ def spectral_locus_visual(colourspace=PRIMARY_COLOURSPACE,
934956
XYZ = np.vstack([XYZ, XYZ[0, ...]])
935957

936958
vertices = colourspace_model_axis_reorder(
937-
XYZ_to_colourspace_model(XYZ, colourspace.whitepoint,
938-
colourspace_model), colourspace_model)
959+
XYZ_to_colourspace_model(
960+
XYZ,
961+
colourspace.whitepoint,
962+
colourspace_model,
963+
), colourspace_model)
939964

940965
RGB = normalise_maximum(
941-
XYZ_to_RGB(XYZ, colourspace.whitepoint, colourspace.whitepoint,
942-
colourspace.XYZ_to_RGB_matrix),
966+
XYZ_to_RGB(
967+
XYZ,
968+
colourspace.whitepoint,
969+
colourspace.whitepoint,
970+
colourspace.matrix_XYZ_to_RGB,
971+
),
943972
axis=-1)
944973

945974
return buffer_geometry(position=vertices, color=RGB)
@@ -960,15 +989,16 @@ def pointer_gamut_visual(colourspace_model='CIE xyY'):
960989
*Pointer's Gamut* visual geometry formatted as *JSON*.
961990
"""
962991

963-
pointer_gamut_data = np.reshape(POINTER_GAMUT_DATA, (16, -1, 3))
992+
data_pointer_gamut = np.reshape(DATA_POINTER_GAMUT, (16, -1, 3))
964993
vertices = []
965994
for i in range(16):
966995
section = colourspace_model_axis_reorder(
967996
XYZ_to_colourspace_model(
968997
np.vstack(
969-
[pointer_gamut_data[i], pointer_gamut_data[i][0, ...]]),
970-
POINTER_GAMUT_ILLUMINANT, colourspace_model),
971-
colourspace_model)
998+
[data_pointer_gamut[i], data_pointer_gamut[i][0, ...]]),
999+
CCS_ILLUMINANT_POINTER_GAMUT,
1000+
colourspace_model,
1001+
), colourspace_model)
9721002

9731003
vertices.append(list(zip(section, section[1:])))
9741004

@@ -995,8 +1025,10 @@ def visible_spectrum_visual(colourspace_model='CIE xyY'):
9951025
XYZ = XYZ_outer_surface()
9961026
vertices = colourspace_model_axis_reorder(
9971027
XYZ_to_colourspace_model(
998-
XYZ, ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['E'],
999-
colourspace_model), colourspace_model)
1028+
XYZ,
1029+
CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['E'],
1030+
colourspace_model,
1031+
), colourspace_model)
10001032

10011033
vertices = as_float_array(list(zip(vertices, vertices[1:])))
10021034

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "colour-analysis",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"description": "Colour - Analysis",
55
"private": true,
66
"scripts": {

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "colour-analysis"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "Image analysis tools based on Colour and Three.js"
55
license = "BSD-3-Clause"
66
authors = [ "Colour Developers <colour-developers@colour-science.org>" ]
@@ -43,8 +43,9 @@ classifiers = [
4343
]
4444

4545
[tool.poetry.dependencies]
46-
python = "^3.5"
47-
colour-science = "^0.3.14"
46+
python = "^3.6"
47+
colour-science = "^0.3.16"
48+
cachelib = "*"
4849
flask = "*"
4950
flask-caching = "*"
5051
flask-compress = { git = "https://github.com/colour-science/flask-compress" }

0 commit comments

Comments
 (0)