lambda2color: Wavelength-to-RGB Conversion
A lightweight Python library to convert light wavelengths (in nanometers) into corresponding RGB colors using the CIE 1931 XYZ color space.
Features
- Convert wavelengths (380–780 nm) to RGB values.
- Based on the CIE 1931 color matching functions.
- Supports custom illuminants and color spaces.
Installation
pip install lambda2color
Usage
from lambda2color import Lambda2color, xyz_from_xy
# Define a standard white illuminant (D65)
illuminant_D65 = xyz_from_xy(0.3127, 0.3291)
# Initialize color space conversion for sRGB
cs_srgb = Lambda2color(
red=xyz_from_xy(0.64, 0.33),
green=xyz_from_xy(0.30, 0.60),
blue=xyz_from_xy(0.15, 0.06),
white=illuminant_D65
)
# Convert wavelengths to RGB
wavelengths = cs_srgb.cmf[1:, 0]
N_wavelengths = len(wavelengths)
hues = np.zeros((N_wavelengths, 3))
for i_wavelength in range(N_wavelengths):
spec = np.zeros((N_wavelengths+1))
spec[i_wavelength] = 1
hues[i_wavelength, :] = cs_srgb.spec_to_rgb(spec)
# give for S, M and L cones' peak sensitivities
for spec, color in [(445, 'blue'), (555, 'green'), (600, 'red')]:
i_wavelength = np.argmin(np.abs(wavelengths - spec))
print(f' RGB for the {color=} at wavelength {wavelengths[i_wavelength]} nm: {hues[i_wavelength, :]}')
Documentation
Visualizations
CIE Color Matching Functions
Spectral Colors
Advanced Use Cases
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lambda2color-0.8.2.tar.gz
(5.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambda2color-0.8.2.tar.gz.
File metadata
- Download URL: lambda2color-0.8.2.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e563288ac20aa56223999fb56d3f4662a99f83ca463afedafb36bcfd98c77c6
|
|
| MD5 |
bb01424994c91bf67aa7df6352f9ef4e
|
|
| BLAKE2b-256 |
e9c0033b7ed6391df0ff9a13c65365b07cc48c0b1d07fec6baa7c9a911c3bd52
|
File details
Details for the file lambda2color-0.8.2-py3-none-any.whl.
File metadata
- Download URL: lambda2color-0.8.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bd97f6d6e3fc3f194c30eb1db88d77e572b3a6b17119f7d07fe37051ca61ff0
|
|
| MD5 |
2327d54eb2cc435f1cd81763977164ba
|
|
| BLAKE2b-256 |
c6c16ef390208ab986b0a51deab5987f00b93785fe37150c11f127af44699e50
|