Color#

Provides tools for color manipulation.

Note

All numerical color values are by default returned using the range [0,1].

color(arg, alpha=None, as_int=False, int_type=<class 'int'>)[source]#

Converts color arguent to rgb values

Arguments

argobject

Color specifiction, e.g. a rgb tuple, color name from matplotlib or vispy, hex code

alphaNone, bool or float

Include the alpha value in the rgb tuple. If None and an alpha value exists, it is kept, otherwise it is not included. If False the alpha value is not included. If True, the alpha value is included and set to 1 in case its not given in the input.

as_intbool

If True, return colors as integers in range 0 to 255.

Returns

rgblist of float or int

RBG or RGBA values for the colors.

color_map(cmap=None, alpha=True, as_int=False, int_type=<class 'int'>)#

Convert argument to a color map function.

Arguments

cmapNone, string, tuple or list of colors

Color map specification. If a tuple is given a colormap that linearly interpolates is returned.

alphaNone, bool, int or float

Include the alpha value in the color map.

as_intbool

If True return color maps as integers in range 0 to 255.

int_typedtype

The type to use for integer color maps.

Returns

cmapfunction

A color map function that maps floats in [0,1] to a RBG or RGBA tuples.

colormap(cmap=None, alpha=True, as_int=False, int_type=<class 'int'>)[source]#

Convert argument to a color map function.

Arguments

cmapNone, string, tuple or list of colors

Color map specification. If a tuple is given a colormap that linearly interpolates is returned.

alphaNone, bool, int or float

Include the alpha value in the color map.

as_intbool

If True return color maps as integers in range 0 to 255.

int_typedtype

The type to use for integer color maps.

Returns

cmapfunction

A color map function that maps floats in [0,1] to a RBG or RGBA tuples.

darker(arg, fraction=0.3)[source]#
gray_image_to_rgb(image, color_name, pseudo_z_score=False, normalize=False, range_max=None)[source]#

Convert a grayscale image to a colored RGB image.

Parameters: image (numpy.ndarray): The grayscale image to convert. color (str): The color to convert to. Must be one of ‘cyan’, ‘magenta’, ‘yellow’, ‘red’, ‘green’, ‘blue’.

Returns: numpy.ndarray: The converted RGB image.

hex_to_rgb(color, alpha=None, as_int=False)[source]#

Return rgb color from hex code

Arguments

colorstring

Hex code of the color

alphaNone, bool, int or float

Include the alpha value in the rgb tuple. If None the alpha value is included if given in the hex code, if False no alpha value is given, if True the alpha value is included and set to 1 in case its not given in the input.

as_intbool

If True return colors as integers in range 0 to 255.

Returns

rgblist of float or int

RBG or RGBA values for the colors.

lighter(arg, fraction=0.3)[source]#
orientation_to_boys(orientations, alpha=None, as_int=False, normalize=True)[source]#

Colormap mapping 3d orientation vectors into rgb colors.

Arguments

orientationsarray

List of 3d vectors as nx3 array

alphaNone, bool, int or float

Include the alpha value in the color map.

as_intbool

If True return color maps as integers in range 0 to 255.

normalizebool

Normalize vectors to unit length. set to False to avoid overhead when passing normalized vectors.

Returns

colorsarray

RGB colors for the orientation vectors according to Boys coloring.

Note

The Boys color map is a smooth way of coloring orientations.

References

[1] https://ieeexplore.ieee.org/abstract/document/5290761

orientation_to_rgb(orientation, alpha=None, as_int=False)[source]#

Color map mapping 3d orientation vectors into rgb colors using normalized coordinates.

Arguments

orientationsarray

List of 3d vectors as nx3 array.

alphaNone, bool, int or float

Include the alpha value in the color map.

as_intbool

If True return color maps as integers in range 0 to 255.

Returns

colorsarray

RGB colors for the orientation vectors according to standard coloring.

Note

This color map is not continuous.

rand_cmap(n_labels, map_type='bright', first_color_black=True, last_color_black=False, cmap_name='Paired')[source]#

Creates a random colormap to be used together with matplotlib. Useful for segmentation tasks

Arguments

n_labelsint

Number of labels (size of colormap)

map_typestr

‘bright’ for strong colors, ‘soft’ for pastel colors

first_color_blackbool

Option to use first color as black, True or False

last_color_blackbool

Option to use last color as black, True or False

Returns

random_colormaplist of RGB colors

colormap for matplotlib

rgb_LUT()[source]#

Returns a lookup table listing all integer rgb colors

Note

Useful to color data and plot in imagej.

rgb_to_LUT(rgb)[source]#

Converts the rgb colors to the index color in the full rgb color look up table

Arguments

rgbarray

Integer rgb values as nX3 array

Returns

indexarray

The indices of the rgb values in the full rgb LUT.

rgb_to_hex(rgb, alpha=None, as_int=False)[source]#

Return hex code from rgb or rgba colors

Arguments

colortuple of int or float

Hex code of the color

alphaNone, bool or float

Include the alpha value in the rgb tuple

as_intbool

If True return colors as integers in range 0 to 255.

Returns

rgblist of float or int

RBG or RGBA values for the colors.

write_LUT(filename, colors)[source]#

Write a lut lookup table file from a list of colors for use with imagej

Arguments

filenamestr

file name of the lookup table

colorsarray

Colors as nX3 array to write to te ookup table

Returns

filenamestr

Filename of the lookup table.

write_PAL(filename, colors)[source]#

Write a pal pallette file from a list of colors for use with e.g. imaris

Arguments

filenamestr

file name of the lookup table

colorsarray

Colors as nX3 array to write to te ookup table

Returns

filenamestr

Filename of the lookup table.