Colorimetry
After working on PGS subtitle extractions which involve conversion of BT.709 YCbCr to sRGB colorspace, I continued investigating other aspects of colorimetry. I will include here any C language tools I develop.
The intent is to work from first principles to the greatest extent possible. In this case that means working directly from the CIE color-matching functions, which were obtained from The Colour & Vision Research Laboratory. Those data are included in a table below.
Typically RGB values would be used to display images on a screen. The sRGB standard specifies the 1931 2-deg observer D65 white coordinates and includes gamma-correction to be applied to the linear RGB values to account for the non-linearity in display of color on computer monitors. The routines provided below allow for application of sRGB gamma-correction. Generally you want to use the 1931 D65 white reference and sRGB gamma-correction if displaying on a computer monitor. The sRGB standard RGB color primaries are the same as the BT.709 color primaries used in high-definition television (e.g., see PGS subtitle extractions).
Usually CMFs are created by test subjects adjusting R, G, and B intensities in order to match a test color. They originally observed the test color and color match within a 2-degree field of view. It was later recognized that the cone distribution on the retina is not uniform and for some applications a 10-deg field of view is more appropriate, thus in 1964 the CIE approved a 10-deg CMF standard.
NOTE: None of the monochromatic (single wavelength) stimuli can be recreated accurately using the sRGB colorspace since those chromaticities lie outside the sRGB chromaticity triangle. This means sRGB images of the visible spectrum are, by definition, incorrect. It is also popular to create sRGB images of the chromaticity locus with the entire space within the locus plotted with color pixels, however, only those points within the sRGB triangle can be properly rendered in an sRGB image. Most chromaticity diagrams on the web (which are, of course, sRGB images) fill in the entire space within the locus anyway.
Produce chromativity locus drawings |
locus.c | Produce a bitmap of the chromaticity locus for selected CMF, with or without axis scales. Can include RGB gamut triangle for selected RGB colorspace, and can also include marker for white point. For example, this is the 1931 chromaticity locus with sRGB gamut triangle included. Can also plot one gamut outline and color-in the sRGB gamut like here (1931 locus, Adobe RGB primary triangle, sRGB colored-in, D65 whitepint marked). Requires CMFs from table below. Compile: gcc -Wall locus.c -lm -o locus Usage: ./locus Output: out.bmp |
Derive the XYZ/RGB conversion matrices |
matrix.c | Derive the XYZ/RGB conversion matrix for a selected RGB colorspace and illuminant. Compile: gcc -Wall matrix.c -lm -o matrix Usage: ./matrix Output: reports to stdout |
Convert Wavelength to XYZ and RGB Coordinates |
wl.c | Produce XYZ and RGB coordinates for user-supplied wavelength (i.e., monochromatic light). Results are given with and without sRGB gamma-correction. Requires CMFs from table below. Compile: gcc -Wall wl.c -lm -o wl Usage: ./wl Output: reports to stdout |
Visible Spectrum Calculation |
bmp.c | Produce a bitmap of the visible spectrum using the selected color-matching functions (CMFs) and white reference, with or without sRGB gamma-correction. Results are produced in 0.1 nm intervals, using linear interpolation of CMFs, if necessary. NOTE: None of the monochromatic (single wavelength) stimuli can be recreated accurately using the sRGB colorspace since those chromaticities lie outside the sRGB chromaticity triangle, so although they're pretty, they're not particularly useful. Requires CMFs from table below. Compile: gcc -Wall bmp.c -lm -o bmp Usage: ./bmp Output: out.bmp |
Color-Matching Functions (CMFs) (as comma-separated value files) |
CIE_xyz_1931_2deg.csv | CIE 1931 2-deg CMFs (360 - 830 nm) |
CIE_xyz_1931_2deg_judd1951.csv | CIE 1931 2-deg CMFs modified by Judd (1951) (370 - 770 nm) |
CIE_xyz_1931_2deg_judd1951_vos1978.csv | CIE 1931 2-deg CMFs modified by Judd (1951) and Vos (1978) (380 - 825 nm) |
CIE_xyz_1964_10deg.csv | CIE 1964 10-deg CMFs (360 - 830 nm) |
CIE_xyz_2006_2deg_lms_cones.csv | 2006 2-deg CMFs transformed from the CIE (2006) 2-deg LMS cone fundamentals (390 - 830 nm) |
CIE_xyz_2006_10deg_lms_cones.csv | 2006 10-deg CMFs transformed from the CIE (2006) 10-deg LMS cone fundamentals (390 - 830 nm) |
Visible Spectrum Results (see Note for bmp.c) Note that the available CMF wavelength ranges are not all the same. |
P. David Buchan pdbuchan@gmail.com