matlab怎么使⽤spm_vol,SPM12批量处理预处理数据经过⼏次实践,现总结下通⽤的流程。
从⼀个问题出发:
问题:我想计算海马体积、内嗅⽪层体积和内嗅⽪层厚度等等。
过程:
1.先⽤⼀个⼈的数据保存⼀个对所有⼈的数据选择好要进⾏的处理,如下图:
image.png
Tips:如果下⼀步的数据需要⽤到上⼀步的结果,当你选择时会有⼀个Dependency供你选择,如下图:
image.png
2.选择File->Save batch and script来保存⼀个对待处理的数据通⽤的batch⽂件,如下图,我这⾥保存为batch.m和batch_job.m
image.png
3.编辑batch.m和batch_job.m这两个⽂件,使⽤⼀个循环⼀次性把这些数据处理完。
于是在原本的batch.m⽂件⾥,添加如下的代码实现循环:
% By - Galory Email - 996377370a@gmail
% List of open inputs
global sub type
% My files are named as 1 2 3 4 5 6 7 8 9 10 11 (24)
type={'1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24'};
for i=1:length(type)
sub = i;
end
解释⼀下,上边length(type)就是要循环的次数,之后再把原来的代码放⼊这个for循环中的sub = i;与end之间。
在batch_job.m⽂件⾥添加如下代码:
global sub
inputpath=['C:/Users/xuwhe/Desktop/t1/' num2str(sub)];
%选取raw data
pathname1=[inputpath '/'];
sdir1=dir([pathname1,'*.nii']);%select .nii file
for i=1:length(sdir1)
imgfile1{i,1}=[pathname1 sdir1(i).name];
end
注意这⾥是根据⾃⼰的⽂件夹结构来设置,⽐如我这⾥是这样的:
image.png
会发现我的⽂件布局结构是所有数据都在C:/Users/xuwhe/Desktop/t1/路径下,因为提前给每个⼈编好了号,每个⼈对应⼀个数字的⽂件夹,这⾥就是1、2、3......24;⽽在这每个数字命名的⽂件夹之下就是待处理的.nii⽂件,这⾥采⽤的是通配符*.nii选取nii⽂件。
修改完毕,逐⼀核对⼀下该设置路径的位置有没有正确读取,可以先拿⼀两个⼈测试。
之后运⾏batch_job.m就可以了。
unknown怎么处理这⾥附上完整代码:
batch.m:
% By - Galory Email - 996377370a@gmail
% List of open inputs
global sub type
% My files are named as 1 2 3 4 5 6 7 8 9 10 11 (24)
type={'1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24'};
for i=1:length(type)
sub = i;
nrun = 1; % enter the number of runs here
jobfile = {'C:/Users/xuwhe/Desktop/t/batch_job.m'};
jobs = repmat(jobfile, 1, nrun);
inputs = cell(0, nrun);
for crun = 1:nrun
end
spm('defaults','fmri');
spm_jobman('run',jobs,inputs{:});
end
batch_job.m:
%-----------------------------------------------------------------------
% Job saved on 30-Aug-2018 23:46:58 by cfg_util (rev $Rev: 6460 $)
% spm SPM - SPM12 (6906)
% cfg_basicio BasicIO - Unknown
%-----------------------------------------------------------------------
global sub
inputpath=['C:/Users/xuwhe/Desktop/t1/' num2str(sub)];
%选取raw data
pathname1=[inputpath '/'];
sdir1=dir([pathname1,'*.nii']);%select .nii file
for i=1:length(sdir1)
imgfile1{i,1}=[pathname1 sdir1(i).name];
end
matlabbatch{1}.ls.cat.estwrite.data = imgfile1;
matlabbatch{1}.ls.cat.estwrite.nproc = 0;
matlabbatch{1}.ls.cat.estwrite.opts.tpm = {'D:/software/neuroscience/Matlab2016b/toolbox/spm12/tpm/TPM.nii'}; matlabbatch{1}.ls.cat.estwrite.opts.affreg = 'mni';
matlabbatch{1}.ls.cat.estwrite.opts.biasstr = 0.5;
matlabbatch{1}.ls.pts.APP = 1070;
matlabbatch{1}.ls.pts.LASstr = 0.5;
matlabbatch{1}.ls.utstr = 0;
matlabbatch{1}.ls.istration.darteltpm =
{'D:/software/neuroscience/Matlab2016b/toolbox/spm12/toolbox/cat12/templates_1.50mm/Template_1_IXI555_MNI152.nii'};
matlabbatch{1}.ls.istration.shootingtpm =
{'D:/software/neuroscience/Matlab2016b/toolbox/spm12/toolbox/cat12/templates_1.50mm/Template_0_IXI555_MNI152_GS.nii'}
matlabbatch{1}.ls.str = 0;
matlabbatch{1}.ls.pts.vox = 1.5;
matlabbatch{1}.ls.stypes.fixed = [1 0.1];
matlabbatch{1}.ls.cat.estwrite.output.surface = 1;
matlabbatch{1}.ls.cat.estwrite.output.uromorphometrics = 1;
matlabbatch{1}.ls.cat.estwrite.output.ROImenu.atlases.lpba40 = 1;
matlabbatch{1}.ls.cat.estwrite.output.bra = 1;
matlabbatch{1}.ls.cat.estwrite.output.ROImenu.atlases.hammers = 1;
matlabbatch{1}.ls.cat.estwrite.output.GM.native = 0;
matlabbatch{1}.ls.cat.estwrite.d = 1;
matlabbatch{1}.ls.cat.estwrite.output.GM.dartel = 0;
matlabbatch{1}.ls.cat.estwrite.output.WM.native = 0;
matlabbatch{1}.ls.cat.estwrite.d = 1;
matlabbatch{1}.ls.cat.estwrite.output.WM.dartel = 0;
matlabbatch{1}.ls.cat.estwrite.output.bias.warped = 1;
matlabbatch{1}.ls.cat.estwrite.output.jacobian.warped = 1;
matlabbatch{1}.ls.cat.estwrite.output.warps = [0 0];
matlabbatch{2}.spm.spatial.smooth.data(1) = cfg_dep('CAT12: Segmentation: mwp1 Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','tiss', '()',{1}, '.','mwp', '()',{':'}));
matlabbatch{2}.spm.spatial.smooth.fwhm = [8 8 8];
matlabbatch{2}.spm.spatial.smooth.dtype = 0;
matlabbatch{2}.spm.spatial.smooth.im = 0;
matlabbatch{2}.spm.spatial.smooth.prefix = 's';
matlabbatch{3}.ls.calcvol.data_xml(1) = cfg_dep('CAT12: Segmentation: CAT Repor
t', substruct('.','val', '{}', {1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','catreport', '()',{':'}));
matlabbatch{3}.ls.calcvol.calcvol_TIV = 1;
matlabbatch{3}.ls.calcvol.calcvol_name = '';
matlabbatch{4}.ls.cat.stools.surfresamp.data_surf(1) = cfg_dep('CAT12: Segmentation: Left Thickness',
substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','lhthickness', '()',{':'}));
matlabbatch{4}.ls.cat._hemi = 1;
matlabbatch{4}.ls.cat.sh32k = 1;
matlabbatch{4}.ls.cat.stools.surfresamp.fwhm_surf = 15;
matlabbatch{4}.ls.cat.stools.surfresamp.nproc = 0;
matlabbatch{5}.ls.cat.stools.surfextract.data_surf(1) = cfg_dep('CAT12: Segmentation: Left Central Surface', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','lhcentral', '()',{':'}));
matlabbatch{5}.ls.cat.stools.surfextract.GI = 1;
matlabbatch{5}.ls.cat.stools.surfextract.FD = 0;
matlabbatch{5}.ls.cat.stools.surfextract.SD = 1;
matlabbatch{5}.ls.cat.stools.surfextract.nproc = 0;
matlabbatch{6}.ls.cat.stools.surf2roi.cdata{1}(1) = cfg_dep('CAT12: Segmentation: Left Thickness', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','lhthickness', '()',{':'}));
编辑于20180902

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。