alekq
alekq

Reputation: 137

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?

Upvotes: 2

Views: 1987

Answers (2)

Kel Solaar
Kel Solaar

Reputation: 4080

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 :)

Upvotes: 2

aerobiomat
aerobiomat

Reputation: 3437

The process normally takes the following steps:

  • Convert the spectrum to a CIE XYZ value
  • Convert the XYZ value to RGB using a specific CIE color system
  • Apply gamma correction

There is an explanation and code here.

Update

You may prefer to use this project: https://github.com/aerobio/spectra/

Upvotes: 2

Related Questions