Skip to content
Tools for color models
Python P4 Lua Roff Perl 6 Mathematica Other
Branch: master
Clone or download
Latest commit 13985ca Oct 1, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci circleci: install lxml Sep 25, 2019
.github/workflows gh-actions: install dependencies Sep 2, 2019
colorio version bump Oct 1, 2019
experiments lint fix Sep 2, 2019
test store luminosity index Oct 1, 2019
.bandit add bandit tests Feb 6, 2018
.flake8 add flake8 config Sep 18, 2018
.gitignore more gitignore Sep 12, 2019
.pylintrc some pylint fixes Feb 9, 2018
LICENSE update year, small readme update Apr 15, 2019
Makefile lint fix Sep 2, 2019 readme Oct 1, 2019
codecov.yml initial commit Jan 16, 2018 apply isort Jul 10, 2019
test_requirements.txt more test requirements Sep 18, 2018


Tools for color models.

CircleCI codecov Code style: black colorful PyPi Version DOI GitHub stars PyPi downloads

Color spaces

All color spaces implement the two methods

vals = colorspace.from_xyz100(xyz)
xyz = colorspace.to_xyz100(vals)

for conversion from and to XYZ100. Adding new color spaces is as easy as writing a class that provides those two methods.

The following color spaces are implemented:

  • XYZ (colorio.XYZ())
  • xyY (colorio.XYY())
  • Linear SRGB (colorio.SrgbLinear()) This class has the two additional methods
    for conversion from and to standard RGB.
  • HSL and HSV (colorio.HSL(), colorio.HSV()) These classes have the two methods
    for conversion from and to standard RGB.
  • CIELAB (colorio.CIELAB())
  • CIELUV (colorio.CIELUV())
  • RLAB (colorio.RLAB())
  • ICtCp (colorio.ICtCp())
  • IPT (colorio.IPT())
  • CIECAM02 / CAM02-UCS
    import colorio
    L_A = 64 / numpy.pi / 5
    ciecam02 = colorio.CIECAM02(0.69, 20, L_A)
    cam02 = colorio.CAM02('UCS', 0.69, 20, L_A)
    The implementation contains a few improvements over the CIECAM02 specification (see here).
  • CAM16 / CAM16-UCS
    import colorio
    L_A = 64 / numpy.pi / 5
    cam16 = colorio.CAM16(0.69, 20, L_A)
    cam16ucs = colorio.CAM16UCS(0.69, 20, L_A)
    The implementation contains a few improvements over the CAM16 specification (see here).
  • Jzazbz (colorio.JzAzBz())

All methods in colorio are fully vectorized, i.e., computation is really fast.


colorio provides a number of useful tools for analyzing and visualizing color spaces.

Visualizing the SRGB gamut


The SRGB gamut is a perfect cube in SRGB space, and takes curious shapes when translated into other color spaces. The above image shows the SRGB gamut in XYZ space. The image data was created with

import colorio

colorspace = colorio.CIELAB()
colorspace.save_srgb_gamut( "srgb.vtk", n=50, cut_000=False)

# The HDR (Rec.2100, Rec.2020) gamut works the same way
colorspace.save_hdr_gamut("hdr.vtk", n=50, cut_000=False)

The VTK file can then be opened in, e.g., ParaView, where the following instructions apply:

  1. Open the file in ParaView and execute the following steps in the Properties tab to the left.
  2. Press the Apply button.
  3. Under the Coloring section, change Solid Color to srgb.
  4. If necessary, press the gear button to the right of the search field to activate advanced options.
  5. Under the Scalar Coloring section, uncheck Map Scalars.

More images are in the gh-pages branch.

The data can be written in most formats supported by meshio. (You might have to install additional packages for some formats.)

Visualizing the visible gamut


Same as above, but with the gamut visible under a given illuminant.

import colorio

illuminant = colorio.illuminants.d65()
observer = colorio.observers.cie_1931_2()

colorspace = colorio.XYZ()
colorspace.save_visible_gamut(observer, illuminant, "visible.vtk")

The gamut is shown in grey since SRGB screens are not able to display the colors anyway.

Slices through the color spaces

Instead of fiddling around with the proper 3D objects, colorio can plot slices through all color spaces. One simply provides the slice index (typically the one that corresponds to "lightness" in the respective color space, e.g., 2 in xyY and 0 in CIELAB) and the slice level.

The solid line corresponds to monochromatic light; for convenience, the slice through the SRGB gamut is also displayed.

xyY (at Y=0.4) CIELAB (at L=50) CAM16-UCS (at J'=50)
import colorio

# xyy = colorio.XYY()
# xyy.show_visible_slice("xyy-visible-slice.png", 2, 0.4)

# cielab = colorio.CIELAB()
# cielab.show_visible_slice(0, 50)

cam16 = colorio.CAM16UCS(0.69, 20, 4.07)
cam16.show_visible_slice(0, 50)
# cam16.save_visible_slice("cam16ucs-visible-slice.png", 0, 50)

For convenience, it is also possible to show the classical visible gamut in xy with Planckian locus and the SRGB colors (at maximum luminosity).

import colorio


Show experimental data

colorio contains lots of experimental data sets some of which can be used to assess certain properties of color spaces.

xyY (at Y=0.4) CIELAB (at L=50) CAM16 (at L=50)

The famous MacAdam ellipses (from this article) can be plotted with

import colorio

# xyy = colorio.XYY()
# xyy.show_macadam(0.4)
# xyy.save_macadam("macadam-xyy.png", 0.4)

cieluv = colorio.CIELUV()
xyY (at Y=0.4) CIELAB (at L=50) CAM16 (at L=50)

Likewise for Luo-Rigg.

import colorio

# xyy = colorio.XYY()
# xyy.show_luo_rigg(0.4)
# xyy.save_luo_rigg("luo-rigg-xyy.png", 0.4)

cieluv = colorio.CIELUV()

For example

import colorio

colorspace = colorio.JzAzBz()

shows constant-hue data from the Ebner-Fairchild experiments in the hue-plane of some color spaces. (Ideally, all colors in one set sit on a line.)


Likewise for Hung-Berns:


Note the dark blue distortion in CIELAB and CAM16.

import colorio

colorspace = colorio.JzAzBz()
Xiao et al.

Likewise for Xiao et al.:

import colorio

colorspace = colorio.CIELAB()

Munsell color data is visualized with

import colorio

colorspace = colorio.CIELUV()

To retrieve the Munsell data in xyY format, use

import colorio

h, V, C, xyy = colorio.get_munsell_data()

Color differences

Color differences in any space can be computed with, b).


colorio is available from the Python Package Index, so just use

pip3 install colorio --user

to install.


To run the tests, simply check out this repository and run



colorio is published under the MIT license.

You can’t perform that action at this time.