Closed binarybottle closed 11 years ago
the nipype interface doesn't currently allow multiple metrics for a transform. i'm currently working on a cerebellar alignment evaluation and will post back what parameters work well for that.
also nick advised using the metrics in antsCorticalThickness.sh, so i tried those:
reg = Registration()
reg._cmd = '/software/ANTS/versions/130509/antsRegistration'
reg.inputs.transforms = ['Rigid', 'Affine', 'SyN']
reg.inputs.transform_parameters = [(0.1,), (0.1,), (0.1, 3.0, 0.0)]
reg.inputs.number_of_iterations = [[1000,500,250,100]]*2 + [[100,100,70,20]]
reg.inputs.dimension = 3
reg.inputs.write_composite_transform = True
reg.inputs.collapse_output_transforms = True
reg.inputs.metric = ['MI']*2 + ['CC']
reg.inputs.metric_weight = [1]*3 # Default (value ignored currently by ANTs)
reg.inputs.radius_or_number_of_bins = [32]*2 + [4]
reg.inputs.sampling_strategy = ['Regular']*2 + [None]
reg.inputs.sampling_percentage = [0.25]*2 + [None]
reg.inputs.convergence_threshold = [1.e-8]*2 + [1e-9]
reg.inputs.convergence_window_size = [10]*2 + [15]
reg.inputs.smoothing_sigmas = [[3,2,1,0]]*3
reg.inputs.sigma_units = ['mm']*3
reg.inputs.shrink_factors = [[8,4,2,1]]*2 + [[6,4,2,1]]
reg.inputs.use_estimate_learning_rate_once = [True, True, True]
reg.inputs.use_histogram_matching = [False]*2 + [True] # This is the default
reg.inputs.initial_moving_transform_com = True
reg.inputs.output_warped_image = True
reg.inputs.winsorize_lower_quantile = 0.01
reg.inputs.winsorize_upper_quantile = 0.99
takes about 6 hours with:
regnode = Node(reg, name='ANTSreg')
regnode.inputs.num_threads = 2
i can't get it to use more than 2 threads.
thank you, satra. these do differ quite a bit. i heard the new itk4 version would take longer, but 6 hours? well, i think it makes sense for now to use the above to compute and apply an affine transform to standard space, and worry about nonlinear volume deformation to label subcortical regions a little later. will the following save an affine transform?:
reg = Node(name='Register_template', interface = Registration())
mbFlow.add_nodes([reg])
if do_input_nifti:
mbFlow.connect([(niftiVol, reg, [('nifti_volume','moving_image')])])
else:
mbFlow.connect([(mgh2nifti, reg, [('out_file','moving_image')])])
reg.inputs.fixed_image = [ants_template]
reg.inputs.num_threads = 2
reg.inputs.transforms = ['Rigid', 'Affine']
reg.inputs.transform_parameters = [(0.1,), (0.1,)]
reg.inputs.number_of_iterations = [[1000,500,250,100]]*2
reg.inputs.dimension = 3
reg.inputs.write_composite_transform = True
reg.inputs.collapse_output_transforms = True
reg.inputs.metric = ['MI']*2
reg.inputs.metric_weight = [1]*2
reg.inputs.radius_or_number_of_bins = [32]*2
reg.inputs.sampling_strategy = ['Regular']*2
reg.inputs.sampling_percentage = [0.25]*2
reg.inputs.convergence_threshold = [1.e-8]*2
reg.inputs.convergence_window_size = [10]*2
reg.inputs.smoothing_sigmas = [[3,2,1,0]]*2
reg.inputs.sigma_units = ['mm']*2
reg.inputs.shrink_factors = [[8,4,2,1]]*2
reg.inputs.use_estimate_learning_rate_once = [True, True]
reg.inputs.use_histogram_matching = [False]*2
reg.inputs.output_warped_image = True
reg.inputs.winsorize_lower_quantile = 0.01
reg.inputs.winsorize_upper_quantile = 0.99
# Nipype output:
reg.inputs.write_composite_transform = True
mbFlow.connect([(reg, Sink,
[('composite_transform', 'transforms.@affine')])])
it seems to work only if i remove the line: reg.inputs.sigma_units = ['mm']*2
otherwise i get the error: "traits.trait_errors.TraitError: Cannot set the undefined 'sigma_units' attribute of a 'RegistrationInputSpec' object."
you don't have nipype 0.8 - that was added in the current release.
thank you -- i just updated and am running, but i don't know what the output affine transform file name will be, so how do i connect it to the next node in?:
https://github.com/binarybottle/mindboggle/blob/master/mindboggle/pipeline.py#L1191
since you are only using the affine transforms you can do:
wf.connect(regnode, 'composite_transform', at, 'transforms')
if in the future you only want to apply the affine part of a complex transform you would do:
wf.connect(regnode, ('forward_transforms', pickfirst), atl, 'transforms')
where
pickfirst = lambda x: x[:1]
thank you, satra. the resulting *GenericAffine.mat transform file is not a text file. is this because i chose write_composite_transform?: https://github.com/binarybottle/mindboggle/blob/master/mindboggle/pipeline.py#L646 how do i get it to output the transform as a text file?
also, i am now getting the following error (i got the first file but not the second): FileNotFoundError: File/Directory '['/Users/arno/Desktop/output/workspace/Mindboggle/_hemi_rh_subject_Twins-2-1/antsRegister_standard/affine_0GenericAffine.mat', '/Users/arno/Desktop/output/workspace/Mindboggle/_hemi_rh_subject_Twins-2-1/antsRegister_standard/affine_1InverseWarp.nii.gz']' not found for Registration output 'reverse_transforms'. Interface Registration failed to run.
why do you need a text file? ants now stores the transforms as mat files or hdf5 files.
regarding the reverse transforms, how recent a version of ants are you using?
i need a text file for flexibility. for example, i am using it in the form of a numpy array to transform the coordinates within a vtk surface mesh.
i installed ants via github on april 26th.
regarding the text file, you'll have to bring it up with the ants folks
can you paste the contents of the folder:
/Users/arno/Desktop/output/workspace/Mindboggle/_hemi_rh_subject_Twins-2-1/antsRegister_standard/
or put it in dropbox temporarily so i can take a look.
i placed the directory in the dropbox.
perhaps then i will revert to using the ANTS command instead of antsRegistration to get the text itk transform. is the ANTS command wrapped in nipype as well?
it is wrapped under legacy.
but you can read the .mat file in python, so why do you need the text file?
also the reverse_transform error is a bug in nipype when no nonlinear transforms are specified. i won't have time to fix that immediately.
how do i read that .mat file in python?
until the bug is fixed i'll use flirt and read its -omat transform using np.loadtxt, or skip ahead to computing a nonlinear transform with antsRegistration.
from scipy.io import loadmat
regarding a text transform option, nick tustison wrote to me:
"We currently don't have that option. There is an external program 'ConvertTransformFile' which will convert the binary format to text format."
unfortunately, i get the following error when i try to load the ants transform in our dropbox:
from scipy.io import loadmat transform = loadmat('/drop/MB/data/arno/mri/affine_to_template.mat') ValueError: Unknown mat file type, version 57, 56
i'll just go ahead and use the "ConvertTransformFile" program for now.
I would like to obtain an affine (as well as nonlinear) transform from each image volume to a template (yet to be supplied; currently set to the MNI152 template). For this I have included nipype's antsRegistration wrapper: http://www.mit.edu/~satra/nipype-nightly/interfaces/generated/nipype.interfaces.ants.registration.html#examples,
but am having trouble setting the parameters according to: https://github.com/stnava/ANTs/blob/master/Scripts/newAntsExample.sh
in particular, i don't know how to set multiple metrics for syn: https://github.com/binarybottle/mindboggle/blob/master/mindboggle/pipeline.py#L637
and i have not been successful saving the affine transform.