colour.colorimetry.msds_to_XYZ_integration#

colour.colorimetry.msds_to_XYZ_integration(msds: ArrayLike | SpectralDistribution | MultiSpectralDistributions, cmfs: MultiSpectralDistributions | None = None, illuminant: SpectralDistribution | None = None, k: Real | None = None, shape: SpectralShape | None = None) NDArrayFloat[source]#

Convert given multi-spectral distributions to CIE XYZ tristimulus values using given colour matching functions and illuminant.

The multi-spectral distributions can be either a colour.MultiSpectralDistributions class instance or an ArrayLike in which case the shape must be passed.

Parameters:
  • msds (ArrayLike | SpectralDistribution | MultiSpectralDistributions) – Multi-spectral distributions, if an ArrayLike the wavelengths are expected to be in the last axis, e.g. for a 512x384 multi-spectral image with 77 bins, msds shape should be (384, 512, 77).

  • cmfs (MultiSpectralDistributions | None) – Standard observer colour matching functions, default to the CIE 1931 2 Degree Standard Observer.

  • illuminant (SpectralDistribution | None) – Illuminant spectral distribution, default to CIE Illuminant E.

  • k (Real | None) – Normalisation constant \(k\). For reflecting or transmitting object colours, \(k\) is chosen so that \(Y = 100\) for objects for which the spectral reflectance factor \(R(\lambda)\) of the object colour or the spectral transmittance factor \(\tau(\lambda)\) of the object is equal to unity for all wavelengths. For self-luminous objects and illuminants, the constants \(k\) is usually chosen on the grounds of convenience. If, however, in the CIE 1931 standard colorimetric system, the \(Y\) value is required to be numerically equal to the absolute value of a photometric quantity, the constant, \(k\), must be put equal to the numerical value of \(K_m\), the maximum spectral luminous efficacy (which is equal to 683 \(lm\cdot W^{-1}\)) and \(\Phi_\lambda(\lambda)\) must be the spectral concentration of the radiometric quantity corresponding to the photometric quantity required.

  • shape (SpectralShape | None) – Spectral shape that sd, cmfs and illuminant will be aligned to it if passed.

Returns:

CIE XYZ tristimulus values, for a 512x384 multi-spectral image with 77 bins, the output shape will be (384, 512, 3).

Return type:

numpy.ndarray

Notes

Range

Scale - Reference

Scale - 1

XYZ

[0, 100]

[0, 1]

  • When \(k\) is set to a value other than None, the computed CIE XYZ tristimulus values are assumed to be absolute and are thus converted from percentages by a final division by 100.

  • The code path using the ArrayLike multi-spectral distributions produces results different to the code path using a colour.MultiSpectralDistributions class instance: the former favours execution speed by aligning the colour matching functions and illuminant to the given spectral shape while the latter favours precision by aligning the multi-spectral distributions to the colour matching functions.

  • If precision is required, it is possible to interpolate the multi-spectral distributions with scipy.interpolate.interp1d class on the last / tail axis as follows:

    interpolator = scipy.interpolate.interp1d(
        wavelengths,
        values,
        axis=-1,
        kind="linear",
        fill_value="extrapolate",
    )
    values_i = interpolator(wavelengths_i)
    

References

[WS00c]

Examples

>>> from colour import MSDS_CMFS, SDS_ILLUMINANTS
>>> cmfs = MSDS_CMFS["CIE 1931 2 Degree Standard Observer"]
>>> illuminant = SDS_ILLUMINANTS["D65"]
>>> shape = SpectralShape(400, 700, 60)
>>> data = np.array(
...     [
...         [
...             0.0137,
...             0.0159,
...             0.0096,
...             0.0111,
...             0.0179,
...             0.1057,
...             0.0433,
...             0.0258,
...             0.0248,
...             0.0186,
...             0.0310,
...             0.0473,
...         ],
...         [
...             0.0913,
...             0.3145,
...             0.2582,
...             0.0709,
...             0.2971,
...             0.4620,
...             0.2683,
...             0.0831,
...             0.1203,
...             0.1292,
...             0.1682,
...             0.3221,
...         ],
...         [
...             0.0152,
...             0.0842,
...             0.4139,
...             0.0220,
...             0.5630,
...             0.1918,
...             0.2373,
...             0.0430,
...             0.0054,
...             0.0079,
...             0.3719,
...             0.2268,
...         ],
...         [
...             0.0281,
...             0.0907,
...             0.2228,
...             0.1249,
...             0.2375,
...             0.5625,
...             0.0518,
...             0.3230,
...             0.0065,
...             0.4006,
...             0.0861,
...             0.3161,
...         ],
...         [
...             0.1918,
...             0.7103,
...             0.0041,
...             0.1817,
...             0.0024,
...             0.4209,
...             0.0118,
...             0.2302,
...             0.1860,
...             0.9404,
...             0.0041,
...             0.1124,
...         ],
...         [
...             0.0430,
...             0.0437,
...             0.3744,
...             0.0020,
...             0.5819,
...             0.0027,
...             0.0823,
...             0.0081,
...             0.3625,
...             0.3213,
...             0.7849,
...             0.0024,
...         ],
...     ]
... )
>>> msds = MultiSpectralDistributions(data, shape)
>>> msds_to_XYZ_integration(msds, cmfs, illuminant)
... 
array([[  7.5029704...,   3.9487844...,   8.4034669...],
       [ 26.9259681...,  15.0724609...,  28.7057807...],
       [ 16.7032188...,  28.2172346...,  25.6455984...],
       [ 11.5767013...,   8.6400993...,   6.5768406...],
       [ 18.7314793...,  35.0750364...,  30.1457266...],
       [ 45.1656756...,  39.6136917...,  43.6783499...],
       [  8.1755696...,  13.0934177...,  25.9420944...],
       [ 22.4676286...,  19.3099080...,   7.9637549...],
       [  6.5781241...,   2.5255349...,  11.0930768...],
       [ 43.9147364...,  27.9803924...,  11.7292655...],
       [  8.5365923...,  19.7030166...,  17.7050933...],
       [ 23.9088250...,  26.2129529...,  30.6763148...]])
>>> data = np.reshape(data, (2, 6, 6))
>>> msds_to_XYZ_integration(data, cmfs, illuminant, shape=shape)
... 
array([[[  1.3104332...,   1.1377026...,   1.8267926...],
        [  2.1875548...,   2.2510619...,   3.0721540...],
        [ 16.8714661...,  17.7063715...,  35.8709902...],
        [ 12.1648722...,  12.7222194...,  10.4880888...],
        [ 16.0419431...,  23.0985768...,  11.1479902...],
        [  9.2391014...,   3.8301575...,   5.4703803...]],

       [[ 13.8734231...,  17.3942194...,  11.0364103...],
        [ 27.7096381...,  20.8626722...,  35.5581690...],
        [ 22.7886687...,  11.4769218...,  78.3300659...],
        [ 51.1284864...,  52.2463568...,  26.1483754...],
        [ 14.4749229...,  20.5011495...,   6.6228107...],
        [ 33.6001365...,  36.3242617...,   2.8254217...]]])

The default CMFS are the CIE 1931 2 Degree Standard Observer, and the default illuminant is CIE Illuminant E:

>>> msds_to_XYZ_integration(msds)
... 
array([[  8.2415862...,   4.2543993...,   7.6100842...],
       [ 29.6144619...,  16.1158465...,  25.9015472...],
       [ 16.6799560...,  27.2350547...,  22.9413337...],
       [ 12.5597688...,   9.0667136...,   5.9670327...],
       [ 18.5804689...,  33.6618109...,  26.9249733...],
       [ 47.7113308...,  40.4573249...,  39.6439145...],
       [  7.830207 ...,  12.3689624...,  23.3742655...],
       [ 24.1695370...,  20.0629815...,   7.2718670...],
       [  7.2333751...,   2.7982097...,  10.0688374...],
       [ 48.7358074...,  30.2417164...,  10.6753233...],
       [  8.3231013...,  18.6791507...,  15.8228184...],
       [ 24.6452277...,  26.0809382...,  27.7106399...]])