Colour coordinates

Overview

This module provides rudimentary colour coordinate processing. Calculate the CIE 1931 rgb chromaticity coordinates for an arbitrary spectrum.

See the __main__ function for examples of use.

This package was partly developed to provide additional material in support of students and readers of the book Electro-Optical System Analysis and Design: A Radiometry Perspective, Cornelius J. Willers, ISBN 9780819495693, SPIE Monograph Volume PM236, SPIE Press, 2013. http://spie.org/x648.html?product_id=2021423&origin_id=x646

Module functions

pyradi.rychroma.chromaticityforSpectralL(spectral, radiance, xbar, ybar, zbar)

Calculate the CIE chromaticity coordinates for an arbitrary spectrum.

Given a spectral radiance vector and CIE tristimulus curves, calculate the CIE chromaticity coordinates. It is assumed that the radiance spectral density is given in the same units as the spectral vector (i.e. [1/um] or [1/cm-1], corresponding to [um] or [cm-1] respectively. It is furthermore accepted that the tristimulus curves are also sampled at the same spectral intervals as the radiance. See http://en.wikipedia.org/wiki/CIE_1931_color_space for more information on CIE tristimulus spectral curves.

Args:
spectral (np.array[N,] or [N,1]): spectral vector in [um] or [cm-1].
radiance (np.array[N,] or [N,1]): the spectral radiance (any units), (sampled at spectral).
xbar (np.array[N,] or [N,1]): CIE x tristimulus spectral curve (sampled at spectral values).
ybar (np.array[N,] or [N,1]): CIE y tristimulus spectral curve (sampled at spectral values).
zbar (np.array[N,] or [N,1]): CIE z tristimulus spectral curve (sampled at spectral values).
Returns:
[x,y,Y]: color coordinates x, y, and Y.
Raises:
No exception is raised.
pyradi.rychroma.XYZforSpectralL(spectral, radiance, xbar, ybar, zbar)

Calculate the CIE chromaticity coordinates for an arbitrary spectrum.

Given a spectral radiance vector and CIE tristimulus curves, calculate the XYZ chromaticity coordinates. It is assumed that the radiance spectral density is given in the same units as the spectral vector (i.e. [1/um] or [1/cm-1], corresponding to [um] or [cm-1] respectively. It is furthermore accepted that the tristimulus curves are also sampled at the same spectral intervals as the radiance. See http://en.wikipedia.org/wiki/CIE_1931_color_space for more information on CIE tristimulus spectral curves.

Args:
spectral (np.array[N,] or [N,1]): spectral vector in [um] or [cm-1].
radiance (np.array[N,] or [N,1]): the spectral radiance (any units), (sampled at spectral).
xbar (np.array[N,] or [N,1]): CIE x tristimulus spectral curve (sampled at spectral values).
ybar (np.array[N,] or [N,1]): CIE y tristimulus spectral curve (sampled at spectral values).
zbar (np.array[N,] or [N,1]): CIE z tristimulus spectral curve (sampled at spectral values).
Returns:
[X,Y,Z]: color coordinates X,Y,Z.
Raises:
No exception is raised.
pyradi.rychroma.loadCIEbar(specvec, stype)
Args:
specvec (np.array[N,] or [N,1]): spectral vector in [um] or [cm-1].
stype (str]): type spectral vector wl=wavelength, wn=wavenumber.
Returns:
CIE tristimilus (np.array[:,4]: cols=[specvec,x,y,z])
Raises:
No exception is raised.
pyradi.rychroma.rgb2CIExy(rgb, system='CIE RGB')

Convert from RGB coordinates to CIE (x,y) coordinates

The CIE RGB/Adobe/sRGB colour spaces a few colour spaces, using three monochromatic primary colours at standardized colours to represent a subset of the CIE xy chromaticy colour space.

This function converts from RGB coordinates (default CIE RGB) to CIE xy colour. The rgb array can have any number N of datasets in np.array[N,3]. r, g, and b and in the first, second and third columns.

https://en.wikipedia.org/wiki/CIE_1931_color_space https://en.wikipedia.org/wiki/RGB_color_space https://en.wikipedia.org/wiki/Adobe_RGB_color_space https://en.wikipedia.org/wiki/SRGB

Args:
rgb (np.array[N,3]): CIE red/green/blue colour space component, N sets
system (string): ‘CIE RGB’,’Adobe RGB’,’sRGB’
Returns:
xy (np.array[N,2]): color coordinates x, y.
Raises:
No exception is raised.
pyradi.rychroma.CIExy2rgb(xy, system='CIE RGB')

Convert from CIE RGB coordinates to CIE (x,y) coordinates

The CIE RGB/Adobe/sRGB colour spaces a few colour spaces, using three monochromatic primary colours at standardized colours to represent a subset of the CIE xy chromaticy colour space.

This function converts from xy coordinates to RGB (default CIE RGB). The xy array can have any number N of datasets in np.array[N,2]. x is in the first column and y in the second column

https://en.wikipedia.org/wiki/CIE_1931_color_space https://en.wikipedia.org/wiki/RGB_color_space https://en.wikipedia.org/wiki/Adobe_RGB_color_space https://en.wikipedia.org/wiki/SRGB

The rgb values are scaled such that the maximum value of any one component is 1, calculated separately per row. In other words, each rgb coordinate is normalised to 255 in one colour.

Args:
xy (np.array[N,2]): color coordinates x, y.
system (string): ‘CIE RGB’,’Adobe RGB’,’sRGB’
Returns:
rgb (np.array[N,3]): CIE red/green/blue colour space component, N sets
Raises:
No exception is raised.