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
Metadata
Release files for lambda2color 0.8.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lambda2color-0.8.2.tar.gz | 5.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lambda2color-0.8.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.0 kB
Release files / lambda2color-0.8.2.tar.gz
| Download URL | lambda2color-0.8.2.tar.gz |
|---|---|
| Size | 5.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e563288ac20aa56223999fb56d3f4662a99f83ca463afedafb36bcfd98c77c6
|
|
BLAKE2b-256 checksum How to use checksums |
e9c0033b7ed6391df0ff9a13c65365b07cc48c0b1d07fec6baa7c9a911c3bd52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|
Release files / lambda2color-0.8.2-py3-none-any.whl
| Download URL | lambda2color-0.8.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bd97f6d6e3fc3f194c30eb1db88d77e572b3a6b17119f7d07fe37051ca61ff0
|
|
BLAKE2b-256 checksum How to use checksums |
c6c16ef390208ab986b0a51deab5987f00b93785fe37150c11f127af44699e50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.15
|