Elastix manager module
This module takes care of the section to section alignment. It imports libraries that contain the code from the elastix command line tools: https://elastix.lumc.nl/ The libraries are contained within the SimpleITK-SimpleElastix library
- class library.image_manipulation.elastix_manager.ElastixManager(iteration=0)
Bases:
FileLoggerClass for generating, storing and applying transformations within stack alignment [with the Elastix package] All methods relate to aligning images in stack
- align_downsampled_images(transforms)
align the downsample tiff images
- Parameters:
transforms – (dict) dictionary of transformations indexed by id of moving sections
- align_full_size_image(transforms)
- align the full resolution tif images with the transformations provided.
All the sections are aligned to the middle sections, the transformation of a given section to the middle section is the composite of the transformation from the given section through all the intermediate sections to the middle sections.
- Parameters:
transforms – (dict): dictionary of transformations that are index by the id of moving sections
- align_images(INPUT, OUTPUT, transforms)
function to align a set of images with a with the transformations between them given Note: image alignment is memory intensive (but all images are same size) 6 factor of est. RAM per image for clean/transform needs firmed up but safe
- Parameters:
INPUT – (str) directory of images to be aligned
(str) (OUTPUT) – directory output the aligned images
(dict) (transforms) – dictionary of transformations indexed by id of moving sections
- align_section_masks(animal, transforms)
function that can be used to align the masks used for cleaning the image. This not run as part of the pipeline, but is used to create the 3d shell around a certain brain
- Parameters:
animal – (str) Animal ID
transforms – (array): 3*3 transformation array
- apply_full_transformations(channel=1)
Calculate and store the rigid transformation using elastix. Align CH3 from CH1
- calculate_elastix_channels(INPUT, fixed_index, moving_index)
Calculates the rigid transformation from the Elastix output and adds it to the database.
- Parameters:
INPUT – path of the files
fixed_index – index of fixed image
moving_index – index of moving image
- calculate_elastix_transformation(INPUT, fixed_index, moving_index)
Calculates the rigid transformation from the Elastix output and adds it to the database.
- Parameters:
INPUT – path of the files
fixed_index – index of fixed image
moving_index – index of moving image
- call_alignment_metrics()
For the metrics value that shows how well the alignment went, elastix needs to be called as a separate program.
- create_dir2dir_transformations()
Calculate and store the rigid transformation using elastix. Align CH3 from CH1
- create_web_friendly_sections()
A function to create section PNG files for the database portal.
- create_within_stack_transformations()
Calculate and store the rigid transformation using elastix. The transformations are calculated from the next image to the previous This is done in a simple loop with no workers. Usually takes up to an hour to run for a stack. It only needs to be run once for each brain. We are now using multiple iterations to get better alignment. The 2nd pass uses the results of the 1st pass to align
- get_rotation_center(channel=1)
return a rotation center for finding the parameters of a transformation from the transformation matrix
- Return list:
list of x and y for rotation center that set as the midpoint of the section that is in the middle of the stack
- get_transformations()
After the elastix job is done, this goes into each subdirectory and parses the Transformation.0.txt file
- Parameters:
animal – the animal
- Returns:
a dictionary of key=filename, value = coordinates
- load_elastix_transformation(animal, moving_index, iteration)
loading the elastix transformation from the database
- Parameters:
animal – (str) Animal ID
moving_index – (int) index of moving section
- Return array:
2*2 roatation matrix, float: x translation, float: y translation
- static parameter_elastix_parameter_file_to_dict(filename)
- transform_image(img, T)