diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2020-06-09 12:16:05 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2020-06-09 12:16:05 +0200 |
commit | cb3024229b71349753bcf9f1f30187bc8087fd6c (patch) | |
tree | 1981099912623ac36e417e0b9dabafda09a609bc | |
parent | 95fdb61488202942bd8496c34c2615643ccc84fd (diff) |
A new test comparing results with a reference
-rw-r--r-- | test_example.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test_example.py b/test_example.py new file mode 100644 index 0000000..412cece --- /dev/null +++ b/test_example.py @@ -0,0 +1,38 @@ +import numpy as np +from colour import * +from colour.plotting import * +from colour.difference import * +from matplotlib import pyplot as plt +from jakob_hanika import jakob_hanika, model, remap, wvl +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) + target = XYZ_to_Lab(XYZ, ill_xy) + + print("Target: X=%g, Y=%g, Z=%g, L=%g, a=%g, b=%g" % (*XYZ, *target)) + cc, found_sd, error = jakob_hanika(target, ill_sd, ill_xy) + + reference_sd = SpectralDistribution(model(remap(wvl), cc_ref), wvl) + reference_XYZ = sd_to_XYZ(reference_sd, illuminant=ill_sd) + reference_Lab = XYZ_to_Lab(reference_XYZ, ill_xy) + + 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) |