Hello,
I’m hoping to confirm whether my following code is indeed performing the function I’m intending: transforming an image from MNI space to talairach space as specified by Lancaster et al. (https://brainmap.org/icbm2tal/).
def icbm_spm2tal(input_mni_image, name):
talairach_reference_space_image = image.load_img('data/colin_27_mask_2mm.nii.gz')
# spm to talairach
icbm_spm2tal_affine = np.array([[0.9254, 0.0024, -0.0118, -1.0207],
[-0.0048, 0.9316, -0.0871, -1.7667],
[0.0152, 0.0883, 0.8924, 4.0926],
[0.0000, 0.0000, 0.0000, 1.0000]]);
after_rot = image.resample_img(input_mni_image,
target_affine=icbm_spm2tal_affine.dot(talairach_reference_space_image.affine),
target_shape=talairach_reference_space_image.shape[0:3],
interpolation='nearest')
after_rot.to_filename( name + '_tal.nii.gz')
return after_rot
Alternatively, I’ve had trouble with the nipyp ApplyXFM() function
import scipy
icbm_fsl = np.array([[0.9254, 0.0024, -0.0118, -1.0207],
[-0.0048, 0.9316, -0.0871, -1.7667],
[0.0152, 0.0883, 0.8924, 4.0926],
[0.0000, 0.0000, 0.0000, 1.0000]])
scipy.io.savemat('icbm_fsl.mat', {'mydata': icbm_fsl})
cd = '/Users/thomasvanasse/Desktop/'
import nipype.interfaces.fsl as fsl
from nipype.testing import example_data
applyxfm = fsl.preprocess.ApplyXFM()
applyxfm.inputs.in_file = cd + 'mean_rCST.nii.gz'
applyxfm.inputs.in_matrix_file = cd + 'icbm_fsl.mat'
applyxfm.inputs.out_file = cd + 'out_file.nii.gz'
applyxfm.inputs.reference = cd + 'colin_27_mask_2mm.nii.gz'
applyxfm.inputs.apply_xfm = True
result = applyxfm.run()
However, with nipype I get the following error:
RuntimeError: Command:
flirt -in /Users/thomasvanasse/Desktop/mean_rCST.nii.gz -ref /Users/thomasvanasse/Desktop/colin_27_mask_2mm.nii.gz -out /Users/thomasvanasse/Desktop/out_file.nii.gz -omat mean_rCST_flirt.mat -applyxfm -init /Users/thomasvanasse/Desktop/icbm_fsl.mat
Standard output:
Standard error:
libc++abi.dylib: terminating with uncaught exception of type NEWMAT::IncompatibleDimensionsException
Return code: -6
Any help would be appreciated,
Tom