diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2020-06-23 20:08:29 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2020-06-23 20:08:29 +0200 |
commit | c0b52c1c841957b27e2dd82a11ecb3b4ff8db265 (patch) | |
tree | da07444182cf7caf88e65fb940f9315349ac03f4 /gsoc_common.py | |
parent | 33278ad88f8290054aa2b421182019b9167f50ff (diff) |
Update the tests again and remove some useless ones.
Diffstat (limited to 'gsoc_common.py')
-rw-r--r-- | gsoc_common.py | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/gsoc_common.py b/gsoc_common.py index b73d81c..695edc6 100644 --- a/gsoc_common.py +++ b/gsoc_common.py @@ -3,47 +3,53 @@ from colour import * from colour.difference import delta_E_CIE1976 from colour.colorimetry import * from colour.plotting import * +from colour.models import RGB_COLOURSPACES from matplotlib import pyplot as plt + D65_xy = ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"] D65 = SpectralDistribution(ILLUMINANT_SDS["D65"]) +colourspace = RGB_COLOURSPACES["ProPhoto RGB"] # The same wavelength grid is used throughout wvl = SpectralShape(360, 830, 5) wvlp = (wvl.range() - 360) / (830 - 360) + # This is the model of spectral reflectivity described in the article. def model(wvlp, ccp): - yy = ccp[0] * wvlp**2 + ccp[1] * wvlp + ccp[2] - return 1 / 2 + yy / (2 * np.sqrt(1 + yy ** 2)) + yy = ccp[0] * wvlp**2 + ccp[1] * wvlp + ccp[2] + return 1 / 2 + yy / (2 * np.sqrt(1 + yy ** 2)) + # Create a SpectralDistribution using given coefficients def model_sd(ccp, primed=True): - # FIXME: don't hardcode the wavelength grid; there should be a way - # of creating a SpectralDistribution from the function alone - grid = wvlp if primed else wvl.range() - return SpectralDistribution(model(grid, ccp), wvl.range(), name="Model") + # FIXME: don't hardcode the wavelength grid; there should be a way + # of creating a SpectralDistribution from the function alone + grid = wvlp if primed else wvl.range() + return SpectralDistribution(model(grid, ccp), wvl.range(), name="Model") + # Makes a comparison plot with SDs and swatches def plot_comparison(target, matched_sd, label, error, ill_sd, show=True): - if type(target) is SpectralDistribution: - target_XYZ = sd_to_XYZ(target, illuminant=ill_sd) / 100 - else: - target_XYZ = target - target_RGB = np.clip(XYZ_to_sRGB(target_XYZ), 0, 1) - target_swatch = ColourSwatch(label, target_RGB) - matched_XYZ = sd_to_XYZ(matched_sd, illuminant=ill_sd) / 100 - matched_RGB = np.clip(XYZ_to_sRGB(matched_XYZ), 0, 1) - matched_swatch = ColourSwatch("Model", matched_RGB) - - axes = plt.subplot(2, 1, 1) - plt.title(label) - if type(target) is SpectralDistribution: - plot_multi_sds([target, matched_sd], axes=axes, standalone=False) - else: - plot_single_sd(matched_sd, axes=axes, standalone=False) - - axes = plt.subplot(2, 1, 2) - plt.title("ΔE = %g" % error) - plot_multi_colour_swatches([target_swatch, matched_swatch], - standalone=show, axes=axes) + if type(target) is SpectralDistribution: + target_XYZ = sd_to_XYZ(target, illuminant=ill_sd) / 100 + else: + target_XYZ = target + target_RGB = np.clip(XYZ_to_sRGB(target_XYZ), 0, 1) + target_swatch = ColourSwatch(label, target_RGB) + matched_XYZ = sd_to_XYZ(matched_sd, illuminant=ill_sd) / 100 + matched_RGB = np.clip(XYZ_to_sRGB(matched_XYZ), 0, 1) + matched_swatch = ColourSwatch("Model", matched_RGB) + + axes = plt.subplot(2, 1, 1) + plt.title(label) + if type(target) is SpectralDistribution: + plot_multi_sds([target, matched_sd], axes=axes, standalone=False) + else: + plot_single_sd(matched_sd, axes=axes, standalone=False) + + axes = plt.subplot(2, 1, 2) + plt.title("ΔE = %g" % error) + plot_multi_colour_swatches([target_swatch, matched_swatch], + standalone=show, axes=axes) |