Setting an Initial Transform for Elastix

Hi ITK community!

I am setting up a pipeline in python to register MRI image stacks which tend to have poor initial alignment. I would like to provide an elastix image filter (sitk.ElastixImageFilter()) an initial transform determined via manual inspection (I have an 1x6 array of euler rotations, followed by translations).

I can see that I need to provide my elastixImageFilter a text file in a specific format that will define the initial transform (SetInitialTransformParameterFileName), but I am finding it difficult to find information on what the content/formatting of that file should be. And in the Elastix manual it states, “The transformation is defined as a mapping from the fixed image to the moving image.” Does that still apply to the initial transform that I will provide it in the required text file?

Eventually, I aim to remove the need for manual initial alignment, but for now, I want to focus on improving the elastix transform filter portion of my pipeline before I tackle initial alignment automation.

Thank you!

Take a look at this comment, in particular this and this (code below):

    itk.transformwrite([affine_pose_to_case], atlas_to_case_filename)
    out_elastix_transform = open(atlas_to_case_filename + '.txt', "w")
    out_elastix_transform.writelines(['(Transform "File")\n',
                                      '(TransformFileName "' + case + '-' + atlas + '.tfm")'])
    out_elastix_transform.close()

    registered, elastix_transform = itk.elastix_registration_method(
        case_bone_image.astype(itk.F),  # fixed image is used as primary input to the filter
        moving_image=atlas_aa_image.astype(itk.F),
        # moving_mask=atlas_aa_segmentation,
        parameter_object=parameter_object,
        initial_transform_parameter_file_name=atlas_to_case_filename + '.txt',
        # log_to_console=True,
        output_directory=root_dir + bone + '/',
        log_file_name=case + '-' + atlas + '-elx.log'
    )
1 Like