SPM12 toolbox to align an image to SPM's template space.
This toolbox uses the initial step from Segment under the hood.
This registration algorithm is more robust than Coregister when applied to tissue probability maps, and handles affine transforms.
spm_mni_align
folder under spm12/toolbox
spm
.Note:
By default, Estimate does not modify the header of the input files in-place but instead writes a new file.
To recover the in-place behaviour of Coregister, set the Filename Prefix option to an empty string.
matlabbatch{1}.spm.tools.align.estimate.source = {'<PATH TO FIRST IMAGE>'}; % image used in registration
matlabbatch{1}.spm.tools.align.estimate.other = {
'<PATH TO OTHER IMAGE 1>'
'<PATH TO OTHER IMAGE 2>'
'<PATH TO OTHER IMAGE 3>'
...
}; % estimated transform is applied to these images too
matlabbatch{1}.spm.tools.align.estimate.ref = {
fullfile(spm('dir'), 'tpm', 'TPM.nii,1')
fullfile(spm('dir'), 'tpm', 'TPM.nii,2')
fullfile(spm('dir'), 'tpm', 'TPM.nii,3')
fullfile(spm('dir'), 'tpm', 'TPM.nii,4')
fullfile(spm('dir'), 'tpm', 'TPM.nii,5')
fullfile(spm('dir'), 'tpm', 'TPM.nii,6')
}; % tissue probability map defining the template space
matlabbatch{1}.spm.tools.align.estimate.eoptions.rigid = 0; % 0 = affine, 1 = rigid
matlabbatch{1}.spm.tools.align.estimate.eoptions.sep = [8 2]; % Distance between sampled points in mm
matlabbatch{1}.spm.tools.align.estimate.eoptions.fwhm = [32 1]; % Fudge factor in mm (higher = stiff)
matlabbatch{1}.spm.tools.align.estimate.eoptions.prefix = 'e'; % Prefix of the output image
matlabbatch{1}.spm.tools.align.estimate.eoptions.dir = {''}; % Output folder. Empty '' = same as input
matlabbatch{1}.spm.tools.align.write.ref = {'<PATH TO TARGET IMAGE>'}; % defines the resliced space
matlabbatch{1}.spm.tools.align.write.source = {'<PATH TO SOURCE IMAGE>'}; % image to reslice
matlabbatch{1}.spm.tools.align.write.roptions.interp = 4; % Interpolation order
matlabbatch{1}.spm.tools.align.write.roptions.wrap = [0 0 0]; % Dimensions with circulant boundaries
matlabbatch{1}.spm.tools.align.write.roptions.mask = 0; % Mask out voxels where at least one image is out-of-bounds
matlabbatch{1}.spm.tools.align.write.roptions.prefix = 'r'; % Prefix of the output image
matlabbatch{1}.spm.tools.align.write.roptions.dir = ''; % Output folder. Empty '' = same as input
matlabbatch{1}.spm.tools.align.estwrite.source = {'<PATH TO FIRST IMAGE>'}; % image used in registration
matlabbatch{1}.spm.tools.align.estwrite.other = {
'<PATH TO OTHER IMAGE 1>'
'<PATH TO OTHER IMAGE 2>'
'<PATH TO OTHER IMAGE 3>'
...
}; % estimated transform is applied to these images too
matlabbatch{1}.spm.tools.align.estwrite.ref = {
fullfile(spm('dir'), 'tpm', 'TPM.nii,1')
fullfile(spm('dir'), 'tpm', 'TPM.nii,2')
fullfile(spm('dir'), 'tpm', 'TPM.nii,3')
fullfile(spm('dir'), 'tpm', 'TPM.nii,4')
fullfile(spm('dir'), 'tpm', 'TPM.nii,5')
fullfile(spm('dir'), 'tpm', 'TPM.nii,6')
}; % tissue probability map defining the template space
matlabbatch{1}.spm.tools.align.estwrite.eoptions.rigid = 0; % 0 = affine, 1 = rigid
matlabbatch{1}.spm.tools.align.estwrite.eoptions.sep = [8 2]; % Distance between sampled points in mm
matlabbatch{1}.spm.tools.align.estwrite.eoptions.fwhm = [32 1]; % Fudge factor in mm (higher = stiff)
matlabbatch{1}.spm.tools.align.estwrite.eoptions.prefix = 'e'; % Prefix of the output estimated image
matlabbatch{1}.spm.tools.align.estwrite.eoptions.dir = {''}; % Output folder (estimate). Empty '' = same as input
matlabbatch{1}.spm.tools.align.estwrite.roptions.interp = 4; % Interpolation order
matlabbatch{1}.spm.tools.align.estwrite.roptions.wrap = [0 0 0]; % Dimensions with circulant boundaries
matlabbatch{1}.spm.tools.align.estwrite.roptions.mask = 0; % Mask out voxels where at least one image is out-of-bounds
matlabbatch{1}.spm.tools.align.estwrite.roptions.prefix = 'r'; % Prefix of the output resliced image
matlabbatch{1}.spm.tools.align.estwrite.roptions.dir = ''; % Output folder (reslice). Empty '' = same as input
GNU-GPL 3