Extracting Color Coordinates

Description

Allows to extract the current values of one or multiple dimensions for all colors of this color object. The names of the coordinates varies between different color spaces.

Usage

HLS.get(dimname=None)

Arguments

dimnameNone, str
If None (default) values of all coordinates of the current color object are returned. A specific coordinate can be specified if needed.

Return

Returns a numpy.ndarray if coordinates of one specific dimension are requested, else a dict of arrays.

Examples

from colorspace import HCL, sRGB, hexcols
# Example using HCL color object with alpha channel
cols = HCL([260, 80, 30], [80, 0, 80], [30, 90, 30], [1, 0.6, 0.2])
cols.get("H") # Specific dimension
array([260.,  80.,  30.])
cols.get("alpha") # Alpha (if existing)
array([1. , 0.6, 0.2])
cols.get() # All dimensions
{'H': array([260.,  80.,  30.]),
 'C': array([80.,  0., 80.]),
 'L': array([30., 90., 30.]),
 'alpha': array([1. , 0.6, 0.2])}
# Convert colors to sRGB
cols.to("sRGB")
cols.get("R") # Specific dimension
array([0.00691302, 0.88757039, 0.49625787])
cols.get() # All dimensions
{'R': array([0.00691302, 0.88757039, 0.49625787]),
 'G': array([0.24577258, 0.8875635 , 0.17895641]),
 'B': array([ 0.64603426,  0.88759885, -0.30114778]),
 'alpha': array([1. , 0.6, 0.2])}
# Convert to hexcols
cols.to("hex")
cols.get("hex_")
array(['#023FA5', '#E2E2E2', '#7F2E00'], dtype='<U7')

Raises

  • TypeError: If argument dimname is neither None or str.
  • ValueError: If the dimension specified on dimnames does not exist.