transformation
ðŸ§
Functions to transform MRIs.
Author: Simon M. Hofmann
Years: 2023-2024
apply_mask
ðŸ§
apply_mask(data: ndarray, mask: ndarray) -> ndarray
Apply volume mask to data.
Data and the corresponding mask must have the same shape.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
Data to be masked. |
required |
mask |
ndarray
|
Mask to be applied. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Masked data. |
Source code in src/xai4mri/dataloader/transformation.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
clip_data
ðŸ§
clip_data(
data: ndarray, at_percentile: float = CLIP_PERCENTILE
) -> ndarray
Clip provided data at a certain intensity percentile as the clipping threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
Data to be clipped. |
required |
at_percentile |
float
|
Percentile of the upper bound. |
CLIP_PERCENTILE
|
Returns:
Type | Description |
---|---|
ndarray
|
Clipped data. |
Source code in src/xai4mri/dataloader/transformation.py
173 174 175 176 177 178 179 180 181 182 |
|
compress_and_norm
ðŸ§
compress_and_norm(
data: ndarray,
clip_min: float | int | None,
clip_max: float | int | None,
norm: bool | None,
global_norm_min: float | int | None,
global_norm_max: float | int | None,
) -> ndarray
Clip, normalize, and/or compress data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
Data to be processed. |
required |
clip_min |
float | int | None
|
Minimum clip value. |
required |
clip_max |
float | int | None
|
Maximum clip value. |
required |
norm |
bool | None
|
Whether to normalize data. |
required |
global_norm_min |
float | int | None
|
Global minimum value for normalization (usually if data is part of bigger dataset). |
required |
global_norm_max |
float | int | None
|
Global maximum value for normalization (usually if data is part of bigger dataset). |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Processed data. |
Source code in src/xai4mri/dataloader/transformation.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
determine_min_max_clip
ðŸ§
determine_min_max_clip(
data: ndarray, at_percentile: float = CLIP_PERCENTILE
) -> tuple[float, float]
Determine the min and max clip value for the given data.
This clips the data at the given percentile. That is, all values below the min clip value are set to the min clip value, and all values above the max clip value are set to the max clip value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
data as numpy array |
required |
at_percentile |
float
|
percentile of the upperbound |
CLIP_PERCENTILE
|
Returns:
Type | Description |
---|---|
tuple[float, float]
|
min and max clipping values |
Source code in src/xai4mri/dataloader/transformation.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
file_to_ref_orientation
ðŸ§
file_to_ref_orientation(
image_file: Nifti1Image,
reference_space: str = GLOBAL_ORIENTATION_SPACE,
) -> Nifti1Image
Take a Nibabel NIfTI-file (not array) and return it reoriented to the (global) reference orientation space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_file |
Nifti1Image
|
NIfTI image file. |
required |
reference_space |
str
|
Reference orientation space. For example, 'LIA' (default) or 'RSP' (as in |
GLOBAL_ORIENTATION_SPACE
|
Returns:
Type | Description |
---|---|
Nifti1Image
|
reoriented NIfTI image. |
Source code in src/xai4mri/dataloader/transformation.py
58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
get_orientation_transform
ðŸ§
get_orientation_transform(
affine: ndarray,
reference_space: str = GLOBAL_ORIENTATION_SPACE,
) -> Nifti1Image
Get the orientation transform from a given affine matrix to the reference space.
The resulting orientation transform (orient_trans
) can be used to reorient an MRI to a reference space:
nibabel_image_file.as_reoriented(orient_trans)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
affine |
ndarray
|
affine matrix |
required |
reference_space |
str
|
reference space |
GLOBAL_ORIENTATION_SPACE
|
Returns:
Type | Description |
---|---|
Nifti1Image
|
orientation transform |
Source code in src/xai4mri/dataloader/transformation.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
mri_to_ref_orientation
ðŸ§
mri_to_ref_orientation(
image: ndarray,
affine: ndarray,
reference_space: str = GLOBAL_ORIENTATION_SPACE,
) -> ndarray
Reorient an MRI array to a reference orientation space.
Take an MRI array plus its corresponding affine matrix and return the MRI reoriented to the (global) reference space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
ndarray
|
MRI array. |
required |
affine |
ndarray
|
Corresponding affine matrix of the MRI array. |
required |
reference_space |
str
|
Reference orientation space. For example, 'LIA' (default) or 'RSP' (as in |
GLOBAL_ORIENTATION_SPACE
|
Returns:
Type | Description |
---|---|
ndarray
|
reoriented MRI array. |
Source code in src/xai4mri/dataloader/transformation.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
save_ants_warpers
ðŸ§
Save warper files from ANTsPy
's tx
object to the given folder_path
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tx |
dict[str, Any]
|
|
required |
folder_path |
str | Path
|
folder path to save warper files |
required |
image_name |
str
|
Image name that will be used as prefix for the warper files. |
required |
Source code in src/xai4mri/dataloader/transformation.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|