Project overview

After working on PGS subtitle extraction, which involves conversion of BT.709 YCbCr to the sRGB color space, I continued investigating other aspects of colorimetry. This project contains C-language tools developed during that work.

The intent is to work from first principles to the greatest extent practical. The programs therefore work directly with CIE color-matching functions (CMFs). The bundled CMF data were obtained from the Colour & Vision Research Laboratory (CVRL).

For display on a typical computer monitor, sRGB uses the D65 white point and the same RGB chromaticity primaries as BT.709. The programs can apply the sRGB transfer function to linear RGB values where appropriate. Other RGB primaries and white points are available in some programs for comparison and experimentation.

The original CIE 1931 standard observer was based on a 2° field of view. Because cone distribution across the retina is not uniform, the CIE later standardized a 10° observer in 1964 for applications involving a larger field of view.

Programs

matrix.c

Derives RGB-to-XYZ and XYZ-to-RGB conversion matrices for a selected RGB color space and white point, and suggests the native/reference white associated with each defined RGB space where one is known.

wl.c

Reports CMF tristimulus values, spectral chromaticity coordinates, and corresponding sRGB values for a selected wavelength.

vis-spec.c

Produces an sRGB bitmap approximation of the visible spectrum using a selected CMF and white point.

Color-matching-function data

Dataset Range Sampling File
CIE 1931 2° XYZ CMFs 360–830 nm 1 nm CIE_xyz_1931_2deg.csv
CIE 1931 2° XYZ CMFs, Judd (1951) 370–770 nm 10 nm CIE_xyz_1931_2deg_judd1951.csv
CIE 1931 2° XYZ CMFs, Judd (1951) + Vos (1978) 380–825 nm 5 nm CIE_xyz_1931_2deg_judd1951_vos1978.csv
CIE 1964 10° XYZ CMFs 360–830 nm 1 nm CIE_xyz_1964_10deg.csv
2006 2° XYZ CMFs from CIE 2006 LMS fundamentals 390–830 nm 0.1 nm CIE_xyz_2006_2deg_lms_cones.csv
2006 10° XYZ CMFs from CIE 2006 LMS fundamentals 390–830 nm 0.1 nm CIE_xyz_2006_10deg_lms_cones.csv

Each CSV row contains wavelength in nanometres followed by x̄, ȳ, and z̄. There is no header row.

Visible spectrum results

These images were generated by the visible-spectrum program using the indicated color-matching functions and white reference. The available CMF wavelength ranges are not all the same. As noted above, the resulting sRGB colors are display approximations because monochromatic spectral colors lie outside the sRGB gamut.

Building and running

On a system with GCC and make, clone the repository and run:

make

The Makefile builds locus, matrix, vis-spec, and wl in the repository root. The programs are interactive; for example:

./wl

The CMF-reading programs use the files under data/ for their built-in choices. locus and vis-spec write out.bmp and refuse to overwrite an existing file of that name.