Color management for NumPy: LittleCMS2 bindings, color spaces, ICC profile authoring and colormaps
Maintained. Last release 3 days ago, commits in 2 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install python-lcms2README as published on PyPI with version 0.4.7.
python-lcms2
Color management for NumPy. Convert images between ICC profiles and color spaces in one call, measure color differences, build exact ICC profiles from your own NumPy color math, and make perceptually uniform colormaps, all backed by LittleCMS 2.
Features
| Feature | What you get |
|---|---|
| One-call conversion | lcms2.convert(img, "sRGB", "Display P3"): pixel formats come from the array's dtype and shape. |
| Profiles | 24 built-ins (sRGB, Display P3, Adobe RGB, ProPhoto, Rec.2020, Lab, XYZ, …), ICC files, bytes; read and edit header, text and tags. |
| Transforms | Rendering intents, black-point compensation, soft proofing with gamut check, multi-profile chains, device links. |
| Fast and safe | The GIL is released during transforms; any contiguity or stride; alpha channels carried through. |
| Color spaces | OKLab, OKLCh, CIE LCh, HSV, HWB, Display P3, Rec.2100 PQ/HLG, … as NumPy functions, mixed freely with ICC profiles. |
| ICC authoring | lcms2.Profile(my_space) traces your NumPy to_xyz/from_xyz into an exact ICC v4/v5 profile. |
| Colorimetry | ΔE 76/94/2000/CMC/BFD, CIECAM02, white point ⇄ color temperature, chromatic adaptation. |
| Tone curves | Gamma, parametric and tabulated curves; evaluate, invert, join, estimate gamma. |
| Colormaps | Perceptually uniform colormaps in OKLab, gamut-mapped, color-vision-deficiency simulation, matplotlib export. |
| Measurement data | Read and write CGATS / IT8 files. |
Wheels for Windows, Linux and macOS (x86-64 and ARM64) on Python 3.10 and later, including free-threaded 3.14t and 3.15t, and PyPy 3.11; Pyodide wheels on PyPI. NumPy is the only dependency.
Install
pip install python-lcms2
pip install "python-lcms2[plot]" # + matplotlib for colormap export
Use
import numpy as np
import lcms2
img = np.asarray(...) # (H, W, 3) uint8, e.g. from Pillow or OpenCV
p3 = lcms2.convert(img, "sRGB", "Display P3") # uint8 in, uint8 out
lab = lcms2.Profile("sRGB").transform(img, "Lab") # float64 L*a*b*
lcms2.convert([255, 0, 0], "sRGB", "Lab", intent="relative")
# array([54.29, 80.81, 69.89])
lcms2.convert([255, 0, 0], "sRGB", "oklab")
# array([0.6279, 0.2249, 0.1258])
Reuse a Transform when converting many images; formats are resolved per input and cached. press.icc stands
for any CMYK profile, e.g. from your printer or from ECI:
to_cmyk = lcms2.Transform("sRGB", lcms2.Profile("press.icc"), intent="relative", bpc=True)
cmyk = to_cmyk(img) # (H, W, 4) uint8
Profiles
srgb = lcms2.Profile("sRGB") # built-in (case-insensitive: "display p3", "adobe rgb", …)
cmyk = lcms2.Profile("press.icc") # a file
web = lcms2.Profile.from_bytes(icc_bytes) # bytes, e.g. embedded in an image
cmyk # <Profile 'Fogra27L CMYK Coated Press' CMYK output v2.2>
cmyk.color_space, cmyk.device_class, cmyk.tags
cmyk.description = "Press proof"
cmyk.save("press-v2.icc")
Soft proofing
proof = lcms2.Transform(srgb, srgb, proof=cmyk, gamut_check=True)
proof(img) # how img prints; out-of-gamut pixels marked gray
Your own color space, as an ICC profile
from lcms2.spaces import ColorSpace
M = np.array([[0.4360747, 0.3850649, 0.1430804], # sRGB primaries → XYZ (D50)
[0.2225045, 0.7168786, 0.0606169],
[0.0139322, 0.0971045, 0.7141733]])
M_inv = np.linalg.inv(M)
class Gamma18(ColorSpace):
n_channels = 3
def to_xyz(self, rgb):
return np.asarray(rgb) ** 1.8 @ M.T
def from_xyz(self, xyz):
return np.clip(np.asarray(xyz) @ M_inv.T, 0, None) ** (1 / 1.8)
profile = lcms2.Profile(Gamma18()) # exact matrix/TRC profile, usable in any CMS
profile.save("gamma18.icc")
lcms2.convert(img, profile, "sRGB")
Built-in analytic spaces (lcms2.spaces.oklab, oklch, hsv, display_p3, rec2100_pq, …) work the same
way: lcms2.spaces.oklab.profile is an ICC profile of OKLab.
Color differences
lcms2.delta_e(lab1, lab2) # CIEDE2000, vectorized over (..., 3)
lcms2.delta_e(lab1, lab2, method="cmc", l=2, c=1)
Colormaps
import matplotlib.pyplot as plt
cm = lcms2.Colormap.from_colors(["#0b1a3a", "#f08a24", "#fff6d5"]) # interpolated in OKLab
cm = lcms2.Colormap.get("glacier") # built-ins: lcms2.colormap.list()
values = np.linspace(0, 1, 256)
rgb = cm(values) # (256, 3) floats; bytes=True for uint8
cm.is_lightness_monotonic(), cm.uniformity()
cm.simulate("deuteranopia") # color-vision-deficiency preview
plt.imshow(np.random.rand(64, 64), cmap=cm.to_matplotlib())
Examples
examples/ is an 11-step learning path, from one-call conversions to profiles, transforms, soft proofing, color spaces, ICC authoring, colorimetry, tone curves, colormaps, CGATS files and device links. Each step is a runnable script with a Jupyter notebook beside it that shows the results (see its README). All figures below are drawn by the examples.
![]() Soft proof and out-of-gamut pixels | ![]() Gradients mixed in sRGB vs OKLab | ![]() CIEDE2000 heatmap |
![]() Tone curves | ![]() Built-in perceptual colormaps | ![]() Color-vision-deficiency preview |
Documentation
- Installation and quickstart
- Guides: profiles, transforms and proofing, color spaces, ICC authoring, colorimetry, colormaps, CGATS files
- Value ranges and pixel formats
- API reference
Contributing
Building from source and the developer commands are in the contributing guide.
License
MIT. LittleCMS is © Marti Maria Saguer, MIT license (vendor/Little-CMS/LICENSE).





