fsl.data.volumelabels

This module provides the VolumeLabels class, which is used to manage labels associated with the volumes of an Image. This class is primarily used for managing component classifications of a MelodicImage.

See also the fixlabels() module for loading/saving melodic label files.

class fsl.data.volumelabels.VolumeLabels(nvolumes)

Bases: fsl.utils.notifier.Notifier

The VolumeLabels class is a convenience class for managing a collection of classification labels for the volumes of an Image.

The VolumeLabels class refers to volumes as components, because it was originally written to manage classification labels associated wirh the components of a Melodic analysis.

The following methods are available on a VolumeLabels instance:

clear Removes all labels from all components.
load Loads component labels from the specified file.
save Saves the component classifications stored by this VolumeLabels instance to the specified file.
numComponents Returns the number of components (a.k.a.
hasLabel Returns True if the specified component has the specified label, False otherwise.
hasComponent Returns True if the given compoennt has the given label, False otherwise.
getLabels Returns all labels of the specified component.
getAllLabels Returns all labels that are currently associated with any component.
getDisplayLabel Returns the display name for the given label.
getComponents Returns a list of all components which have the given label.
addLabel Adds the given label to the given component.
addComponent Adds the given label to the given component.
removeLabel Removes the given label from the given component.
removeComponent Removes the given label from the given component.
clearLabels Removes all labels from the given component.
clearComponents Removes the given label from all components.

The VolumeLabels class uses the Notifier interface to notify listeners about changes to the labels. Listeners can be registered to be notified on the following topics:

  • added: A new label was added to a component.
  • removed: A label was removed from a component.

When either of these events occur, the value passed to registered listeners will contain a list of (component, label)) tuples, which specify the labels that were added/removed.

Note

All component labels are internally stored as lower case; however, their cased version (whatever is initially used) is accessible via the getDisplayLabel() method.

numComponents()

Returns the number of components (a.k.a. volumes) that this VolumeLabels instance is managing.

getDisplayLabel(label)

Returns the display name for the given label.

clear()

Removes all labels from all components.

load(filename)

Loads component labels from the specified file. See the fixlabels.loadLabelFile() function.

Note

This method adds to, but does not replace, any existing component classifications stored by this VolumeLabels instance. Call the clear() method, before calling load, if you want to discard any existing classifications.

save(filename, dirname=None)

Saves the component classifications stored by this VolumeLabels instance to the specified file. See the fixlabels.saveLabelFile() function.

getLabels(component)

Returns all labels of the specified component.

getAllLabels()

Returns all labels that are currently associated with any component.

hasLabel(component, label)

Returns True if the specified component has the specified label, False otherwise.

addLabel(component, label, notify=True)

Adds the given label to the given component.

Parameters:notify – If True (the default), the Notifier.notify() method will be called, with the 'added' topic. This parameter is only intended for uses interal to the VolumeLabels class.
Returns:True if the label was added, False if the label was already present.
removeLabel(component, label, notify=True)

Removes the given label from the given component.

Returns:True if the label was removed, False if the component did not have this label.
clearLabels(component)

Removes all labels from the given component.

getComponents(label)

Returns a list of all components which have the given label.

hasComponent(label, component)

Returns True if the given compoennt has the given label, False otherwise.

addComponent(label, component)

Adds the given label to the given component.

removeComponent(label, component, notify=True)

Removes the given label from the given component.

clearComponents(label)

Removes the given label from all components.