In this notebook 2 other options of the elastix algorithm are shown: initial transformation and multithreading. They're shown together just to reduce the number of example notebooks and thus can be used independently as well as in combination with whichever other functionality of the elastix algorithm.
Initial transforms are transformations that are done on the moving image before the registration is started.
Multithreading spreaks for itself and can be used in similar fashion in the transformix algorithm.
import itk
# Import Images
fixed_image = itk.imread('data/CT_2D_head_fixed.mha', itk.F)
moving_image = itk.imread('data/CT_2D_head_moving.mha', itk.F)
# Import Default Parameter Map
parameter_object = itk.ParameterObject.New()
parameter_map_rigid = parameter_object.GetDefaultParameterMap('rigid')
parameter_object.AddParameterMap(parameter_map_rigid)
Registration can either be done in one line with the registration function...
# Call registration function with initial transfrom and number of threads
result_image, result_transform_parameters = itk.elastix_registration_method(
fixed_image, moving_image,
parameter_object=parameter_object,
initial_transform_parameter_file_name='data/TransformParameters.0.txt',
number_of_threads=4,
log_to_console=False)
.. or by initiating an elastix image filter object.
# Load Elastix Image Filter Object with initial transfrom and number of threads
elastix_object = itk.ElastixRegistrationMethod.New(fixed_image,moving_image)
# elastix_object.SetFixedImage(fixed_image)
# elastix_object.SetMovingImage(moving_image)
elastix_object.SetParameterObject(parameter_object)
elastix_object.SetInitialTransformParameterFileName(
'data/TransformParameters.0.txt')
elastix_object.SetNumberOfThreads(4)
# Set additional options
elastix_object.SetLogToConsole(False)
# Update filter object (required)
elastix_object.UpdateLargestPossibleRegion()
# Results of Registration
result_image = elastix_object.GetOutput()
result_transform_parameters = elastix_object.GetTransformParameterObject()
Pointing from a transform parameter file to the path of a second initial transform parameter file is supported from the 0.7.0 release of ITKElastix.