How does one take a color expressed in an RGB value (say, three coordinates from 0-255) and produce from it a color temperature in kelvin (or mireds)?
I see this question which looks pretty close. However, the question mentions x and y, an answer mentions R1 and S1, which I think are CIE XYZ color space coordinates. I'm not quite sure how to get to those either. Someone else links to a paper. Someone else says RGB values are meaningless without "stating a color space" (I thought my monitor decided to display something simply from RGB values?).
Can someone just lay out the whole thing without pointing to other places and assuming I know what all the color terminology is?
You could use Colour to perform that computation using the colour.xy_to_CCT_Hernandez1999
definition:
import numpy as np
import colour
# Assuming sRGB encoded colour values.
RGB = np.array([255.0, 235.0, 12.0])
# Conversion to tristimulus values.
XYZ = colour.sRGB_to_XYZ(RGB / 255)
# Conversion to chromaticity coordinates.
xy = colour.XYZ_to_xy(XYZ)
# Conversion to correlated colour temperature in K.
CCT = colour.xy_to_CCT(xy, 'hernandez1999')
print(CCT)
# 3557.10272422
Here is a formula in Java,
double n = ((0.23881) * Color.red(previewColor) + (0.25499) * Color.green(previewColor) + (-0.58291) * Color.blue(previewColor)) / ((0.11109) * Color.red(previewColor) + (-0.85406) * Color.green(previewColor) + (0.52289) * Color.blue(previewColor));
double cct = 449 * Math.pow(n,3) + 3525 * Math.pow(n,2) + 6823.3 * n + 5520.33;
here the value for previewColor is the integer representation of the color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With