summaryrefslogtreecommitdiff
path: root/test_example.py
blob: d0be8dd7be4a8624166be7abc26f0a5497df8fea (plain)
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
import numpy as np
from colour import *
from colour.difference import delta_E_CIE1976
from jakob_hanika import jakob_hanika, model_sd
from test_colorchecker import plot_comparison



illuminant = "D65"
ill_xy = ILLUMINANTS["CIE 1931 2 Degree Standard Observer"][illuminant]
ill_sd = SpectralDistribution(ILLUMINANTS_SDS[illuminant])

# These numbers are taken from Jakob and Hanika's Jupyter notebook.
RGB_ref = np.array([0.79264853,  0.4, 0.63703843]) # *linear* sRGB
cc_ref = np.array([ 18.70184886, -13.19804478, 2.12180137])



if __name__ == "__main__":
	XYZ = sRGB_to_XYZ(1.055 * RGB_ref ** (1/2.4) - 0.055, ill_xy)
	Lab = XYZ_to_Lab(XYZ, ill_xy)

	print("Target: X=%g, Y=%g, Z=%g, L=%g, a=%g, b=%g" % (*XYZ, *Lab))
	ccp, error = jakob_hanika(XYZ, ill_sd, ill_xy)

	reference_sd = model_sd(cc_ref)
	reference_XYZ = sd_to_XYZ(reference_sd, illuminant=ill_sd)
	reference_Lab = XYZ_to_Lab(reference_XYZ, ill_xy)

	found_sd = model_sd(ccp)
	found_XYZ = sd_to_XYZ(found_sd, illuminant=ill_sd)
	found_Lab = XYZ_to_Lab(found_XYZ, ill_xy)

	print("Our results differ from the reference by ΔE = %g" \
	      % delta_E_CIE1976(reference_Lab, found_Lab))

	plot_comparison(XYZ, found_sd, "Reference", error, ill_sd)