Search code examples
pythoncolorsdatasetlight

Find color temperature from spectral response


I search for some Python library that can find color temperature from spectral response from spectrometer. I have single spectrum output like this:

enter image description here

I want to find color temperate of my light source.

The outputs shuld be like here (values not plot):

enter image description here

I searched a lot but I didn't find anything, in libraries like colour-science or python-colormath I don't see option like that. Is it possible at all?


Solution

  • It is certainly possible with Colour:

    >>> import colour
    >>> D65 = colour.ILLUMINANTS_SDS['D65']
    >>> XYZ = colour.sd_to_XYZ(D65)
    >>> xy = colour.XYZ_to_xy(XYZ)
    >>> colour.xy_to_CCT(xy)
    6507.5108766555786
    

    Or with the Automatic Colour Conversion Graph:

    >>> import colour
    >>> colour.convert(D65, 'Spectral Distribution', 'CCT', sd_to_XYZ={'illuminant': colour.sd_ones()})
    6507.5108766555786
    

    You have to specify an illuminant here to override the default which happens to be D65 :)