colormap#

Colormaps module.

cc(na, nd)

Calculate cosine component for Boy's surface.

ss(na, nd)

Calculate sine component for Boy's surface.

boys2rgb(v)

Convert orientation vectors to RGB colors using Boy's Surface.

orient2rgb(v)

Convert orientation vectors to RGB colors based on absolute values.

line_colors(streamlines, *[, cmap])

Create colors for streamlines based on their orientation.

get_cmap(name)

Create a colormap callable similar to matplotlib.pyplot.get_cmap.

create_colormap(v, *[, name, auto])

Create colors from a specific colormap.

distinguishable_colormap(*[, bg, exclude, ...])

Generate colors that are maximally perceptually distinct.

hex_to_rgb(color)

Convert hexadecimal color code to RGB values.

normalize_colors(colors[, n_points])

Normalize colors to float32 arrays in [0, 1] range.

rgb2hsv(rgb)

Convert RGB color values to HSV color space.

hsv2rgb(hsv)

Convert HSV color values to RGB color space.

xyz2rgb(xyz)

Convert XYZ color values to RGB color space.

rgb2xyz(rgb)

Convert RGB color values to XYZ color space.

get_xyz_coords(illuminant, observer)

Get the XYZ coordinates of the given illuminant and observer.

xyz2lab(xyz, *[, illuminant, observer])

Convert XYZ color values to CIE-LAB color space.

lab2xyz(lab, *[, illuminant, observer])

Convert CIE-LAB color values to XYZ color space.

rgb2lab(rgb, *[, illuminant, observer])

Convert from RGB color space to CIE-Lab color space.

lab2rgb(lab, *[, illuminant, observer])

Convert from CIE-Lab color space to RGB color space.

cc#

fury.colormap.cc(na, nd)[source]#

Calculate cosine component for Boy’s surface.

Parameters:
  • na (float) – Amplitude parameter.

  • nd (float) – Angle parameter in degrees.

Returns:

Cosine component value.

Return type:

float

ss#

fury.colormap.ss(na, nd)[source]#

Calculate sine component for Boy’s surface.

Parameters:
  • na (float) – Amplitude parameter.

  • nd (float) – Angle parameter in degrees.

Returns:

Sine component value.

Return type:

float

boys2rgb#

fury.colormap.boys2rgb(v)[source]#

Convert orientation vectors to RGB colors using Boy’s Surface.

Maps a given field of undirected lines (line field) to rgb colors using Boy’s Surface immersion of the real projective plane. Boy’s Surface is one of the three possible surfaces obtained by gluing a Mobius strip to the edge of a disk. The other two are the crosscap and Roman surface, Steiner surfaces that are homeomorphic to the real projective plane (Pinkall 1986). The Boy’s surface is the only 3D immersion of the projective plane without singularities. Visit http://www.cs.brown.edu/~cad/rp2coloring for further details. Cagatay Demiralp, 9/7/2008.

Code was initially in matlab and was rewritten in Python for fury by the FURY Team. Thank you Cagatay for putting this online.

Parameters:

v (array, shape (N, 3) or (3,)) – Unit vectors (e.g., principal eigenvectors of tensor data) representing one of the two directions of the undirected lines in a line field.

Returns:

RGB colors corresponding to the vectors given in v.

Return type:

array, shape (N, 3) or (3,)

Examples

>>> from fury import colormap
>>> v = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
>>> c = colormap.boys2rgb(v)

orient2rgb#

fury.colormap.orient2rgb(v)[source]#

Convert orientation vectors to RGB colors based on absolute values.

Parameters:

v (array, shape (N, 3) or (3,)) – Vectors not necessarily normalized.

Returns:

RGB colors corresponding to the vectors given in v.

Return type:

array, shape (N, 3) or (3,)

Examples

>>> from fury import colormap
>>> v = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
>>> c = colormap.orient2rgb(v)

line_colors#

fury.colormap.line_colors(streamlines, *, cmap='rgb_standard')[source]#

Create colors for streamlines based on their orientation.

Parameters:
  • streamlines (sequence of ndarrays) – Sequence of streamlines, each represented as an ndarray.

  • cmap (str, optional) – Colormap to use, either ‘rgb_standard’ or ‘boys_standard’.

Returns:

Array of colors for each streamline.

Return type:

ndarray

get_cmap#

fury.colormap.get_cmap(name)[source]#

Create a colormap callable similar to matplotlib.pyplot.get_cmap.

Parameters:

name (str) – Name of the colormap.

Returns:

A function that takes values between 0 and 1 and returns RGBA colors.

Return type:

callable

Notes

This function creates a simple colormap function that emulates matplotlib’s behavior for use when matplotlib is not available.

create_colormap#

fury.colormap.create_colormap(v, *, name='plasma', auto=True)[source]#

Create colors from a specific colormap.

Creates an array of shape (N,3) where every row gives the corresponding r,g,b value. The colormaps used are similar to those of matplotlib.

Parameters:
  • v ((N,) array) – Vector of values to be mapped to RGB colors according to colormap.

  • name (str, optional) – Name of the colormap. Currently implemented: ‘jet’, ‘blues’, ‘accent’, ‘bone’ and matplotlib colormaps if matplotlib is installed. For example, we suggest using ‘plasma’, ‘viridis’ or ‘inferno’. Default is ‘plasma’.

  • auto (bool, optional) – If True, v is interpolated to [0, 1] from v.min() to v.max(). Default is True.

Returns:

Array of RGB colors corresponding to the input values.

Return type:

ndarray, shape (N, 3)

Notes

FURY supports a few colormaps for those who do not use Matplotlib, for more colormaps consider downloading Matplotlib (see matplotlib.org).

distinguishable_colormap#

fury.colormap.distinguishable_colormap(*, bg=(0, 0, 0), exclude=None, nb_colors=None)[source]#

Generate colors that are maximally perceptually distinct.

This function generates a set of colors which are distinguishable by reference to the “Lab” color space, which more closely matches human color perception than RGB. Given an initial large list of possible colors, it iteratively chooses the entry in the list that is farthest (in Lab space) from all previously-chosen entries. While this “greedy” algorithm does not yield a global maximum, it is simple and efficient. Moreover, the sequence of colors is consistent no matter how many you request, which facilitates the users’ ability to learn the color order and avoids major changes in the appearance of plots when adding or removing lines.

Parameters:
  • bg (tuple, optional) – Background RGB color, to make sure that your colors are also distinguishable from the background. Default is (0, 0, 0).

  • exclude (list of tuples, optional) – Additional RGB colors to be distinguishable from.

  • nb_colors (int, optional) – Number of colors desired. Default: generate as many colors as needed.

Returns:

If nb_colors is provided, returns a list of RGB colors. Otherwise, yields the next RGB color maximally perceptually distinct from previous ones.

Return type:

iterable of ndarray

Notes

Code was initially in matlab and was rewritten in Python for dipy by the Dipy Team. Thank you Tim Holy for putting this online. Visit http://www.mathworks.com/matlabcentral/fileexchange/29702 for the original implementation (v1.2), 14 Dec 2010 (Updated 07 Feb 2011).

Examples

>>> from fury.colormap import distinguishable_colormap
>>> # Generate 5 colors
>>> _ = [c for i, c in zip(range(5), distinguishable_colormap())]

hex_to_rgb#

fury.colormap.hex_to_rgb(color)[source]#

Convert hexadecimal color code to RGB values.

Parameters:

color (str) – String containing hexcode of color (can also start with a hash).

Returns:

Array of RGB values (between 0 and 1) corresponding to the hexcode.

Return type:

ndarray, shape (3,)

Examples

>>> from fury import colormap
>>> color = "#FFFFFF"
>>> c = colormap.hex_to_rgb(color)
>>>
>>> from fury import colormap
>>> color = "FFFFFF"
>>> c = colormap.hex_to_rgb(color)

normalize_colors#

fury.colormap.normalize_colors(colors, n_points=None)[source]#

Normalize colors to float32 arrays in [0, 1] range.

Accepts colors in multiple formats and converts them to a consistent float32 ndarray with values in [0, 1], suitable for the GPU pipeline.

Parameters:
  • colors (tuple, list, ndarray, str, or None) –

    Input colors. Supported formats:

    • Hex string: "#FF0000" or list of hex strings.

    • Numeric RGB [0, 255]: values > 1.0 are divided by 255.

    • Numeric RGB [0, 1]: float values <= 1.0 pass through.

    • RGBA variants of the above.

    • None: returns default red [[1.0, 0.0, 0.0]].

  • n_points (int, optional) – Expected number of points. If given and a single color is provided, it will be broadcast (tiled) to (n_points, C). If the number of colors doesn’t match n_points and isn’t 1, a ValueError is raised.

Returns:

Normalized colors in [0, 1].

Return type:

ndarray, shape (N, 3) or (N, 4), dtype float32

rgb2hsv#

fury.colormap.rgb2hsv(rgb)[source]#

Convert RGB color values to HSV color space.

Parameters:

rgb (ndarray (..., 3, ...)) – The image in RGB format. By default, the final dimension denotes channels.

Returns:

The image in HSV format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

hsv2rgb#

fury.colormap.hsv2rgb(hsv)[source]#

Convert HSV color values to RGB color space.

Parameters:

hsv (ndarray (..., 3, ...)) – The image in HSV format. By default, the final dimension denotes channels.

Returns:

The image in RGB format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

xyz2rgb#

fury.colormap.xyz2rgb(xyz)[source]#

Convert XYZ color values to RGB color space.

Parameters:

xyz (ndarray (..., 3, ...)) – The image in XYZ format. By default, the final dimension denotes channels.

Returns:

The image in RGB format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

rgb2xyz#

fury.colormap.rgb2xyz(rgb)[source]#

Convert RGB color values to XYZ color space.

Parameters:

rgb ((..., 3, ...) array_like) – The image in RGB format. By default, the final dimension denotes channels.

Returns:

The image in XYZ format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

get_xyz_coords#

fury.colormap.get_xyz_coords(illuminant, observer)[source]#

Get the XYZ coordinates of the given illuminant and observer.

Parameters:
  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}) – The name of the illuminant (the function is NOT case sensitive).

  • observer ({"2", "10", "R"}) – One of: 2-degree observer, 10-degree observer, or ‘R’ observer as in R function grDevices::convertColor.

Returns:

Array with 3 elements containing the XYZ coordinates of the given illuminant.

Return type:

ndarray

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

xyz2lab#

fury.colormap.xyz2lab(xyz, *, illuminant='D65', observer='2')[source]#

Convert XYZ color values to CIE-LAB color space.

Parameters:
  • xyz ((..., 3, ...) array_like) – The image in XYZ format. By default, the final dimension denotes channels.

  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional) – The name of the illuminant (the function is NOT case sensitive). Default is “D65”.

  • observer ({"2", "10", "R"}, optional) – One of: 2-degree observer, 10-degree observer, or ‘R’ observer as in R function grDevices::convertColor. Default is “2”.

Returns:

The image in CIE-LAB format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

lab2xyz#

fury.colormap.lab2xyz(lab, *, illuminant='D65', observer='2')[source]#

Convert CIE-LAB color values to XYZ color space.

Parameters:
  • lab ((..., 3, ...) array_like) – The image in Lab format. By default, the final dimension denotes channels.

  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional) – The name of the illuminant (the function is NOT case-sensitive). Default is “D65”.

  • observer ({"2", "10", "R"}, optional) – The aperture angle of the observer. Default is “2”.

Returns:

The image in XYZ format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

rgb2lab#

fury.colormap.rgb2lab(rgb, *, illuminant='D65', observer='2')[source]#

Convert from RGB color space to CIE-Lab color space.

Converts from the sRGB color space (IEC 61966-2-1:1999) to the CIE Lab colorspace under the given illuminant and observer.

Parameters:
  • rgb ((..., 3, ...) array_like) – The image in RGB format. By default, the final dimension denotes channels.

  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional) – The name of the illuminant (the function is NOT case sensitive). Default is “D65”.

  • observer ({"2", "10", "R"}, optional) – The aperture angle of the observer. Default is “2”.

Returns:

The image in Lab format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.

lab2rgb#

fury.colormap.lab2rgb(lab, *, illuminant='D65', observer='2')[source]#

Convert from CIE-Lab color space to RGB color space.

Parameters:
  • lab ((..., 3, ...) array_like) – The image in Lab format. By default, the final dimension denotes channels.

  • illuminant ({"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional) – The name of the illuminant (the function is NOT case sensitive). Default is “D65”.

  • observer ({"2", "10", "R"}, optional) – The aperture angle of the observer. Default is “2”.

Returns:

The image in RGB format. Same dimensions as input.

Return type:

ndarray (…, 3, …)

Notes

Original Implementation from scikit-image package. It can be found at: scikit-image/scikit-image This implementation might have been modified.