Colour Science for Python
Colour Science is a comprehensive open-source Python package providing a collection of algorithms and datasets for colour science applications, including colourspace conversions, colour appearance models, and spectral computations. It's currently at version 0.4.7 and maintains an active development cycle with frequent alpha milestones and releases, often introducing new features and compatibility updates.
Warnings
- breaking Python version support has evolved. As of v0.4.7, the library requires Python >=3.11 and <3.15. Older Python versions (e.g., 3.5, 3.10) are no longer supported.
- gotcha Several key dependencies like `scipy` and `imageio` became optional in v0.4.7. If your code relies on functionalities provided by these packages, you must explicitly install them, potentially using `pip install "colour-science[all]"` or `pip install colour-science[scipy,imageio]`.
- deprecated The `pygraphviz` dependency, previously used for graph visualization, was replaced by `pydot` in v0.4.5 due to `pygraphviz`'s installation difficulties.
- gotcha Support for `Numpy 2` was implemented in v0.4.5. While this is a feature, users with very old `Numpy` versions (e.g., pre-1.19.x) might encounter compatibility issues, as the library evolved to support newer `Numpy` APIs.
- gotcha In v0.4.6, `trimesh` was briefly and incorrectly added as a required dependency, leading to unexpected installations for some users. This was quickly fixed.
Install
-
pip install colour-science -
pip install "colour-science[all]"
Imports
- colour
import colour
- RGB_to_XYZ
import colour colour.RGB_to_XYZ(...)
Quickstart
import colour
import numpy as np
# Define an sRGB colour in the range [0, 1]
srgb_colour = np.array([0.4, 0.6, 0.8])
# Convert sRGB to XYZ D65
x_y_z_colour = colour.sRGB_to_XYZ(srgb_colour)
# Convert XYZ D65 to Lab D65
lab_colour = colour.XYZ_to_Lab(x_y_z_colour)
print(f"sRGB Colour: {srgb_colour}")
print(f"XYZ D65 Colour: {x_y_z_colour}")
print(f"Lab D65 Colour: {lab_colour}")