imagecat.color module

Functionality for color mapping and colorspace conversion.

class imagecat.color.Palette(colors, reverse=False)[source]

Bases: object

Storage for an ordered collection of colors.

A palette is an ordered collection of colors. Typically, palettes are used to define color mappings.

See also

srgb_to_linear()

Useful for converting colors from other sources into linear space.

Parameters
  • colors (numpy.ndarray, required) – \(M \times N\) matrix containing \(M\) colors with \(N\) channels each. Note that while three channels for colors is typical, any number of channels is allowed. The color channels must be in linear space, not sRGB.

  • reverse (boolean, optional) – If True, reverse the order of colors.

property colors

Color data stored by this palette.

Returns

\(M \times N\) matrix containing \(M\) colors with \(N\) channels each.

Return type

numpy.ndarray

imagecat.color.categorical_map(data, palette)[source]

Convert scalar data to color data using a categorical map.

Integer input values will be used to lookup colors in palette. Modulo arithmetic ensures that colors are repeated for negative or out-of-bound colors. Floating point values are truncated using “floor” prior to lookup.

Parameters
  • data (numpy.ndarray, required) – The data to be mapped.

  • palette (Palette, required) – The palette of colors to use for the categorical mapping.

Returns

mapped – Mapped data with the same shape as data, but an extra dimension added.

Return type

numpy.ndarray

imagecat.color.linear_map(data, palette, min=None, max=None)[source]

Convert scalar data to color data using a linear map.

Input values between min and max will be linearly mapped to the colors in palette. If min or max are None, the corresponding value will be computed from the data.

Parameters
  • data (numpy.ndarray, required) – The data to be mapped.

  • palette (Palette, required) – The palette of colors to use for the linear mapping.

  • min (number, optional) – If None (the default) uses the minimum value in data.

  • max (number, optional) – If None (the default) uses the maximum value in data.

Returns

mapped – Mapped data with the same shape as data, but an extra dimension added.

Return type

numpy.ndarray

imagecat.color.linear_to_srgb(data)[source]

Convert linear color data to sRGB.

Acessed from https://entropymine.com/imageworsener/srgbformula

Parameters

data (numpy.ndarray, required) – Array of any shape containing linear data to be converted to sRGB.

Returns

converted – Array with the same shape as data containing values in sRGB space.

Return type

numpy.ndarray

imagecat.color.srgb_to_linear(data)[source]

Convert sRGB data to linear color.

Acessed from https://entropymine.com/imageworsener/srgbformula

Parameters

data (numpy.ndarray, required) – Array of any shape containing sRGB data to be converted to linear.

Returns

converted – Array with the same shape as data containing values in linear space.

Return type

numpy.ndarray