apply_mask_4d#
- petpal.preproc.regional_tac_extraction.apply_mask_4d(input_arr: numpy.ndarray, mask_arr: numpy.ndarray, verbose: bool = False) numpy.ndarray#
Function to extract ROI voxel tacs from an array using a mask array.
This function applies a 3D mask to a 4D image, returning the time series for each voxel in a single flattened numpy array.
- Parameters:
input_arr (np.ndarray) – Input 4D-image from which to extract ROI voxel tacs.
mask_arr (np.ndarray) – Mask image which determines which voxels to extract.
verbose (bool, optional) – If True, prints information about the shape of extracted voxel tacs.
- Returns:
out_voxels (np.ndarray) – Time series of each voxel in the mask, as a flattened numpy array.
- Raises:
AssertionError – If input array is not 4D.
AssertionError – If input and mask array shapes are mismatched.
Example
import ants import numpy as np from petpal.preproc.regional_tac_extraction import apply_mask_4d # Read images pet_img = ants.image_read("/path/to/pet.nii.gz") masked_region_img = ants.image_read("/path/to/mask_region.nii.gz") # Get underlying arrays pet_arr = pet_img.numpy() masked_region_arr = masked_region_img.numpy() # Run ROI extraction and save time_series = apply_mask_4d(input_arr=pet_arr, mask_arr=masked_region_arr).T np.savetxt("time_series.tsv", time_series, delimiter=' ')