liom_toolkit.registration.templating module

liom_toolkit.registration.templating.build_template(initial_template: ANTsImage | None = None, image_list: list[ANTsImage] | None = None, iterations: int = 3, gradient_step: float = 0.2, blending_weight: float = 0.75, weights: bool | None = None, masks: list | None = None, remove_temp_output: bool = False, save_progress: bool = False, type_of_transform: str = 'SyN', **kwargs) ANTsImage

Estimate an optimal template from an input image_list A modification of the ANTsPy function build_template to use masks. Source here: https://antspyx.readthedocs.io/en/latest/_modules/ants/registration/build_template.html#build_template

Parameters:
  • initial_template (ants.ANTsImage) – The initial template to use

  • image_list (list[ants.ANTsImage]) – The list of images to use to create the template

  • iterations (int) – The number of iterations to use to create the template

  • gradient_step (float) – For shape update gradient

  • blending_weight (float) – Weight for image blending

  • weights (List[float]) – Weight for each input image

  • masks (List[ants.ANTsImage]) – List of masks corresponding to the images in image_list

  • remove_temp_output (bool) – Whether to remove the temporary output files

  • save_progress (bool) – Whether to save the progress of the template building

  • type_of_transform (str) – The type of transform to use for registration

  • kwargs – Extra arguments passed to ants registration

Returns:

The newly created template

Return type:

ants.ANTsImage

Example

>>> import ants
>>> image = ants.image_read( ants.get_ants_data('r16') )
>>> image2 = ants.image_read( ants.get_ants_data('r27') )
>>> image3 = ants.image_read( ants.get_ants_data('r85') )
>>> timage = ants.build_template( image_list = ( image, image2, image3 ) ).resample_image( (45,45))
>>> timagew = ants.build_template( image_list = ( image, image2, image3 ), weights = (5,1,1) )
liom_toolkit.registration.templating.build_template_for_resolution(output_file: str, zarr_files: list, brain_names: list, resolution_level: int = 3, template_resolution: int = 50, iterations: int = 15, init_with_template: bool = False, register_to_template: bool = False, flipped_brains: bool = False) None

Create a template for a given resolution level and save it to disk.

Parameters:
  • output_file (str) – The location where to save the template.

  • zarr_files (list) – The list of zarr files to use to create the template.

  • brain_names (list) – The list of brain names to use for saving the pre-registered images.

  • resolution_level (int) – The resolution level to load the images at.

  • template_resolution (int) – The resolution of the template.

  • iterations (int) – The number of iterations to use to create the template.

  • init_with_template (bool) – Whether to initialize the template with the atlas volume or the first image.

  • register_to_template (bool) – Whether to register the template to the atlas volume.

  • flipped_brains (bool) – Whether to include flipped brains in the template.

Returns:

None

liom_toolkit.registration.templating.create_template(images: list, masks: list, brain_names: list, template_volume: ANTsImage, template_resolution: int | float = 10, iterations: int = 3, init_with_template=True, save_pre_reg: bool = False, remove_temp_output: bool = False, save_templating_progress: bool = False, pre_registration_type: str = 'Rigid', templating_registration_type: str = 'SyN') ANTsImage

Create a template from a folder of images.

Parameters:
  • images (list) – List of images to use to create the template.

  • masks (list) – List of masks to use to create the template.

  • brain_names (list) – List of brain names to use for saving the pre-registered images.

  • template_volume (ants.ANTsImage) – Default template to pre-register the brains to and possible the initial volume for registration.

  • template_resolution (int) – The resolution of the template.

  • iterations (int) – The number of iterations to use to create the template.

  • init_with_template (bool) – Whether to initialize the template with the atlas volume or the first image.

  • save_pre_reg (bool) – Whether to save the pre-registered images.

  • remove_temp_output (bool) – Whether to remove the temporary output.

  • save_templating_progress (bool) – Whether to save the template at each iteration.

  • pre_registration_type (str) – The type of pre-registration to use.

  • templating_registration_type (str) – The type of registration to use to create the template.

Returns:

The newly created template.

Return type:

ants.ANTsImage

liom_toolkit.registration.templating.load_volume_for_registration(image_node, mask_node, resolution_level, flipped=False) -> (<class 'ants.core.ants_image.ANTsImage'>, <class 'ants.core.ants_image.ANTsImage'>)

Load a volume from a zarr file to use in registration. Will apply the mask to the volume and load it in RAS+ orientation. Can also flip the volume.

Parameters:
  • image_node (zarr.core.Node) – The image node to load the image from.

  • mask_node (zarr.core.Node) – The mask node to load the mask from.

  • resolution_level (int) – The resolution level to load the volume at.

  • flipped (bool) – Whether to flip the volume or not.

Returns:

The loaded volume and mask.

Return type:

tuple[ants.ANTsImage, ants.ANTsImage]

liom_toolkit.registration.templating.pre_register_brain(volume: ~ants.core.ants_image.ANTsImage, mask: ~ants.core.ants_image.ANTsImage | None, template: ~ants.core.ants_image.ANTsImage, brain: str, save_pre_reg: bool = False, registration_type: str = 'Rigid') -> (<class 'ants.core.ants_image.ANTsImage'>, <class 'ants.core.ants_image.ANTsImage'>)

Register an image to a template and return the registered image and mask.

Parameters:
  • volume (ants.ANTsImage) – The volume to register

  • mask (ants.ANTsImage) – The mask to use in registration

  • template (ants.ANTsImage) – The template to register to

  • brain (str) – The name of the brain

  • save_pre_reg (bool) – Whether to save the pre-registered image and mask

  • registration_type (str) – The type of registration to use

Returns:

The registered image and registered mask

Return type:

tuple[ants.ANTsImage, ants.ANTsImage]

liom_toolkit.registration.templating.update_brain_name_list(names: list) list

Update the brain name list to include the flipped brains.

Parameters:

names (list) – The list of brain names.

Returns:

The updated list of brain names.

Return type:

list