使用颜色科学包将多个波长转换为单个 RGB 值

问题描述 投票:0回答:1

我正在使用包含反射系数 (Rf) 值及其相应波长的数据集,如下所示:

Rf          Wavelength
0.3907051   190
0.3907051   191
0.3907051   192
...
0.3907051   200

我正在尝试使用 colour-science 包将多个波长转换为单个 RGB 值,但我无法找到有关如何执行此操作的相关文档。如何将这些波长-Rf 对转换为单个 RGB 值?

python colors rgb
1个回答
0
投票

https://colour.readthedocs.io/en/latest/tutorial.html应该给你一个很好的起点。我不知道这个包,但我从教程中提取了什么(链接到评论中显示的相关部分):

enter image description here

import colour

# define the spectral distribution as a dict
# https://colour.readthedocs.io/en/latest/tutorial.html#from-spectral-distribution
data_sample = {
    380: 0.048,
    385: 0.051,
# [...]
    775: 0.432,
    780: 0.421,
}
sd = colour.SpectralDistribution(data_sample)
colour.plotting.plot_single_sd(sd)

# Calculate the tristimulus values from the spectral data
# https://colour.readthedocs.io/en/latest/tutorial.html#convert-to-tristimulus-values
cmfs = colour.MSDS_CMFS["CIE 1931 2 Degree Standard Observer"]
illuminant = colour.SDS_ILLUMINANTS["D65"]

XYZ = colour.sd_to_XYZ(sd, cmfs, illuminant)

# Convert to color
# https://colour.readthedocs.io/en/latest/tutorial.html#convert-to-display-colours
RGB = colour.XYZ_to_sRGB(XYZ / 100)
colour.plotting.plot_single_colour_swatch(colour.plotting.ColourSwatch(RGB, "Sample"), text_kwargs={"size": "x-large"})
© www.soinside.com 2019 - 2024. All rights reserved.