neurite.py.utils
Python utilities for neurite.
fs_lut_to_cmap
convert a freesurfer LUT to a matplotlib colormap.
example lut = ne.py.utils.load_fs_lut('/path/to/seg32_labels.lut') fs_cmap = ne.py.utils.fs_lut_to_cmap(lut)
Args: lut (dict/str): string (path to LUT file) or dict with keys being integers (label ids), and each value should be a dictionary with the key 'color' which is a list with 3 elements, the RGB colors (0 to 255)
Returns: matplotlib ListedColormap: [description]
Source code in neurite/py/utils.py
load_fs_lut
Reads a label lookup-table from file. File is expected to define the anatomical name and color for each label ID. Each line in the file should have the format:
Parameters: filename (str): File to load. Returns: dict: Label lookup dictionary.
Source code in neurite/py/utils.py
normalize_axes
Normalize and validate axes indexing into an N-dimensional (ND) tensor shape. Specifically, the function sorts and deduplicates indices. It normalizes (valid) negative indices into the interval [0, N) and raises an error if they are outside an allowed range.
Parameters:
axes: Axis index inputs, as a Python integer, iterable, or None. None means all allowed
axes or no axis, depending on none_means_all.
shape: Shape of the array or tensor to index into.
allowed: Subset of allowed axes in [0, N). Python integer, iterable, or None. None means
all axes compatible with shape are allowed axes.
none_means_all: Replace an input of axes=None with all axes in [0, N). If False,
axes=None will return an empty tuple.
Returns: The set of specified axes normalized into [0, N) as a tuple.
Source code in neurite/py/utils.py
rebase_lab
Rebase labels and return lookup table (LUT) to convert to new labels in interval [0, N[ as: LUT[label_map]. Be sure to pass all possible labels.
Source code in neurite/py/utils.py
seg_to_rgb_fs_lut
Converts a hard segmentation into an RGB color image given a freesurfer-style label lookup-table dictionary.
Parameters: seg (ndarray): Hard segmentation array. label_table (dict): Label lookup. Returns: ndarray: RGB (3-frame) image with shape of input seg.