chaco.color_spaces module

Conversion functions between various color spaces.

The implementations and data are mostly taken from the old scipy.sandbox.image package.

The CIE XYZ tristimulus colorspace with a standard D65 whitepoint is the default interchange color space for the implementations here. This is a useful whitepoint for viewing on computer monitors. However, it should be noted that the dimmer D50 whitepoint is often used in print applications. Notably, ICC profiles use the XYZ space with a D50 whitepoint as one of its standard interchange color spaces.

chaco.color_spaces.convert(matrix, TTT, axis=- 1)

Apply linear matrix transformation to an array of color triples.

Parameters
  • matrix (float array (3, 3)) – The transformation to apply.

  • TTT (float array) – The set of colors to transform.

  • axis (int, optional) – The axis of TTT along which the color triples extend.

Returns

OUT – The transformed colors.

Return type

float array

chaco.color_spaces.join_colors(c1, c2, c3, axis)

Rejoin the separated colors into a single array.

chaco.color_spaces.lab2xyz(lab, axis=- 1, wp=[0.9504285453771807, 1.0, 1.0889003707981277])

Convert CIE L*a*b* colors to XYZ tristimulus values.

Parameters
  • lab (float array) – L*a*b* values.

  • axis (int, optional) – The axis of the XYZ values.

  • wp (list of 3 floats, optional) – The XYZ tristimulus values of the whitepoint.

Returns

xyz – The XYZ colors.

Return type

float array

chaco.color_spaces.makeslices(n)

Return a list of n slice objects.

Each slice object corresponds to [:] without arguments.

chaco.color_spaces.msh2xyz(msh, axis=- 1, wp=[0.9504285453771807, 1.0, 1.0889003707981277])

Convert Msh values to XYZ tristimulus values.

Parameters
  • msh (float array) – The Msh colors.

  • axis (int, optional) – The axis of the XYZ values.

  • wp (list of 3 floats, optional) – The XYZ tristimulus values of the whitepoint.

Returns

xyz – XYZ values.

Return type

float array

chaco.color_spaces.rgb2rgbp(rgb, gamma=None)

Convert linear RGB coordinates to nonlinear R’G’B’ coordinates.

Parameters
  • rgb (float array) –

  • gamma (float, optional) – If provided, then this value of gamma will be used to correct the colors. If not provided, then the standard sR’G’B’ space will be assumed. It is almost, but not quite equivalent to a gamma of 2.2.

Returns

rgbp

Return type

float array

chaco.color_spaces.rgb2xyz(rgb, axis=- 1)

Convert linear RGB coordinates to XYZ tristimulus values.

Parameters
  • rgb (float array) – RGB values.

  • axis (int, optional) – The axis of the XYZ values.

Returns

xyz – The XYZ colors.

Return type

float array

chaco.color_spaces.rgbp2rgb(rgbp, gamma=None)

Convert nonlinear R’G’B’ coordinates to linear RGB coordinates.

Parameters
  • rgbp (float array) –

  • gamma (float, optional) – If provided, then this value of gamma will be used to correct the colors. If not provided, then the standard sR’G’B’ space will be assumed. It is almost, but not quite equivalent to a gamma of 2.2.

Returns

rgb

Return type

float array

chaco.color_spaces.separate_colors(xyz, axis=- 1)

Separate an array of color triples into three arrays, one for each color axis.

Parameters
  • xyz (float array) –

  • axis (int, optional) – The axis along which the color triples extend.

Returns

  • x (float array)

  • y (float array)

  • z (float array) – The separate color arrays.

  • axis (int) – The axis along which they need to be reassembled.

chaco.color_spaces.srgb2xyz(srgb, axis=- 1)

Convert sR’G’B’ colors to XYZ.

Parameters
  • srgb (float array) – sR’G’B’ values.

  • axis (int, optional) – The axis of the XYZ values.

Returns

xyz – The XYZ colors.

Return type

float array

chaco.color_spaces.triwhite(x, y)

Convert x,y chromaticity coordinates to XYZ tristimulus values.

chaco.color_spaces.xyz2lab(xyz, axis=- 1, wp=[0.9504285453771807, 1.0, 1.0889003707981277])

Convert XYZ tristimulus values to CIE L*a*b*.

Parameters
  • xyz (float array) – XYZ values.

  • axis (int, optional) – The axis of the XYZ values.

  • wp (list of 3 floats, optional) – The XYZ tristimulus values of the whitepoint.

Returns

lab – The L*a*b* colors.

Return type

float array

chaco.color_spaces.xyz2msh(xyz, axis=- 1, wp=[0.9504285453771807, 1.0, 1.0889003707981277])

Convert XYZ tristimulus values to Msh.

Msh is a hemispherical coordinate system derived from L*a*b*. The origin remains the same. M is the distance from the origin. s is an inclination angle from the vertical corresponding to saturation. h is the azimuthal angle corresponding to hue.

Moreland, Kenneth. Diverging Color Maps for Scientific Visualization (Expanded). http://www.sandia.gov/~kmorel/documents/ColorMaps/ColorMapsExpanded.pdf

Parameters
  • xyz (float array) – XYZ values.

  • axis (int, optional) – The axis of the XYZ values.

  • wp (list of 3 floats, optional) – The XYZ tristimulus values of the whitepoint.

Returns

msh – The Msh colors.

Return type

float array

chaco.color_spaces.xyz2rgb(xyz, axis=- 1)

Convert XYZ tristimulus values to linear RGB coordinates.

Parameters
  • xyz (float array) – XYZ values.

  • axis (int, optional) – The axis of the XYZ values.

Returns

rgb – The RGB colors.

Return type

float array

chaco.color_spaces.xyz2srgb(xyz, axis=- 1)

Convert XYZ colors to sR’G’B’.

Parameters
  • xyz (float array) – XYZ values.

  • axis (int, optional) – The axis of the XYZ values.

Returns

srgb – The sR’G’B’ colors.

Return type

float array

chaco.color_spaces.xyz2xyz(xyz)

Identity mapping.