Hey there,
This is my workflow in nipype:
- Realign using SPM, coregister with BBRegister (Freesurfer), convert to ITK format using C3DAffineTool, Register T1 to template using ANTs, merge BBRegister and ANTs matrices, and apply them to the mean image from the Realign step using AntsApplyTransform.
The registration works out just fine, but the transformation is horrible. I tried just transforming using the ITK converted BBRegister matrix and the result is faulty. Would love to know what I’m doing wrong here. Here’s my code:
bbreg = MapNode(BBRegister(),
# overwrite=True,
iterfield=['source_file'],
name='bbreg')
bbreg.inputs.init = 'header'
bbreg.inputs.contrast_type = 't2'
bbreg.inputs.subjects_dir = fs_sub_dir
bbreg.inputs.out_fsl_file = True
bbreg.inputs.epi_mask = True
bbreg.inputs.registered_file = True
preproc.connect([
(infosource, bbreg, [('subject_id', 'subject_id')]),
(realignUnwarp, bbreg, [('mean_image', 'source_file')]),
])
# Convert BBRegister transformation to ANTS ITK format.
convert2itk = MapNode(C3dAffineTool(),
iterfield=['source_file', 'transform_file'],
name='convert2itk')
convert2itk.inputs.fsl2ras = True
convert2itk.inputs.itk_transform = True
preproc.connect([
(bbreg, convert2itk, [('out_fsl_file', 'transform_file')]),
(realignUnwarp, convert2itk, [('mean_image', 'source_file')]),
(brainextract, convert2itk, [('out_file', 'reference_file')])
])
# Concatenate the affine and ants transforms into a list.
merge = MapNode(Merge(2), overwrite=True, iterfield=['in2'], name='mergexfm')
preproc.connect(convert2itk, 'itk_transform', merge, 'in2')
preproc.connect(reg, 'composite_transform', merge, 'in1')
# Transform the mean image, first to anatomical then to target.
warpmean = MapNode(ants.ApplyTransforms(),
overwrite=False,
iterfield=['input_image', 'transforms'],
name='warpmean')
warpmean.inputs.input_image_type = 0
warpmean.inputs.interpolation = 'Linear'
warpmean.inputs.invert_transform_flags = [False, False]
warpmean.inputs.terminal_output = 'file'
warpmean.inputs.args = '--float'
warpmean.inputs.num_threads = 4
warpmean.plugin_args = {'sbatch_args': '-c%d' % 4}
warpmean.inputs.reference_image = template_image
preproc.connect([
(realignUnwarp, warpmean, [('mean_image', 'input_image')]),
(merge, warpmean, [('out', 'transforms')])
])