Saving Output of ANTs registration using Python

Summary of what happened:

I am trying to register MR and PET images interfacing ANTs in Python via Nipype. When I just try to test the example registration code on the Nipype documentation website (Neuroimaging in Python - Pipelines and Interfaces — nipy pipeline and interfaces package), I keep getting an error that says:

FileNotFoundError: No such file or directory ‘/Users/bastiaanvantol/output_Composite.h5’ for output ‘composite_transform’ of a Registration interface

Can anyone point me in the direction of the problem? It seems that it is looking for a file or directory where the composite_transform, output of the Registration interface, should be saved. However, in the documentation I can’t seem to find where and how I should specify where this output should be saved.

Any help would be greatly appreciated!

Command used :

This is the example script used:

reg = Registration()
reg.inputs.fixed_image = pet_img
reg.inputs.moving_image = mr_img
reg.inputs.output_transform_prefix = “output_”
reg.inputs.transforms = [‘Affine’, ‘SyN’]
reg.inputs.transform_parameters = [(2.0,), (0.25, 3.0, 0.0)]
reg.inputs.number_of_iterations = [[1500, 200], [100, 50, 30]]
reg.inputs.dimension = 3
reg.inputs.write_composite_transform = True
reg.inputs.collapse_output_transforms = False
reg.inputs.initialize_transforms_per_stage = False
reg.inputs.metric = [‘Mattes’]*2
reg.inputs.metric_weight = [1]*2 # Default (value ignored currently by ANTs)
reg.inputs.radius_or_number_of_bins = [32]*2
reg.inputs.sampling_strategy = [‘Random’, None]
reg.inputs.sampling_percentage = [0.05, None]
reg.inputs.convergence_threshold = [1.e-8, 1.e-9]
reg.inputs.convergence_window_size = [20]*2
reg.inputs.smoothing_sigmas = [[1,0], [2,1,0]]
reg.inputs.sigma_units = [‘vox’] * 2
reg.inputs.shrink_factors = [[2,1], [3,2,1]]
reg.inputs.use_estimate_learning_rate_once = [True, True]
reg.inputs.use_histogram_matching = [True, True] # This is the default
reg.inputs.output_warped_image = ‘output_warped_image.nii.gz’
reg.cmdline

reg.run()

Hi @bneur,

You might find ANTsPy easier to use, if that works with your workflow. Here is a minimal example of a registration: Aligning fMRIPrep and QSIPrep Outputs - #18 by mblesac

If you want to stick to Nipype, it would be worth asking if you see any outputs anywhere when you run this code. The reg.inputs.output_transform_prefix = “output_” means it should be producing the transform matrix file that is being asked for in the error, maybe there is a mismatch in working directories?

Hope that helps,
Steven

Thank you for your comment Steven. I do want to try to wrap my head around the ANTs-nipype interface, but I will definitely take a look at ANTsPy too.

When I run the following line of code -
outputs=reg._list_outputs()

A directory called outputs is created with one key named composite-transform and its value /Users/bastiaanvantol/output_Composite.h5.

Another key is warped_image, and its value is /Users/bastiaanvantol/output_warped_image.nii.gz

However, no actual transform matrix file are produced, nor the warped nifti image. So, I do think this might be a problem related to working directories. Any idea on how to move on from here? I should have my working directory where I saved my .py script aligned with where I want my output to be? Or where the antsRegistration interface has been downloaded?