diff --git a/colour/quality/ssi.py b/colour/quality/ssi.py index 2a2d041d0e..fb1fb6f5be 100644 --- a/colour/quality/ssi.py +++ b/colour/quality/ssi.py @@ -21,7 +21,7 @@ from colour.algebra import LinearInterpolator, sdiv, sdiv_mode from colour.colorimetry import SpectralDistribution, SpectralShape, reshape_sd from colour.hints import NDArrayFloat -from colour.utilities import as_float_scalar, zeros +from colour.utilities import zeros __author__ = "Colour Developers" __copyright__ = "Copyright 2013 Colour Developers" @@ -44,8 +44,10 @@ def spectral_similarity_index( - sd_test: SpectralDistribution, sd_reference: SpectralDistribution -) -> float: + sd_test: SpectralDistribution, + sd_reference: SpectralDistribution, + round_results: bool = True, +) -> NDArrayFloat: """ Return the *Academy Spectral Similarity Index* (SSI) of given test spectral distribution with given reference spectral distribution. @@ -56,6 +58,9 @@ def spectral_similarity_index( Test spectral distribution. sd_reference Reference spectral distribution. + round_results + Controls rounding the results. Particularly useful when using SSI in an + optimization routine. Default True. Returns ------- @@ -143,6 +148,8 @@ def spectral_similarity_index( c_wdr_i = convolve1d(np.hstack([0, wdr_i, 0]), [0.22, 0.56, 0.22]) m_v = np.sum(c_wdr_i**2) - SSI = np.around(100 - 32 * np.sqrt(m_v)) + SSI = 100 - 32 * np.sqrt(m_v) - return as_float_scalar(SSI) + if round_results: + return np.around(SSI) + return SSI diff --git a/colour/quality/tests/test_ssi.py b/colour/quality/tests/test_ssi.py index 35b01266d0..36c366e6bc 100644 --- a/colour/quality/tests/test_ssi.py +++ b/colour/quality/tests/test_ssi.py @@ -576,6 +576,32 @@ def test_spectral_similarity_index(self): 72.0, ) + def test_spectral_similarity_rounding(self): + """ + Test :func:`colour.quality.ssi.spectral_similarity_index` for + producing continuous values. + """ + + # Test values were computed at ed2e90 + self.assertAlmostEqual( + spectral_similarity_index( + SDS_ILLUMINANTS["C"], + SDS_ILLUMINANTS["D65"], + round_results=False, + ), + 94.178, + places=2, + ) + self.assertAlmostEqual( + spectral_similarity_index( + SpectralDistribution(DATA_HMI), + SDS_ILLUMINANTS["D50"], + round_results=False, + ), + 71.772, + places=2, + ) + if __name__ == "__main__": unittest.main()