• Stars
    star
    320
  • Rank 131,126 (Top 3 %)
  • Language
    TeX
  • Created almost 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐ŸŒˆ Tools for color research

coloria

Tools for color research.

PyPi Version PyPI pyversions GitHub stars Downloads

Discord

Installation

Install Coloria from PyPI with

pip install coloria

To run Coloria, you need a license. See here for more info.

Illuminants, observers, white points

Illuminants CIE 1931 Observer
import coloria
import matplotlib.pyplot as plt

illu = coloria.illuminants.d65()
plt.plot(illu.lmbda_nm, illu.data)
plt.xlabel("wavelength [nm]")
plt.show()

The following illuminants are provided:

  • Illuminant A ("indoor light", coloria.illuminants.a(resolution_in_nm))
  • Illuminant C (obsolete, "North sky daylight", coloria.illuminants.c())
  • Illuminants D ("natural daylight", coloria.illuminants.d(nominal_temp) or coloria.illuminants.d65() etc.)
  • Illuminant E (equal energy, coloria.illuminants.e())
  • Illuminant series F ("fluorescent lighting", coloria.illuminants.f2() etc.)

Observers:

  • CIE 1931 Standard 2-degree observer (coloria.observers.coloria.observers.cie_1931_2())
  • CIE 1964 Standard 10-degree observer (coloria.observers.coloria.observers.cie_1964_10())

Color appearance models

Color appearance models (CAMs) predicts all kinds of parameters in color perception, e.g., lightness, brightness, chroma, colorfulness, saturation etc. Since these values depend on various factors, such as the surrouning, the models are initialized with various different parameters.

CAMs can be used to construct color spaces (see below).

The color appearance models available in coloria are

  • CIECAM02 / CAM02-UCS

    import coloria
    
    ciecam02 = coloria.cam.CIECAM02("average", 20, 100)
    # parameters:
    # c:   surround parameter
    # Y_b: relative background luminance
    # L_A: luminance of the adapting field
    
    xyz = [19.31, 23.93, 10.14]
    corr = ciecam02.from_xyz100(xyz)
    # then work with those values:
    corr.lightness
    corr.brightness
    corr.chroma
    corr.hue_composition
    corr.hue_angle_degrees
    corr.colorfulness
    corr.saturation
  • CAM16 / CAM16-UCS

    import coloria
    
    cam16 = coloria.cam.CAM16("average", 20, 100)
  • ZCAM

    import coloria
    
    cam16 = coloria.cam.ZCAM("average", 20, 100, 20)

Color coordinates and spaces

Color coordinates are handled as NumPy arrays or as ColorCoordinates, a thin wrapper around the data that retains the color space information and has some handy helper methods. Color spaces can be instantiated from the classes in coloria.cs, e.g.,

import coloria

coloria.cs.CIELAB()

Most methods that accept such a colorspace also accept a string, e.g., cielab.

As an example, to interpolate two sRGB colors in OKLAB, and return the sRGB:

from coloria.cs import ColorCoordinates

# you can also plug in large numpy arrays instead of two lists here
c0 = ColorCoordinates([1.0, 1.0, 0.0], "srgb1")  # yellow
c1 = ColorCoordinates([0.0, 0.0, 1.0], "srgb1")  # blue

# naive interpolation gives [0.5, 0.5, 0.5], a mid gray

# convert to OKLAB
c0.convert("oklab")
c1.convert("oklab")

# interpolate
c2 = (c0 + c1) * 0.5

c2.convert("srgbhex", mode="clip")

print(c2.color_space)
print(c2.data)
<coloria color space sRGB-hex>
#6cabc7

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 already implemented:

  • XYZ (coloria.cs.XYZ(100), the parameter determining the scaling)

  • xyY (coloria.cs.XYY(100), the parameter determining the scaling of Y)

  • sRGB (coloria.cs.SRGBlinear(), coloria.cs.SRGB1(), coloria.cs.SRGB255(), coloria.cs.SRGBhex())

  • HSL and HSV (coloria.cs.HSL(), coloria.cs.HSV()) These classes also have the two methods

    from_srgb1()
    to_srgb1()
    

    for direct conversion from and to standard RGB.

  • OSA-UCS (coloria.cs.OsaUcs()), 1947

  • CIELAB (coloria.cs.CIELAB()), 1976

  • CIELUV (coloria.cs.CIELUV()), 1976

  • RLAB (coloria.cs.RLAB()), 1993

  • IPT (coloria.cs.IPT()), 1998

  • DIN99 and its variants DIN99{b,c,d} (coloria.cs.DIN99()), 1999

  • CAM02-UCS, 2002

    import coloria
    
    cam02 = coloria.cs.CAM02("UCS", "average", 20, 100)

    The implementation contains a few improvements over the CIECAM02 specification (see here).

  • CAM16-UCS, 2016

    import coloria
    
    cam16ucs = coloria.cs.CAM16UCS("average", 20, 100)

    The implementation contains a few improvements over the CAM16 specification (see here).

  • SRLAB2 (coloria.cs.SRLAB2())

  • Jzazbz (coloria.cs.JzAzBz()), 2017

  • ICtCp (coloria.cs.ICtCp()), 2018

  • IGPGTG (coloria.cs.IGPGTG()), 2020

  • proLab (coloria.cs.PROLAB()), 2020

  • Oklab (coloria.cs.OKLAB()), 2020

  • OkLCh (coloria.cs.OKLCH()), 2020

  • HCT (coloria.cs.HCT()/ HCTLAB (coloria.cs.HCTLAB()), 2022

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

Color difference formulas

coloria implements the following color difference formulas:

  • CIE76
    coloria.diff.cie76(lab1, lab2)
  • CIE94
    coloria.diff.cie94(lab1, lab2)
  • CIEDE2000
    coloria.diff.ciede2000(lab1, lab2)
  • CMC l:c
    coloria.diff.cmc(lab1, lab2)

Chromatic adaptation transforms

coloria implements the following CATs:

  • von Kries
    cat, cat_inv = coloria.cat.von_kries(whitepoint_source, whitepoint_destination)
    xyz1 = cat @ xyz0
  • Bradford (coloria.cat.bradford)
  • sharp (coloria.cat.sharp)
  • CMCCAT2000 (coloria.cat.cmccat2000)
  • CAT02 (coloria.cat.cat02)
  • CAT16 (coloria.cat.cat16)
  • Bianco-Schettini (coloria.cat.bianco_schettini)

Gamut visualization

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

sRGB gamut

CIELAB CAM16-UCS Oklab

The sRGB gamut is a perfect cube in sRGB space, and takes curious shapes when translated into other color spaces. The above images show the sRGB gamut in different color spaces.

import coloria

p = coloria.plot_rgb_gamut(
    "cielab",  # or coloria.cs.CIELAB()
    n=51,
    show_grid=True,
)
p.show()

For more visualization options, you can store the sRGB data in a file

import coloria

coloria.save_rgb_gamut("srgb.vtk", "cielab", n=51)
# all formats supported by https://github.com/coloria-dev/meshio

and open it with a tool of your choice. See here for how to open the file in ParaView.

For lightness slices of the sRGB gamut, use

import coloria

p = coloria.plot_rgb_slice("cielab", lightness=50.0, n=51)
p.show()
# or
# p.screenshot("screenshot.png")

Surface color gamut

XYZ CIELAB CAM16-UCS

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

import coloria

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

p = coloria.plot_surface_gamut(
    "xyz100",  # or coloria.cs.XYZ(100)
    observer,
    illuminant,
)
p.show()

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

The visible gamut

xyY JzAzBz Oklab

Same as above, but with the gamut of visible colors up to a given lightness Y.

import coloria

observer = coloria.observers.cie_1931_2()

colorspace = coloria.cs.XYZ(100)

p = coloria.plot_visible_gamut(colorspace, observer, max_Y1=1)
p.show()

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

For slices, use

import coloria

plt = coloria.plot_visible_slice("cielab", lightness=0.5)
plt.show()

Color gradients

With coloria, you can easily visualize the basic color gradients of any color space. This may make defects in color spaces obvious, e.g., the well-known blue-distortion of CIELAB and related spaces. (Compare with the hue linearity data below.)

import coloria

plt = coloria.plot_primary_srgb_gradients("cielab")
plt.show()
CIELAB DIN99 OKLAB

Experimental data

coloria contains lots of experimental data sets some of which can be used to assess certain properties of color spaces. Most data sets can also be visualized.

Color differences

xyY CIELAB CAM16

Color difference data from MacAdam (1974). The above plots show the 43 color pairs that are of comparable lightness. The data is matched perfectly if the facing line stubs meet in one point.

import coloria

data = coloria.data.MacAdam1974()

cs = coloria.cs.CIELAB

plt = data.plot(cs)
plt.show()
print(coloria.data.MacAdam1974().stress(cs))
24.54774029343344

The same is available for

coloria.data.BfdP()
coloria.data.Leeds()
coloria.data.RitDupont()
coloria.data.Witt()

coloria.data.COMBVD()  # a weighted combination of the above

Munsell

xyY CIELAB CAM16

Munsell color data is visualized with

import coloria

cs = coloria.cs.CIELUV
plt = coloria.data.Munsell().plot(cs, V=5)
plt.show()

To retrieve the Munsell data in xyY format, use

import coloria

munsell = coloria.data.Munsell()

# munsell.h
# munsell.V
# munsell.C
# munsell.xyy

Ellipses

MacAdam ellipses (1942)
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 coloria

cs = coloria.cs.CIELUV
plt = coloria.data.MacAdam1942(50.0).plot(cs)
plt.show()

The better the colorspace matches the data, the closer the ellipses are to circles of the same size.

Luo-Rigg ellipses
xyY CIELAB CAM16

Likewise for Luo-Rigg.

import coloria

# xyy = coloria.cs.XYY(100)
# coloria.data.LuoRigg(8).show(xyy, 0.4)
# coloria.data.LuoRigg(8).savefig("luo-rigg-xyy.png", xyy, 0.4)

cieluv = coloria.cs.CIELUV()
plt = coloria.data.LuoRigg(8).plot(cieluv, 50)
plt.show()

Hue linearity

Ebner-Fairchild
xyY CIELAB CAM16

For example

import coloria

colorspace = coloria.cs.JzAzBz
plt = coloria.data.EbnerFairchild().plot(colorspace)
plt.show()

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.)

Hung-Berns

Likewise for Hung-Berns:

xyY CIELAB CAM16

Note the dark blue distortion in CIELAB and CAM16.

import coloria

colorspace = coloria.cs.JzAzBz
plt = coloria.data.HungBerns().plot(colorspace)
plt.show()
Xiao et al.

Likewise for Xiao et al.:

xyY CIELAB CAM16
import coloria

colorspace = coloria.cs.CIELAB
plt = coloria.data.Xiao().plot(colorspace)
plt.show()

Lightness

Fairchild-Chen
xyY CIELAB CAM16

Lightness experiment by Fairchild-Chen.

import coloria

cs = coloria.cs.CIELAB
plt = coloria.data.FairchildChen("SL2").plot(cs)
plt.show()

Articles

More Repositories

1

tikzplotlib

๐Ÿ“Š Save matplotlib figures as TikZ/PGFplots for smooth integration into LaTeX.
Python
2,398
star
2

meshio

๐Ÿ•ธ๏ธ input/output for many mesh formats
Python
1,930
star
3

tiptop

๐Ÿ–ฅ๏ธ Command-line system monitoring
Python
1,749
star
4

tuna

๐ŸŸ Python profile viewer
Python
1,363
star
5

perfplot

๐Ÿ“ˆ Performance analysis for Python snippets
Python
1,339
star
6

awesome-scientific-computing

๐Ÿ˜Ž Curated list of awesome software for numerical analysis and scientific computing
Python
1,319
star
7

pygmsh

๐Ÿ•ธ๏ธ Gmsh for Python
Python
844
star
8

matplotx

๐Ÿ“Š More styles and useful extensions for Matplotlib
Python
789
star
9

termplotlib

๐Ÿ“ˆ Plotting on the command line
Python
669
star
10

stressberry

Stress tests for the Raspberry Pi ๐Ÿ˜…
Python
319
star
11

github-trends

๐Ÿ“ˆ GitHub star history plots
260
star
12

dufte

๐Ÿ“ˆ Minimalistic Matplotlib style
Python
216
star
13

deadlink

๐Ÿ’€ Checks and fixes URLs in code and documentation.
Python
162
star
14

cplot

๐ŸŒˆ Plot complex functions
Python
149
star
15

termtables

๐Ÿ–ฅ๏ธ Pretty tables in the terminal
Python
98
star
16

pytest-codeblocks

๐Ÿ“„ Test code blocks in your READMEs
Python
95
star
17

action-cached-lfs-checkout

GitHub checkout action with LFS files pulled from cache
Just
90
star
18

ua-beamer

A LaTeX beamer theme for the University of Antwerp
TeX
75
star
19

pipdate

Small pip update helpers.
Python
73
star
20

matlab-guidelines

Guidelines for writing clean and fast code in MATLAB
TeX
67
star
21

spectro

๐ŸŽต Audio file analysis
Python
47
star
22

tablign

Aligns columns in your ASCII tables on the command line or in vim.
Python
43
star
23

pyfoobar

Python project template/scaffold and best practices
Python
41
star
24

betterspy

๐Ÿ‘€ Visualization for SciPy sparse matrices.
Python
40
star
25

color-data

๐ŸŒˆ Collected experimental data for color research
Python
39
star
26

stackoverflow-trends

๐Ÿ“ˆ StackOverflow trends
35
star
27

xhub

๐Ÿ“ GitHub with LaTeX math, diagrams, etc.
JavaScript
35
star
28

maelstrom

Numerical simulation of magnetohydrodynamics.
Python
33
star
29

purple-pi

๐Ÿ’œ LaTeX math wherever you want
JavaScript
31
star
30

stackoverflow-card

JavaScript
31
star
31

markdown-math-acid-test

Showcase GitHub math bugs
25
star
32

fontman

Manage and update your installed fonts.
Python
21
star
33

tau

The better pi
Python
20
star
34

pyfma

Fused multiply-add (with a single rounding) for Python.
Python
20
star
35

scipyx

SciPy fixes and extensions
Python
18
star
36

gitfaces

Fetch contributor avatars for a GitHub repository
Python
17
star
37

epicycler

Create epicycle animations.
Python
15
star
38

fjson

Python JSON writer with formatted floats
Python
14
star
39

python-vs-cpp

C++
13
star
40

identinum

Identify exact expression for decimal.
Python
9
star
41

mikado

Friendly solver interfaces for Trilinos.
C++
8
star
42

materials

Density, magnetic permeability etc. for a range of materials.
Python
8
star
43

note-on-cam16

Algorithmic improvements for the CIECAM02 and CAM16 color appearence models
TeX
8
star
44

matheon-html5-template

Matheon HTML5 presentation template
JavaScript
8
star
45

flow

Navier-Stokes and heat equation with FEniCS.
Python
5
star
46

nosh

A numerical solver for nonlinear Schrรถdinger equations
C++
4
star
47

tex-font-errors-cheatsheet

Cheat sheet(s) for decoding the meaning of TeX font errors
3
star
48

rhino

Python
3
star
49

vandermonde

๐Ÿ“ Tools for working with Vandermonde matrices, e.g., Bjรถrck-Pereyra.
Python
3
star
50

keygen_licensing_tools

Tools for license valididation with Keygen.sh
Python
3
star
51

corona-charts

Corona data and charts, updated automatically
Python
2
star
52

plm

Python
2
star
53

math-test

2
star
54

github-mathml-test

2
star
55

parabolic

Time stepping methods for parabolic problems.
Python
2
star
56

sippp

Fortran library for the solution of singularly perturbed parabolic problems
Fortran
2
star
57

nschloe.github.io

HTML
2
star
58

hanoi-material

Class material for nonlinear optimization at Hanoi Autumn School 2013
MATLAB
2
star
59

talk-python-scientific

Python in Scientific Computation
JavaScript
2
star
60

trilinos-tutorial

C++
1
star
61

tspsolve

Solution algorithms for the travelling salesman problem.
Python
1
star
62

launchpadtools

Tools for submitting packages to Ubuntu Launchpad
Python
1
star
63

nschloe

about me
1
star