|
| None | __init__ (self, gui=None) |
| |
| tuple[np.ndarray, np.ndarray, list[tuple[int, int]], tuple[int, int, int], str, tuple[float, float, float], list[tuple[int, int]], str, str] | run (self, str t1, str flair, str temp_dir, bool bet_only=False) |
| |
|
| clean (self, temp_dir) |
| |
| tuple[dict[str, str|None], int, int, list[str]] | find_nii_files (self) |
| |
|
| tuple[np.ndarray, tuple[float, float, float], np.ndarray, tuple[int, int, int]] | _load_img (self, str img_path) |
| |
| np.ndarray | _z_score_norm (self, np.ndarray data, np.ndarray seg=None) |
| |
| str | _bias_correct (self, str img_path, str prefix) |
| |
| tuple[str, str] | _register_to_reference (self, str img_path, str ref, str suffix, str prefix) |
| |
| None | _print_action (self, str action_name) |
| |
| str | _reorient_RAS (self, str img_path, str prefix) |
| |
| np.ndarray | _create_nonzero_mask (self, np.ndarray data) |
| |
| tuple[np.ndarray, np.ndarray, tuple[slice, slice, slice]] | _crop_to_nonzero (self, np.ndarray data, np.ndarray seg=None, int nonzero_label=-1, tuple[slice, slice, slice] bbox=None) |
| |
| tuple[np.ndarray, list[tuple[int, int]]] | _padding (self, np.ndarray data, int min_size=128) |
| |
| tuple[np.ndarray, np.ndarray, list[tuple[int, int]], tuple[int, int, int], str, tuple[float, float, float], list[tuple[int, int]], str] | _preprocess_modality (self, str modality, bool is_MNI, tuple[slice, slice, slice] bbox=None) |
| |
This class performs preprocessing on 3D images
| tuple[np.ndarray, np.ndarray, tuple[slice, slice, slice]] StrokeSegLab.preprocessing.preprocessor.Preprocessor._crop_to_nonzero |
( |
| self, |
|
|
np.ndarray | data, |
|
|
np.ndarray | seg = None, |
|
|
int | nonzero_label = -1, |
|
|
tuple[slice, slice, slice] | bbox = None ) |
|
protected |
@public
Crop the input data and segmentation to the non-zero region. Optionally reuses a provided bounding box (Used to crop the FLAIR image using the same bounding box as the T1 image)
Args:
data (np.ndarray): Input array of shape (c, x, y, z)
seg (np.ndarray, optional): Corresponding segmentation array. Defaults to None.
nonzero_label (int, optional): Label used to mark regions outside the non-zero crop. Defaults to -1.
bbox (tuple[slice, slice, slice], optional): _description_. Defaults to None.
Returns:
tuple[np.ndarray, np.ndarray, tuple[slice, slice, slice]]: Cropped image data, Cropped segmentation mask, Bounding box used for cropping
| tuple[np.ndarray, tuple[float,float,float], np.ndarray, tuple[int,int,int]] StrokeSegLab.preprocessing.preprocessor.Preprocessor._load_img |
( |
| self, |
|
|
str | img_path ) |
|
protected |
@public
Load a NIFTI image from the given file path.
- Load using nibabel
- extract affine matrix and voxel spacing
- extract, transpose and add a channel to data if necessary : (z, y, x) -> (c, x, y, z)
- Store original shape (used later in postprocessing)
Args:
img_path (str): The image path
Returns:
tuple[np.ndarray, tuple[float,float,float], np.ndarray, tuple[int,int,int]]: Data loaded, spacing, affine matrix and the original shape
| tuple[np.ndarray, list[tuple[int, int]]] StrokeSegLab.preprocessing.preprocessor.Preprocessor._padding |
( |
| self, |
|
|
np.ndarray | data, |
|
|
int | min_size = 128 ) |
|
protected |
@public
Pad the data with zeros so that each dimension is at least min_size
If the input data has 4 dimensions and the first dimension (channels) is 1, this dimension is squeezed out before padding and then restored afterwards
The padding is applied symmetrically (half before, half after) on each dimension.
Args:
data (np.ndarray): Input array of shape (c, x, y, z)
min_size (int, optional): Minimum size. Defaults to 128.
Returns:
tuple[np.ndarray, list[tuple[int, int]]]: Padded data, List of tuples indicating how much padding was added before and after each dimension
| tuple[np.ndarray,np.ndarray,list[tuple[int, int]], tuple[int,int,int], str, tuple[float,float,float], list[tuple[int, int]], str] StrokeSegLab.preprocessing.preprocessor.Preprocessor._preprocess_modality |
( |
| self, |
|
|
str | modality, |
|
|
bool | is_MNI, |
|
|
tuple[slice, slice, slice] | bbox = None ) |
|
protected |
@public
Run the full preprocessing pipeline except brain extraction :
- If the image is not already register to MNI : bias correction, reorient to RAS, register to MNI
- Resampling, Z score, padding
Args:
modality (str): Image path
is_MNI (bool): True if the image is already register to MNI
bbox (tuple[slice, slice, slice], optional): Bounding box coordinates used for cropping. Defaults to None.
Returns:
tuple[np.ndarray,np.ndarray,list[tuple[int, int]], tuple[int,int,int], str, tuple[float,float,float], list[tuple[int, int]], str]:
- data preprocessed
- affine matrix
- Bounding box coordinates used for cropping
- Original shape of the image before preprocessing
- Path to the transformation text file
- Voxel spacing of the image
- List of padding tuples applied to each dimension
- Reference MNI image array or None
| np.ndarray StrokeSegLab.preprocessing.preprocessor.Preprocessor._z_score_norm |
( |
| self, |
|
|
np.ndarray | data, |
|
|
np.ndarray | seg = None ) |
|
protected |
@public
Apply z-score normalization to the input data. If a segmentation mask is provided, the normalization is applied only on the region where the mask is non-negative. Otherwise, the entire volume is normalized.
Args:
data (np.ndarray): Input data (c, x, y, z)
seg (np.ndarray, optional): _description_. Defaults to None.
Returns:
np.ndarray: _description_
| tuple[np.ndarray,np.ndarray,list[tuple[int, int]], tuple[int,int,int], str, tuple[float,float,float], list[tuple[int, int]], str, str] StrokeSegLab.preprocessing.preprocessor.Preprocessor.run |
( |
| self, |
|
|
str | t1, |
|
|
str | flair, |
|
|
str | temp_dir, |
|
|
bool | bet_only = False ) |
Run the brain extraction and handle different case : 1 or 2 channels, BET only or not, MNI input or not, save MNI or not
Args:
t1 (str): Path to the T1 image
flair (str): Path to the FLAIR image
temp_dir (str): Path to the temporary directory
bet_only (bool, optional): If True doing brain extraction only. Defaults to False.
Returns:
tuple[np.ndarray,np.ndarray,list[tuple[int, int]], tuple[int,int,int], str, tuple[float,float,float], list[tuple[int, int]], str, str]:
- data preprocessed
- affine matrix
- Bounding box coordinates used for cropping
- Original shape of the image before preprocessing
- Path to the transformation text file
- Voxel spacing of the image
- List of padding tuples applied to each dimension
- Path to the brain-extracted T1 image
- Reference MNI image array or None