diff options
Diffstat (limited to 'test_compare_with_tables.py')
-rw-r--r-- | test_compare_with_tables.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test_compare_with_tables.py b/test_compare_with_tables.py new file mode 100644 index 0000000..a13be00 --- /dev/null +++ b/test_compare_with_tables.py @@ -0,0 +1,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") + + |