Skip to content

Instantly share code, notes, and snippets.

@KelSolaar
Last active October 23, 2021 14:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KelSolaar/fb1e09b56b54d37d90e1886aef5ea4d4 to your computer and use it in GitHub Desktop.
Save KelSolaar/fb1e09b56b54d37d90e1886aef5ea4d4 to your computer and use it in GitHub Desktop.
Cornell Box to sRGB
import numpy as np
import colour
D = np.array([
[400, 0.343, 0.092, 0.040],
[404, 0.445, 0.096, 0.046],
[408, 0.551, 0.098, 0.048],
[412, 0.624, 0.097, 0.053],
[416, 0.665, 0.098, 0.049],
[420, 0.687, 0.095, 0.050],
[424, 0.708, 0.095, 0.053],
[428, 0.723, 0.097, 0.055],
[432, 0.715, 0.095, 0.057],
[436, 0.710, 0.094, 0.056],
[440, 0.745, 0.097, 0.059],
[444, 0.758, 0.098, 0.057],
[448, 0.739, 0.096, 0.061],
[452, 0.767, 0.101, 0.061],
[456, 0.777, 0.103, 0.060],
[460, 0.765, 0.104, 0.062],
[464, 0.751, 0.107, 0.062],
[468, 0.745, 0.109, 0.062],
[472, 0.748, 0.112, 0.061],
[476, 0.729, 0.115, 0.062],
[480, 0.745, 0.125, 0.060],
[484, 0.757, 0.140, 0.059],
[488, 0.753, 0.160, 0.057],
[492, 0.750, 0.187, 0.058],
[496, 0.746, 0.229, 0.058],
[500, 0.747, 0.285, 0.058],
[504, 0.735, 0.343, 0.056],
[508, 0.732, 0.390, 0.055],
[512, 0.739, 0.435, 0.056],
[516, 0.734, 0.464, 0.059],
[520, 0.725, 0.472, 0.057],
[524, 0.721, 0.476, 0.055],
[528, 0.733, 0.481, 0.059],
[532, 0.725, 0.462, 0.059],
[536, 0.732, 0.447, 0.058],
[540, 0.743, 0.441, 0.059],
[544, 0.744, 0.426, 0.061],
[548, 0.748, 0.406, 0.061],
[552, 0.728, 0.373, 0.063],
[556, 0.716, 0.347, 0.063],
[560, 0.733, 0.337, 0.067],
[564, 0.726, 0.314, 0.068],
[568, 0.713, 0.285, 0.072],
[572, 0.740, 0.277, 0.080],
[576, 0.754, 0.266, 0.090],
[580, 0.764, 0.250, 0.099],
[584, 0.752, 0.230, 0.124],
[588, 0.736, 0.207, 0.154],
[592, 0.734, 0.186, 0.192],
[596, 0.741, 0.171, 0.255],
[600, 0.740, 0.160, 0.287],
[604, 0.732, 0.148, 0.349],
[608, 0.745, 0.141, 0.402],
[612, 0.755, 0.136, 0.443],
[616, 0.751, 0.130, 0.487],
[620, 0.744, 0.126, 0.513],
[624, 0.731, 0.123, 0.558],
[628, 0.733, 0.121, 0.584],
[632, 0.744, 0.122, 0.620],
[636, 0.731, 0.119, 0.606],
[640, 0.712, 0.114, 0.609],
[644, 0.708, 0.115, 0.651],
[648, 0.729, 0.117, 0.612],
[652, 0.730, 0.117, 0.610],
[656, 0.727, 0.118, 0.650],
[660, 0.707, 0.120, 0.638],
[664, 0.703, 0.122, 0.627],
[668, 0.729, 0.128, 0.620],
[672, 0.750, 0.132, 0.630],
[676, 0.760, 0.139, 0.628],
[680, 0.751, 0.144, 0.642],
[684, 0.739, 0.146, 0.639],
[688, 0.724, 0.150, 0.657],
[692, 0.730, 0.152, 0.639],
[696, 0.740, 0.157, 0.635],
[700, 0.737, 0.159, 0.642]
])
W = colour.SpectralDistribution(D[..., 1], D[..., 0]).interpolate(colour.SpectralShape(400, 700, 1))
print('White\n-----')
print('sRGB (Scene-Referred Linear) :', colour.convert(W, 'Spectral Distribution', 'Scene-Referred RGB'))
print('sRGB (Output-Referred) :', colour.convert(W, 'Spectral Distribution', 'Output-Referred RGB'))
G = colour.SpectralDistribution(D[..., 2], D[..., 0]).interpolate(colour.SpectralShape(400, 700, 1))
print('Green\n-----')
print('sRGB (Scene-Referred Linear) :', colour.convert(G, 'Spectral Distribution', 'Scene-Referred RGB'))
print('sRGB (Output-Referred) :', colour.convert(G, 'Spectral Distribution', 'Output-Referred RGB'))
R = colour.SpectralDistribution(D[..., 3], D[..., 0]).interpolate(colour.SpectralShape(400, 700, 1))
print('Red\n---')
print('sRGB (Scene-Referred Linear) :', colour.convert(R, 'Spectral Distribution', 'Scene-Referred RGB'))
print('sRGB (Output-Referred) :', colour.convert(R, 'Spectral Distribution', 'Output-Referred RGB'))
L = colour.SpectralDistribution([0.0, 8.0, 15.6, 18.4], [400, 500, 600, 700], interpolator=colour.LinearInterpolator, sd_to_XYZ={'illuminant': colour.sd_ones(colour.SpectralShape(400, 700, 1))}).interpolate(colour.SpectralShape(400, 700, 1), interpolator=colour.LinearInterpolator)
print('Light\n-----')
print('sRGB (Scene-Referred Linear) :', colour.convert(L, 'Spectral Distribution', 'Scene-Referred RGB'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment