pycolorbar.colors package#

Submodules#

pycolorbar.colors.colors_io module#

Color encoding and decoding functions.

class pycolorbar.colors.colors_io.CIELABEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding CIE LAB color values.

This class handles the conversion between external and internal CIELAB color values.

External data range: Luminance (0-100), A (-128,127), B (-128, 127) Internal data range: Luminance (0-1), A (-1,1), B (-1,1)

Note: A and B can theoretically range from -128 to +127 but practical ranges are smaller.

class pycolorbar.colors.colors_io.CIELUVEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding CIE LUV color values.

This class handles the conversion between external and internal LUV color values.

External data range: Luminance (0-100), U (-100,100), V (-100, 100) Internal data range: Luminance (0-1), U (-1,1), V (-1,1)

U* and V* can theoretically range from -100 to +100 but practical ranges are smaller. The u and v coordinates measure positions on green/red and blue/yellow axes.

class pycolorbar.colors.colors_io.CIEXYZEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding CIE XYZ color values.

This class handles the conversion between external and internal CIE XYZ color values.

External data range: X (0-100), Y (0-100), Z (0-100) Internal data range: X (0-1), Y (0-1), Z (0-1)

class pycolorbar.colors.colors_io.CMYKEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding CMYK color values.

This class handles the conversion between external and internal CMYK color values.

External data range: Cyan (0-100), Magenta (0-100), Yellow (0-100) Key/Black (0-100) Internal data range: Cyan (0-1), Magenta (0-1), Yellow (0-1) Key/Black (0-1)

class pycolorbar.colors.colors_io.ColorEncoderDecoder(external_data_range, internal_data_range, name)[source]#

Bases: object

Base Color Encoding-Decoding Class.

check_colors(colors)[source]#

Check colors array dimension, size and type validity.

Parameters

colors (np.ndarray) – 2D array where each column represents a channel in the color space.

Returns

colors – 2D array where each column represents a channel in the color space.

Return type

np.ndarray

check_valid_external_data_range(colors, strict=False)[source]#

Check if the color values are within the external data range for each channel.

Raises an informative ValueError if a channel does not comply with the data range. If ‘strict’ is True, it ensures that not all values are within the internal data range.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • strict (bool, optional) – If True, performs a strict check to ensure that the values are within the external data range and not within the internal data range. Default is False.

Raises

ValueError – If any channel values are not within the external data range or, if ‘strict’ is True, that not all channel values are also within the internal data range.

check_valid_internal_data_range(colors)[source]#

Check if the color values are within the internal data range for each channel.

Raises an informative ValueError if a channel does not comply with the data range.

Parameters

colors (np.ndarray) – 2D array where each column represents a channel in the color space.

Raises

ValueError – If any channel values are not within the internal data range.

decode(colors)[source]#

Decode color values from external to internal representation.

Parameters

colors (np.ndarray) – 2D array where each column represents a channel in the color space.

Returns

Decoded color values in internal representation.

Return type

np.ndarray

encode(colors)[source]#

Encode color values from internal to external representation.

Parameters

colors (np.ndarray) – 2D array where each column represents a channel in the color space.

Returns

Encoded color values in external representation.

Return type

np.ndarray

is_within_external_data_range(colors, strict: bool = False)[source]#

Check if the color values of each channels are within the external data range.

Optionally, perform a strict check to ensure that not all values are also within the internal data range.

Parameters
  • colors (np.array) – 2D array where each column represents a channel in the color space.

  • strict (bool, optional) – If True, performs a check to ensure that not all values are also within the internal data range. Default is False.

Returns

If strict=False, True if all channel values are within the external data range, False otherwise. If strict=True, True if all channels values are within the external data range and not also all inside the internal data range, False otherwise.

Return type

bool

is_within_internal_data_range(colors)[source]#

Check if the color values are within the internal data range for each channel.

Parameters

colors (np.array) – 2D-Array with the columns representing the color space dimensions.

Returns

True if all channel values are within the internal data range, False otherwise.

Return type

bool

class pycolorbar.colors.colors_io.HCLEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding HCL color values.

The color space is also known as PolarLUV or cylindrical transformations of the CIELUV (CIELChuv)

HCL rearrange the two CIELUV U and V chroma values into chroma (C) and hue (h). The CIELUV coordinate L* (luminance) remains unchanged.

This class handles the conversion between external and internal HCL color values.

External data range: Hue (0-255), Chroma (0-255), Luminance (0-255) Internal data range: Hue (0-1), Chroma (0-1), Luminance (0-1)

class pycolorbar.colors.colors_io.HSVEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding HSV (also called HSB) color values.

This class handles the conversion between external and internal HSV color values.

External data range: Hue (0-360), Saturation (0-100), Value (0-100) Internal data range: Hue (0-2π), Saturation (0-1), Value (0-1)

The Hue channel requires special handling for the conversion between degrees and radians.

class pycolorbar.colors.colors_io.LCHEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding LCH color values.

The color space is also known as PolarLAB or cylindrical transformations of the CIELAB (CIELChab)

LCH rearrange the two CIELAB A and B chroma values into chroma (C) and hue (h). The CIELAB coordinate L* (luminance) remains unchanged.

This class handles the conversion between external and internal LCh color values.

External data range: Luminance (0-100), Chroma (0-200), Hue (0-360) Internal data range: Luminance (0-1), Chroma (0-2), Hue (0-2π)

The Hue channel requires special handling for the conversion between degrees and radians.

class pycolorbar.colors.colors_io.RGBAEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding RGBA color values.

This class handles the conversion between external and internal RGB color values.

External data range: R (0-255), G (0-255), B (0-255), A (0-100) Internal data ranges: R (0-1), G (0-1), B (0-1), A (0-1)

class pycolorbar.colors.colors_io.RGBEncoderDecoder[source]#

Bases: ColorEncoderDecoder

A class for encoding and decoding RGB color values.

This class handles the conversion between external and internal RGB color values.

External data range: R (0-255), G (0-255), B (0-255) Internal data ranges: R (0-1), G (0-1), B (0-1)

pycolorbar.colors.colors_io.check_valid_external_data_range(colors, color_space, strict=False)[source]#

Check if the color values are within the external data range for each channel.

Raises an informative ValueError if a channel does not comply with the data range. If ‘strict’ is True, it ensures that not all values are within the internal data range.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • color_space (str) – The name of the color space.

  • strict (bool, optional) – If True, performs a strict check to ensure that the values are within the external data range and not within the internal data range. Default is False.

Raises

ValueError – If any channel values are not within the external data range or, if ‘strict’ is True, that not all channel values are also within the internal data range.

pycolorbar.colors.colors_io.check_valid_internal_data_range(colors, color_space)[source]#

Check if the color values are within the internal data range for the specified color space.

Raises an informative ValueError if a channel does not comply with the data range.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • color_space (str) – The name of the color space.

Raises

ValueError – If any channel values are not within the internal data range.

pycolorbar.colors.colors_io.decode_colors(colors, color_space)[source]#

Decode colors from external to internal representation for the specified color space.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • color_space (str) – The name of the color space.

Returns

Decoded color values in internal representation.

Return type

np.ndarray

pycolorbar.colors.colors_io.encode_colors(colors, color_space)[source]#

Encode colors from internal to external representation for the specified color space.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • color_space (str) – The name of the color space.

Returns

Encoded color values in external representation.

Return type

np.ndarray

pycolorbar.colors.colors_io.get_color_space_class(color_space)[source]#

Retrieve the class associated with the specified color space.

Parameters

color_space (str) – The name of the color space. Valid color spaces are ‘RGB’, ‘RGBA’, ‘HSV’, ‘LCH’, ‘HCL’, ‘CIELUV’, ‘CIELAB’, ‘CIEXYZ’, ‘CMYK’.

Returns

The class corresponding to the specified color space.

Return type

class

pycolorbar.colors.colors_io.is_within_external_data_range(colors, color_space, strict=False)[source]#

Check if the color values are within the external data range for the specified color space.

Optionally, perform a strict check to ensure that not all values are also within the internal data range.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • color_space (str) – The name of the color space.

  • strict (bool, optional) – If True, performs a check to ensure that not all values are also within the internal data range. Default is False.

Returns

True if all channel values are within the external data range (and, if strict is True, not within the internal data range), False otherwise.

Return type

bool

pycolorbar.colors.colors_io.is_within_internal_data_range(colors, color_space)[source]#

Check if the color values are within the internal data range for the specified color space.

Parameters
  • colors (np.ndarray) – 2D array where each column represents a channel in the color space.

  • color_space (str) – The name of the color space.

Returns

True if all channel values are within the internal data range, False otherwise.

Return type

bool

Module contents#