Registration Module
Base Image Normalization API
affine_registration(fixed_image, moving_image, moving_mask=None, template_mask=None, fast_method=True)
Register two images using an affine transformation. This method applies a 3D affine transformation in order to register the moving image to the fixed image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed_image
|
ImageIO
|
np.ndarray The fixed image as the reference space. |
required |
moving_image
|
ImageIO
|
np.ndarray The moving image to be registered. |
required |
moving_mask
|
ImageIO
|
np.ndarray, optional The mask of the moving image. If not provided, the moving image will be used as the mask. |
None
|
template_mask
|
ImageIO
|
np.ndarray, optional The mask of the fixed image. If not provided, the fixed image will be used as the mask. |
None
|
Raises:
| Type | Description |
|---|---|
Exception
|
fixed_image and moving_image must be a numpy array. |
Returns
resampled_image : np.ndarray The moving image transformed into the template image space. transformation_matrix : np.ndarray The transformation matrix mapping from moving to template space.
Source code in asltk/registration/__init__.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
apply_transformation(moving_image, reference_image, transforms, **kwargs)
Apply a transformation list set to an image.
This method applies a list of transformations to a moving image to align it with a reference image. The transformations are typically obtained from a registration process, such as rigid or affine registration.
Note
The transforms parameter should be a list of transformation matrices
obtained from a registration process. The transformations are applied
in the order they are provided in the list.
Tip
Additional parameters can be passed to the ants.apply_transforms
function using the kwargs parameter. This allows for customization of
the transformation process, such as specifying interpolation methods,
handling of missing data, etc. See more in the ANTsPy documentation:
https://antspy.readthedocs.io/en/latest/registration.html#ants.apply_transforms
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
np.ndarray The image to be transformed. |
required | |
reference_image
|
ImageIO
|
np.ndarray The reference image to which the transformed image will be aligned. If not provided, the original image will be used as the reference. |
required |
transforms
|
list
|
list The transformation matrix list. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
transformed_image |
np.ndarray The transformed image. |
Source code in asltk/registration/__init__.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
rigid_body_registration(fixed_image, moving_image, moving_mask=None, template_mask=None)
Register two images using a rigid body transformation. This methods applies a Euler 3D transformation in order to register the moving image to the fixed image.
Note
The registration assumes that the moving image can be adjusted using only rotation and translation, without any scaling or shearing. This is suitable for cases in algiment among temporal volumes, such as in ASL data, where the images are acquired in the same space and only small movements are expected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed_image
|
ImageIO
|
np.ndarray The fixed image as the reference space. |
required |
moving_image
|
ImageIO
|
np.ndarray The moving image to be registered. |
required |
moving_mask
|
ImageIO
|
np.ndarray, optional The mask of the moving image. If not provided, the moving image will be used as the mask. |
None
|
template_mask
|
ImageIO
|
np.ndarray, optional The mask of the fixed image. If not provided, the fixed image will be used as the mask. |
None
|
Raises:
| Type | Description |
|---|---|
Exception
|
fixed_image and moving_image must be a numpy array. |
Exception
|
moving_mask must be a numpy array. |
Exception
|
template_mask must be a numpy array. |
Returns
normalized_image : np.ndarray The moving image transformed into the template image space. transforms : list A list of transformation mapping from moving to template space.
Source code in asltk/registration/__init__.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
space_normalization(moving_image, template_image, moving_mask=None, template_mask=None, transform_type='SyNBoldAff', **kwargs)
Perform brain normalization to register the moving image into the template image space.
This function uses ANTsPy to register a moving image to a template image. Optional masks can be provided for both images. The registration process supports different transformation types.
This is the base method for space normalization, which can be used for different types of images, such as M0, T1w, and ASL images. The method is designed to be flexible and can be used for different types of images, as long as the moving image and template image are provided in the correct format.
Note
For more specific cases, such as ASL data normalization, one can
use other methods, such as in asl_normalization module.
Note
Usually the space normalization is performed between the M0 and T1w images. The M0 image is one of the images obtained in the ASL acquisition and the T1w image is the anatomical image template.
Important
The transform_type parameter allows for different types of
transformations, such as 'SyN', 'BSpline', etc. The default is 'SyNBoldAff',
which is suitable for registering ASL images to a T1-weighted template.
All the definitions of the transformation types can be found in the
ANTsPy documentation: https://antspy.readthedocs.io/en/latest/registration.html
Important
This method always assumes a template image as a BrainAtlas object. One may pass a string with the name of the atlas, and the method will automatically load the atlas and use the T1-weighted image as the template image. If a different template image is needed, it should be passed as a BrainAtlas object, however, it depends on the ASLtk Kaggle dataset structure, so it is not recommended to raise an issue in the official ASLtk repository if the template image is not presented in the BrainAtlas format.
Parameters
moving_image : np.ndarray The moving image. template_image : BrainAtlas or str or np.ndarray The template image as BrainAtlas object, string with the atlas name or a numpy array. moving_mask : np.ndarray, optional The moving mask in the same space as the moving image. If not provided, no mask is used. template_mask : np.ndarray, optional The template mask in the same space as the template image. If not provided, no mask is used. transform_type : str, optional Type of transformation ('SyN', 'BSpline', etc.). Default is 'SyNBoldAff'. verbose : bool, optional Whether to print detailed orientation analysis. Default is False.
Returns
normalized_image : np.ndarray The moving image transformed into the template image space. transform : list A list of transformation mapping from moving to template space.
Source code in asltk/registration/__init__.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
ASL Normalization API
asl_template_registration(asl_data, atlas_reference='MNI2009', additional_maps=None, asl_data_mask=None, verbose=False)
Register ASL data to common atlas space.
This function applies a elastic normalization to fit the subject head space into the atlas template space.
Note
This method takes in consideration the ASLData object, which contains
the pcasl and/or m0 image. The registration is performed using primarily
the m0image if available, otherwise it uses the pcasl image.
Therefore, choose wisely the ref_vol parameter, which should be a valid index
for the best pcaslvolume reference to be registered to the atlas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asl_data
|
ASLData
|
ASLData The ASLData object containing the pcasl and/or m0 image to be corrected. |
required |
ref_vol
|
(int, optional) The index of the reference volume to which all other volumes will be registered. Defaults to 0. |
required | |
asl_data_mask
|
ImageIO
|
np.ndarray A single volume image mask. This can assist the normalization method to converge into the atlas space. If not provided, the full image is adopted. |
None
|
atlas_name
|
str
The atlas type to be considered. The BrainAtlas class is applied, then choose
the |
required | |
verbose
|
bool
|
(bool, optional) If True, prints progress messages. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not an ASLData object. |
ValueError
|
If ref_vol is not a valid index. |
RuntimeError
|
If an error occurs during registration. |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
ASLData object with corrected volumes and a list of transformation matrices. |
Source code in asltk/registration/asl_normalization.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
head_movement_correction(asl_data, ref_vol=None, method='snr', roi=None, verbose=False)
Correct head movement in ASL data using rigid body registration.
This function applies rigid body registration to correct head movement in ASL data. It registers each volume in the ASL data to a reference volume.
Hence, it can be helpfull to correct for head movements that may have
occurred during the acquisition of ASL data.
Note:
The reference volume is selected based on the ref_vol parameter,
which should be a valid index of the total number of volumes in the ASL data.
The ref_vol value for 0 means that the first volume will be used as the reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asl_data
|
ASLData
|
ASLData) The ASLData object containing the pcasl image to be corrected. |
required |
ref_vol
|
ImageIO
|
(np.ndarray, optional)
The reference volume to which all other volumes will be registered.
If not defined, the |
None
|
method
|
str
|
(str, optional) The method to select the reference volume. Options are 'snr' or 'mean'. If 'snr', the volume with the highest SNR is selected. If 'mean', the volume with the highest mean signal is selected. |
'snr'
|
verbose
|
bool
|
(bool, optional) If True, prints progress messages. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not an ASLData object. |
ValueError
|
If no valid reference volume is provided. |
RuntimeError
|
If the normalization fails. |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
ASLData object with corrected volumes and a list of transformation matrices. |
Source code in asltk/registration/asl_normalization.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |