1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import numpy as np
from colour import *
from colour.difference import delta_E_CIE1976
from colour.models import RGB_COLOURSPACES
from colour.recovery import RGB_to_sd_Jakob2019, Jakob2019Interpolator
from gsoc_common import *
colourspace = RGB_COLOURSPACES["ACES2065-1"]
def stats(table, prefix):
table = np.array(table)
print("%s min/max/avg/std: %g/%g/%g/%g" % (prefix, np.min(table),
np.max(table), np.mean(table), np.std(table)))
if __name__ == "__main__":
interp = Jakob2019Interpolator()
interp.from_file("data/aces2065_1.coeff")
errors = []
errors_interp = []
rel_deltas = []
for i in range(100):
RGB = np.random.random(3)
for use_feedback in [False, True]:
recovered_sd, error = RGB_to_sd_Jakob2019(
RGB,
colourspace,
return_error=True,
use_feedback=use_feedback
)
if error < 1e-3:
break
XYZ = RGB_to_XYZ(
RGB,
colourspace.whitepoint,
D65_xy,
colourspace.RGB_to_XYZ_matrix,
)
Lab = XYZ_to_Lab(XYZ, D65_xy)
sd_interp = interp.RGB_to_sd(RGB)
XYZ_interp = sd_to_XYZ(sd_interp, illuminant=D65) / 100
Lab_interp = XYZ_to_Lab(XYZ_interp, D65_xy)
error_interp = delta_E_CIE1976(Lab, Lab_interp)
XYZ_recovered = sd_to_XYZ(recovered_sd, illuminant=D65) / 100
Lab_recovered = XYZ_to_Lab(XYZ_recovered, D65_xy)
rel_delta = error / error_interp
print("%.5f %.5f %.5f E%10.6f I%7.3f RΔ%.6f"
% (*RGB, error, error_interp, rel_delta))
errors.append(error)
errors_interp.append(error_interp)
rel_deltas.append(rel_delta)
print(colourspace.name)
stats(errors, "Colour")
stats(errors_interp, "Interpolator")
stats(rel_deltas, "Rel. delta")
|