unravel.image_tools.modify_labels module#

Use img_modify_labels (ml) from UNRAVEL to modify specified label IDs in a NIfTI image.

Usage:#

img_modify_labels -i path/image.nii.gz -ids 1 2 3 -o path/image.nii.gz [-val 0] [–retain_IDs] [–binarize] [-v]

unravel.image_tools.modify_labels.parse_args()[source]#
unravel.image_tools.modify_labels.set_labels(img, label_IDs, value=0)[source]#

Set specified label IDs in the ndarray to a given value.

Parameters:
  • img (ndarray) – The input image as a numpy ndarray.

  • label_IDs (list of int) – The label IDs to set to a specific value.

  • value (int) – The intensity to set for specified label IDs (default: 0).

Returns:

The modified image with specified label IDs set to the given value.

Return type:

ndarray

unravel.image_tools.modify_labels.retain_labels(img, label_IDs, omit_value=0)[source]#

Retain only specified label IDs in the image, setting others to omit_value.

Parameters:
  • img (ndarray) – The input image as a numpy ndarray.

  • label_IDs (list of int) – The label IDs to retain.

  • omit_value (int) – The intensity to set for labels not in label_IDs (default: 0).

Returns:

The modified image with only the specified label IDs retained.

Return type:

ndarray

unravel.image_tools.modify_labels.main()[source]#