Skip to content

[FEATURE]: Spectral Similarity Index should handle colour.MultiSpectralDistributions #1370

@lschmidt-mkwz

Description

@lschmidt-mkwz

Description

Hi all !

Should be an easy fix, just ensure the shapes are correctly broadcasted. Unless this is intended !

Code for Reproduction

import colour

data = {
    500: (0.004900, 0.323000, 0.272000),
    510: (0.009300, 0.503000, 0.158200),
    520: (0.063270, 0.710000, 0.078250),
    530: (0.165500, 0.862000, 0.042160),
    540: (0.290400, 0.954000, 0.020300),
    550: (0.433450, 0.994950, 0.008750),
    560: (0.594500, 0.995000, 0.003900),
}

labels = ("x_bar", "y_bar", "z_bar")

msd = colour.MultiSpectralDistributions(data, labels=labels)

colour.spectral_similarity_index(msd, msd)

Exception Message

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[13], line 17
     13 labels = ("x_bar", "y_bar", "z_bar")
     15 msd = colour.MultiSpectralDistributions(data, labels=labels)
---> 17 colour.spectral_similarity_index(msd, msd)

File ~/Y/X/.venv/lib/python3.14/site-packages/colour/quality/ssi.py:117, in spectral_similarity_index(sd_test, sd_reference, round_result)
    114     reference_i = sdiv(reference_i, np.sum(reference_i))
    115     dr_i = sdiv(test_i - reference_i, reference_i + 1 / 30)
--> 117 wdr_i = dr_i * [
    118     4 / 15,
    119     22 / 45,
    120     32 / 45,
    121     40 / 45,
    122     44 / 45,
    123     1,
    124     1,
    125     1,
    126     1,
    127     1,
    128     1,
    129     1,
    130     1,
    131     1,
    132     1,
    133     1,
    134     1,
    135     1,
    136     1,
    137     1,
    138     1,
    139     1,
    140     1,
    141     1,
    142     1,
    143     1,
    144     1,
    145     1,
    146     11 / 15,
    147     3 / 15,
    148 ]
    149 c_wdr_i = convolve1d(wdr_i, [0.22, 0.56, 0.22], mode="constant", cval=0)
    150 m_v = np.sum(c_wdr_i**2)

ValueError: operands could not be broadcast together with shapes (30,3) (30,)

Environment Information

===============================================================================
*                                                                             *
*   Interpreter :                                                             *
*       python : 3.14.0 (main, Oct 10 2025, 12:47:49) [Clang 20.1.4 ]         *
*                                                                             *
*   colour-science.org :                                                      *
*       colour : 0.4.6                                                        *
*                                                                             *
*   Runtime :                                                                 *
*       imageio : 2.37.0                                                      *
*       matplotlib : 3.10.7                                                   *
*       networkx : 3.5                                                        *
*       numpy : 2.3.3                                                         *
*       scipy : 1.16.2                                                        *
*                                                                             *
===============================================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions