FastSurferCNN.utils.mapper¶
Original Author: David Kuegler.
Date: Aug-19-2022
- class FastSurferCNN.utils.mapper.ColorLookupTable(classes=None, color_palette=None, colormap='gist_ncar', name=None)[source]¶
This class provides utility in creating color palettes from colormaps. It will map from class (see
ColorLookupTable.__init__()) to color/other info.If you want a mapping from the class (typically the labelname to id), see
ColorLookupTable.labelname2index().Attributes
Return the classes.
Return the color palette if it exists.
Return the name of the mapper.
Methods
colormap()Generate a Mapper object that maps classes to their corresponding colors.
get_color_by_index(index[, base])Return the color (r, g, b, a) tuple associated with the index in the passed base.
getitem_by_index(index)Return index, key, colors and additional values for the key.
Return a mapping between the key and the value it is associated with.
Return a mapping between the key and the (consecutive) index it is associated with.
- get_color_by_index(index, base=1.0)[source]¶
Return the color (r, g, b, a) tuple associated with the index in the passed base.
- labelname2id()[source]¶
Return a mapping between the key and the value it is associated with.
- Mapper[KT, Any]
Not implemented in the base class.
- Raises:
RuntimeErrorIf no value is associated.
- labelname2index()[source]¶
Return a mapping between the key and the (consecutive) index it is associated with.
This is the inverse of ColorLookupTable.classes.
- property classes¶
Return the classes.
- property color_palette¶
Return the color palette if it exists.
- property name¶
Return the name of the mapper.
- class FastSurferCNN.utils.mapper.JsonColorLookupTable(file_or_buffer, color_palette=None, colormap='gist_ncar', name=None)[source]¶
This class extends the ColorLookupTable to handle JSON data.
Attributes
classesReturn the classes.
color_paletteReturn the color palette if it exists.
nameReturn the name of the mapper.
Methods
colormap()Generate a Mapper object that maps classes to their corresponding colors.
Converts the labels from the internal data dictionary to a pandas DataFrame.
get_color_by_index(index[, base])Return the color (r, g, b, a) tuple associated with the index in the passed base.
getitem_by_index(index)Return index, key, colors and additional values for the key.
Return a mapping between the key and the value it is associated with.
labelname2index()Return a mapping between the key and the (consecutive) index it is associated with.
- labelname2id()[source]¶
Return a mapping between the key and the value it is associated with.
- Returns:
Mapper[KT,Any]A Mapper object that provides a mapping between label names (keys) and their corresponding IDs (values).
- Raises:
RuntimeErrorIf no value is associated.
- class FastSurferCNN.utils.mapper.Mapper(mappings, name='undefined')[source]¶
Map from one label space to a generic ‘label’-space.
Attributes
Return the max label.
Return the name of the mapper.
Return a set of labels the mapper accepts.
Return the set of labels the mapper converts to as a set of python-natives (if possible), arrays expanded to tuples.
Methods
__call__(label_image)Transform a label image from prediction to the target space.
chain(other_mapper)Chain the current mapper with the
other_mapper.Return, whether the Mapper is bijective.
make_classmapper(mappings[, keep_labels, ...])Map from one label space (int) to another (also int) using a mappings function.
map(image[, out])Forward map the labels from prediction to internal space.
Map dictionary from the target space to the source space.
update(other[, overwrite])Merge another map into this mapper.
map_logits
map_probs
- chain(other_mapper)[source]¶
Chain the current mapper with the
other_mapper.This effectively is an optimization to first applying this mapper and then applying the
other_mapper.- Parameters:
- other_mapper“Mapper[
VT,T_OtherValue]” Mapper mapping from the target-space of this mapper to a new space.
- other_mapper“Mapper[
- Returns:
- Mapper“Mapper[
KT,T_OtherValue]” A mapper mapping from the input space of this mapper to the target-space of the
other_mapper.
- Mapper“Mapper[
- classmethod make_classmapper(mappings, keep_labels=(), compress_out_space=False, name='undefined')[source]¶
Map from one label space (int) to another (also int) using a mappings function.
Can also be used as a transform.
Creates a
Mapperobject from a mappings dictionary and a list of labels to keep.- Parameters:
- mappings
Dict[int,int] A dictionary of labels from -> to mappings.
- keep_labels
Sequence[int] A list of classes to keep after mapping, where all not included classes are not changed (default: empty).
- compress_out_space
bool Whether to reassign labels to reduce the maximum label (default: False).
- name
str Mame for messages (default: “undefined”).
- mappings
- Returns:
- Raises:
ValueErrorIf keep_labels contains an entry > 65535.
- map(image, out=None)[source]¶
Forward map the labels from prediction to internal space.
- Parameters:
- image
AT Data to map to internal space.
- out
Optional[AT] Output array for performance. Returns an
numpy.ndarraywith mapped values. (Default value = None).
- image
- Returns:
ATData after being mapped to the internal space.
- property max_label¶
Return the max label.
- property name¶
Return the name of the mapper.
- property source_space¶
Return a set of labels the mapper accepts.
- property target_space¶
Return the set of labels the mapper converts to as a set of python-natives (if possible), arrays expanded to tuples.
- class FastSurferCNN.utils.mapper.TSVLookupTable(file_or_buffer, name=None, header=None, add_background=True)[source]¶
This class extends the ColorLookupTable to handle TSV (Tab Separated Values) data.
Attributes
classesReturn the classes.
color_paletteReturn the color palette if it exists.
nameReturn the name of the mapper.
Methods
colormap()Generate a Mapper object that maps classes to their corresponding colors.
Return the raw panda data object.
get_color_by_index(index[, base])Return the color (r, g, b, a) tuple associated with the index in the passed base.
getitem_by_index(index)Find the Entry associated by a No.
Return a Mapper between the key and the value it is associated with.
labelname2index()Return a mapping between the key and the (consecutive) index it is associated with.
- getitem_by_index(index)[source]¶
Find the Entry associated by a No.
- Parameters:
- index
int The index Returns a tuple of the index, the label, and a tuple of the RGBA color label.
- index
- Returns:
- labelname2id()[source]¶
Return a Mapper between the key and the value it is associated with.
- Returns:
Mapper[KT,Any]A Mapper object that links keys to their corresponding values based on the class and data index.
- Raises:
RuntimeErrorIf no value is associated.