Skip to content

Commit 35424bc

Browse files
authored
Add argument for calculating continuous spectral_similarity_index values. (#1117)
1 parent 82e0390 commit 35424bc

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

colour/quality/ssi.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from colour.algebra import LinearInterpolator, sdiv, sdiv_mode
2222
from colour.colorimetry import SpectralDistribution, SpectralShape, reshape_sd
2323
from colour.hints import NDArrayFloat
24-
from colour.utilities import as_float_scalar, zeros
24+
from colour.utilities import zeros
2525

2626
__author__ = "Colour Developers"
2727
__copyright__ = "Copyright 2013 Colour Developers"
@@ -44,8 +44,10 @@
4444

4545

4646
def spectral_similarity_index(
47-
sd_test: SpectralDistribution, sd_reference: SpectralDistribution
48-
) -> float:
47+
sd_test: SpectralDistribution,
48+
sd_reference: SpectralDistribution,
49+
round_results: bool = True,
50+
) -> NDArrayFloat:
4951
"""
5052
Return the *Academy Spectral Similarity Index* (SSI) of given test
5153
spectral distribution with given reference spectral distribution.
@@ -56,6 +58,9 @@ def spectral_similarity_index(
5658
Test spectral distribution.
5759
sd_reference
5860
Reference spectral distribution.
61+
round_results
62+
Controls rounding the results. Particularly useful when using SSI in an
63+
optimization routine. Default True.
5964
6065
Returns
6166
-------
@@ -143,6 +148,8 @@ def spectral_similarity_index(
143148
c_wdr_i = convolve1d(np.hstack([0, wdr_i, 0]), [0.22, 0.56, 0.22])
144149
m_v = np.sum(c_wdr_i**2)
145150

146-
SSI = np.around(100 - 32 * np.sqrt(m_v))
151+
SSI = 100 - 32 * np.sqrt(m_v)
147152

148-
return as_float_scalar(SSI)
153+
if round_results:
154+
return np.around(SSI)
155+
return SSI

colour/quality/tests/test_ssi.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,32 @@ def test_spectral_similarity_index(self):
576576
72.0,
577577
)
578578

579+
def test_spectral_similarity_rounding(self):
580+
"""
581+
Test :func:`colour.quality.ssi.spectral_similarity_index` for
582+
producing continuous values.
583+
"""
584+
585+
# Test values were computed at ed2e90
586+
self.assertAlmostEqual(
587+
spectral_similarity_index(
588+
SDS_ILLUMINANTS["C"],
589+
SDS_ILLUMINANTS["D65"],
590+
round_results=False,
591+
),
592+
94.178,
593+
places=2,
594+
)
595+
self.assertAlmostEqual(
596+
spectral_similarity_index(
597+
SpectralDistribution(DATA_HMI),
598+
SDS_ILLUMINANTS["D50"],
599+
round_results=False,
600+
),
601+
71.772,
602+
places=2,
603+
)
604+
579605

580606
if __name__ == "__main__":
581607
unittest.main()

0 commit comments

Comments
 (0)