BrainData¶
Class containing all image manipulation tools for nifti images.
Paint4Brains Data Manipulation
This script contains the main functions required for manipulating the data required by the software. Data manipulation includes loading the data, performing any required pre-processing, selecting data and label slices, and manipulating information. This file consists of several functions. Please check individual documentations for particular infomration.
- Usage:
To use this module, import it and instantiate is as you wish:
from Paint4Brains.BrainData import BrainData
-
class
Paint4Brains.BrainData.BrainData(filename, label_filename=None)¶ BrainData class for Paint4Brains.
This class contains the main functions required for manipulating the data required by the software.
- Args:
- filename (str): Path leading to the location of the brain data file. label_filename (str): Path to the location of the labeled data file.
-
current_data_slice¶ Returns the current data slice of the brain
Function returning the 2D slice of the brain input, using the get_data_slice function.
- Returns:
- list: 2-D image representing the view of the brain at the self.i slice from the self.section axis
-
current_label¶ Current Label Values
Returns the value of the label currently being edited
- Returns:
- int: Value of label currently being edited
-
current_label_data_slice¶ Returns the current data slice of the label being currently edited
Function calling the get_label_data_slice to return the current data slice of the label currently being edited.
- Returns:
- list: 2-D image representing the view of the label being currently edited at the self.i slice from the self.section axis
-
current_other_labels_data_slice¶ Returns the current data slice of all labels
- Returns:
- list: 2-D image representing the view of all labels at the self.i slice from the self.section axis
-
extract()¶ Brain Extraction
Function which performs brain extraction/skull stripping on nifti images. To run extraction, this function uses the deepbrain neural network.
-
full_brain()¶ Brain & Head Images
This function returns the image to the original brain with the head image It also returns the background image to the unextracted brain.
-
get_data_slice(i)¶ Function returning the 2D MRI slice for a given point
This function Returns the 2-D slice at point i of the full MRI data (not labels). Depending on the desired view (self.section) it returns a different 2-D slice of the 3-D data. A number of transposes and flips are done to return the 2_D image with a sensible orientation.
- Args:
- i (int): Index point, indicating the desired location where the 2D slice is to be sampled.
- Returns:
- list: 2D slice at point i of the full MRI data
-
get_label_data_slice(i)¶ Returns the 2-D slice at point i of the labelled data.
Depending on the desired view (self.section) it returns 2-D slice with respect to a different axis of the 3-D data. A number of transposes and flips are done to return the 2_D image with a sensible orientation.
- Args:
- i (int): Index point, indicating the desired location where the 2D slice is to be sampled.
- Returns:
- list: 2-D slice at point i of the labelled data
-
get_other_labels_data_slice(i)¶ Returns the 2-D slice at point i of all labelled data.
Depending on the desired view (self.section) it returns 2-D slice with respect to a different axis of the 3-D data. A number of transposes and flips are done to return the 2_D image with a sensible orientation
- Args:
- i (int): Index point, indicating the desired location where the 2D slice is to be sampled.
- Returns:
- list: 2-D slice at point i of all labelled data
-
load_label_data(filename)¶ Segmentation labels loader
Loads a .nii file representing the segmentation labels into the BrainData class. It can deal with binary labels or multiple labels. If there were any previous labels loaded, it deletes them. It assumes the niifti file for the labels is oriented in the same as the niifti file for the original brain. However, it does not assume that the header stored in the file has been updated.
- Args:
- filename (str): Path of the file to load into the GUI
-
log_normalization()¶ Logarithmic Normalization
A Method that performs a logarithmic normalization on the brain
-
position_as_voxel(mouse_x, mouse_y)¶ 3D Mouse Position
Returns the 3-D position of the mouse with respect to the brain
- Args:
- mouse_x (int): Position of the mouse in the x axis mouse_y (int): Position of the mouse in the y axis
- Returns:
- tuple: 3-D position of the mouse (in voxels)
-
reorient(target_axcoords=('L', 'A', 'S'))¶ Image Reorientation
Function to perform reorientation of image axis in the coronol, saggital and axial planes.
- Args:
- target_axcoords (list): List of target output axis orientations, represented as strings corresponding to the axial (A), saggital (S) and coronal (L) planes.
-
save_label_data(saving_filename)¶ Label Data Saver
Saves the labeled data currently being edited into a niifti file. It currently does not save the header. TODO: If required, add the header saver capability.
- Args:
- saving_filename (str): Name of the file to be saved as
-
segment(device)¶ Brain Segmenter
This function calls the Segmenter file to perform brain segmentation.
- Args:
- device (str/int): Device to run the neural network on, can be “cpu” or cuda-enabled GPU (“gpu”).
-
store_edit()¶ Function that stores previous edits.
This list of edits are then used by the undo and redo functions.
-
voxel_as_position(i, j, k)¶ 2D Mouse Position
Returns the 2-D position of the mouse from the 3-D position of the Brain
- Args:
- i (int): Brain voxel position on x-axis j (int): Brain voxel position on y-axis k (int) :Brain voxel position on z-axis
- Returns:
- tuple: 2-D position of the mouse