Segmenter

Paint4Brains Segmenter

This file contains the relevant functions for producing the segmented labeled brains, a core function of the Paint4Brains Software. The functions and methods in this file were extracted from the several files associated with the original QuickNAT implementation.

Attributes:
label_names (list): List of all labels corresponding to the different regions that QuickNAT is able to segment. new_affine (np.array): Homogenous affine giving relationship between voxel coordinates and world coordinates for the segmented files.
Usage:

To use this module, import it and instantiate is as you wish:

from Paint4Brains.Segmenter import Segmenter segmentation_operation = Segmenter(parameters) segmentation_operation.segment(file_path)
class Paint4Brains.Segmenter.Segmenter(device='cpu', coronal_model_path=None, axial_model_path=None)

Segmenter class for Paint4Brains.

This class contains the main segmentation functions required for performing the segmentation operation.

Args:
coronal_model_path (str): Path to the pre-trained coronal QuickNAT model axial_model_path (str): Path to the pre-trained axial QuickNAT model device (int/str): Device type used for training (int - GPU id, str- CPU)
Returns:
filename (str): The file name of the outputted segmentation file.
segment(file_path)

Main Segmentation Operation

This function combines the segmentations from both axis to obtain the final result

Args:
file_path (str): Path to the desired input brain file
Returns:
filename (str): The file name of the outputted segmentation file.
Paint4Brains.Segmenter.load_and_preprocess(file_path, orientation)

Load & Preprocess

This function is composed of two other function calls: one that calls a function loading the data, and another which preprocesses the data to the required format. # TODO: Need to check if any more preprocessing would be required besides summing the tracts!

Args:
file_paths (list): List containing the input data and target labelled output data orientation (str): String detailing the current view (COR, SAG, AXL)
Returns:
volume (np.array): Array of training image data of data type dtype. header (class): ‘nibabel.nifti1.Nifti1Header’ class object, containing image metadata original (class): ‘nibabel.nifti1.Nifti1Image’ class object, containing the original input volume
Paint4Brains.Segmenter.transform(image)

Conformation Function

This function takes a brain extracted image and conforms it to [256, 256, 256] and 1 mm^3 voxel size just like Freesurfer’s mri_conform function

Args:
image (Nifti1Image): Input image to be conformed.
Returns:
transformed_image (Nifti1Image): Conformed image.
Paint4Brains.Segmenter.undo_transform(mask, original)

Undo transforation

Function which reverts a previously performed transformation.

Args:
mask (Nifti1Image): Image to be reverted to a previous state original (Nifti1Image): The original model which serves as a reference
Returns:
new_mask (Nifti1Image): The reverted image