Colour Science for Python

0.4.7 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

This quickstart demonstrates a basic colourspace conversion from sRGB to XYZ and then to CIE Lab using the `colour` library. It showcases how to import the library and use its primary conversion functions with NumPy arrays.

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}")

view raw JSON →