第一次使用matlab spm配准医学图像,使用spm提供的GUI界面,一次只能处理一个图像。
使用一下脚本,可以实现批量配准操作:
spm_jobman('initcfg');
dir_path='E:\\xxx\\processed_t1\\new_MS'
subdir=dir(dir_path)
for i=3:length(subdir)
%设置source文件地址
source=fullfile( dir_path, subdir( i ).name, 'new_t1.nii' );
%设置reference文件地址
reference=fullfile( dir_path, subdir( i ).name, 'FLAIR_brain_norm.nii' );
clear matlabbatch
% 以下spm12默认设置
matlabbatch{1}.spm.spatial.coreg.estwrite.ref = {reference};
matlabbatch{1}.spm.spatial.coreg.estwrite.source = {source};
matlabbatch{1}.spm.spatial.coreg.estwrite.other = {''};
matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.interp = 4;
matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.wrap = [0 0 0];
matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.mask = 0;
matlabbatch{1}.spm.spatial.coreg.estwrite.roptions.prefix = 'r';
% 运行
spm_jobman('run', matlabbatch);
end