combine_regions_as_mask#

petpal.preproc.segmentation_tools.combine_regions_as_mask(segmentation_img: ants.core.ANTsImage | numpy.ndarray, label: int | list[int]) ants.core.ANTsImage#

Create a mask from a segmentation image and one or more labels.

If just one label is provided, this function will return a mask where values are 1 at voxels equal to that label, and 0 elsewhere. If the labels provided are in a list, the mask will be 1 at voxels in the segmentation that are equal to any of the provided values, and zero elsewhere.

Parameters:
  • segmentation_img (ants.core.ANTsImage | np.ndarray) – Image or array of brain regions.

  • label (int | list[int]) – Label or labels to mask the segmentation with.

Returns:

mask (ants.core.ANTsImage | np.ndarray)

Image or array of mask on the provided labels.

Output type matches the type used in segmentation_img.

Example

import ants

from petpal.preproc.segmentation_tools import combine_regions_as_mask

# Load the image
seg_img = ants.image_read('/path/to/seg.nii.gz')

# If the segmentation is FreeSurfer aparc+aseg, then region 12 is the Right Putamen
right_putamen = combine_regions_as_mask(segmentation_img = seg_img, label=12)

# If we want a mask of both the right and left putamen, use regions 12 and 51
whole_putamen = combine_regions_as_mask(segmentation_img = seg_img, label=[12, 51])