asldro.utils package¶
Submodules¶
asldro.utils.example_resampling module¶
asldro.utils.general module¶
General utilities
-
asldro.utils.general.
map_dict
(input_dict: Mapping[str, Any], io_map: Mapping[str, str], io_map_optional: bool = False) → Dict[str, str]¶ Maps a dictionary onto a new dictionary by changing some/all of the keys. :param input_dict: The input dictionary :param io_map: The dictionary used to perform the mapping. All keys and values must be strings. For example: As an example: {
“one”: “two”, “three”: “four”
} will map inputs keys of “one” to “two” AND “three” to “four”. :param io_map_optional: If this is False, a KeyError will be raised if the keys in the io_map are not found in the input_dict. :raises KeyError: if keys required in the mapping are not found in the input_dict :return: the remapped dictionary
-
asldro.utils.general.
splitext
(path)¶ The normal os.path.splitext treats path/example.tar.gz as having a filepath of path/example.tar with a .gz extension - this fixes it
asldro.utils.resampling module¶
Utility Functions for the ASL DRO
-
asldro.utils.resampling.
rot_x_mat
(theta: float) → numpy.ndarray¶ creates a 4x4 affine performing rotations about x
- Parameters
theta (float) – angle to rotate about x in degrees
- Returns
4x4 affine for rotating about x
- Return type
np.array
-
asldro.utils.resampling.
rot_y_mat
(theta: float) → numpy.ndarray¶ creates a 4x4 affine performing rotations about y
- Parameters
theta (float) – angle to rotate about y in degrees
- Returns
4x4 affine for rotating about y
- Return type
np.array
-
asldro.utils.resampling.
rot_z_mat
(theta: float) → numpy.ndarray¶ creates a 4x4 affine performing rotations about z
- Parameters
theta (float) – angle to rotate about z in degrees
- Returns
4x4 affine for rotating about z
- Return type
np.array
-
asldro.utils.resampling.
scale_mat
(scale: Union[Tuple[float, float, float], numpy.ndarray]) → numpy.ndarray¶ Creates a 4x4 affine performing scaling
- Parameters
vector (Tuple[float, float, float]) – describes (sx, sy, sz) scaling factors
- Returns
4x4 affine for scaling
- Return type
np.array
-
asldro.utils.resampling.
transform_resample_affine
(image: Union[nibabel.Nifti1Image, nibabel.Nifti2Image, asldro.containers.image.BaseImageContainer], translation: Tuple[float, float, float], rotation: Tuple[float, float, float], rotation_origin: Tuple[float, float, float], target_shape: Tuple[int, int, int]) → Tuple[numpy.ndarray, numpy.ndarray]¶ Calculates the affine matrices that transform and resample an image in world-space. Note that while an image (NIFTI or BaseImageContainer derived) is accepted an an argument, the image is not acutally resampled.
- Parameters
image (Union[nib.Nifti1Image, nib.Nifti2Image, BaseImageContainer]) – The input image
translation (Tuple[float, float, float]) – vector to translate in the image by in world space
rotation (Tuple[float, float, float]) – angles to rotate the object by in world space
rotation_origin (Tuple[float, float, float]) – coordinates for the centre point of rotation in world space
target_shape (Tuple[int, int, int]) – target shape for the resampled image
- Returns
[target_affine_with_motion, target_affine_no_motion]. target_affine_with_motion is the affine to supply to a resampling function. After resampling theresampled image’s affine should be set to to target_affine_no_motion so that it only has the image formation (scaling) operation performed (not the motion)
- Return type
Tuple[np.array, np.array]
-
asldro.utils.resampling.
transform_resample_image
(image: Union[nibabel.Nifti1Image, nibabel.Nifti2Image, asldro.containers.image.BaseImageContainer], translation: Tuple[float, float, float], rotation: Tuple[float, float, float], rotation_origin: Tuple[float, float, float], target_shape: Tuple[int, int, int]) → Tuple[Union[nibabel.Nifti2Image, nibabel.Nifti2Image], numpy.ndarray]¶ Transforms and resamples a nibabel NIFTI image in world-space
- Parameters
image (Union[nib.Nifti1Image, nib.Nifti2Image]) – The input image
translation (Tuple[float, float, float]) – vector to translate in the image by in world space
rotation (Tuple[float, float, float]) – angles to rotate the object by in world space
rotation_origin (Tuple[float, float, float]) – coordinates for the centre point of rotation in world space
target_shape (Tuple[int, int, int]) – target shape for the resampled image
- Returns
[resampled_image, target_affine]. resampled_image is the input image with the transformation and resampling applied. target_affine is the affine that was used to resample the image. Note resampled_image has an affine that only corresponds to voxel scaling and not motion, i.e. the image FOV is the same as the input image FOV.
- Return type
Tuple[Union[nib.Nifti2Image, nib.Nifti2Image], np.array]
-
asldro.utils.resampling.
translate_mat
(translation: Union[Tuple[float, float, float], numpy.ndarray]) → numpy.ndarray¶ Creates a 4x4 affine performing translations
- Parameters
vector (Tuple[float, float, float]) – describes (x, y, z) to translate along respective axes
- Returns
4x4 affine for translation
- Return type
np.array