之前寫(xiě)過(guò)一篇http://www.itdecent.cn/p/8f16cbbfd962,當(dāng)時(shí)只是初步學(xué)會(huì),還未熟練應(yīng)用。
經(jīng)過(guò)幾次實(shí)踐,現(xiàn)總結(jié)下通用的流程。
從一個(gè)問(wèn)題出發(fā):
問(wèn)題:我想計(jì)算海馬體積、內(nèi)嗅皮層體積和內(nèi)嗅皮層厚度等等。
思路:經(jīng)調(diào)研,使用軟件CAT12和FreeSurfer都可以處理,但FreeSurfer更加耗時(shí),而且之前我也總結(jié)過(guò)CAT12與Freesurfer的對(duì)比https://github.com/Galory/daily-paper-neuroscience/blob/master/2018/08/29.md。決定選擇使用CAT12。
過(guò)程:
1.先用一個(gè)人的數(shù)據(jù)保存一個(gè)對(duì)所有人的數(shù)據(jù)選擇好要進(jìn)行的處理,如下圖:

Tips:如果下一步的數(shù)據(jù)需要用到上一步的結(jié)果,當(dāng)你選擇時(shí)會(huì)有一個(gè)
Dependency供你選擇,如下圖:
2.選擇File->Save batch and script來(lái)保存一個(gè)對(duì)待處理的數(shù)據(jù)通用的batch文件,如下圖,我這里保存為batch.m和batch_job.m

3.編輯batch.m和batch_job.m這兩個(gè)文件,使用一個(gè)循環(huán)一次性把這些數(shù)據(jù)處理完。
于是在原本的batch.m文件里,添加如下的代碼實(shí)現(xiàn)循環(huán):
% By - Galory Email - 996377370a@gmail.com
% 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)就是要循環(huán)的次數(shù),之后再把原來(lái)的代碼放入這個(gè)for循環(huán)中的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
注意這里是根據(jù)自己的文件夾結(jié)構(gòu)來(lái)設(shè)置,比如我這里是這樣的:

會(huì)發(fā)現(xiàn)我的文件布局結(jié)構(gòu)是所有數(shù)據(jù)都在C:/Users/xuwhe/Desktop/t1/路徑下,因?yàn)樘崆敖o每個(gè)人編好了號(hào),每個(gè)人對(duì)應(yīng)一個(gè)數(shù)字的文件夾,這里就是1、2、3......24;而在這每個(gè)數(shù)字命名的文件夾之下就是待處理的.nii文件,這里采用的是通配符*.nii選取nii文件。
修改完畢,逐一核對(duì)一下該設(shè)置路徑的位置有沒(méi)有正確讀取,可以先拿一兩個(gè)人測(cè)試。
之后運(yùn)行batch_job.m就可以了。
這里附上完整代碼:
batch.m:
% By - Galory Email - 996377370a@gmail.com
% 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}.spm.tools.cat.estwrite.data = imgfile1;
matlabbatch{1}.spm.tools.cat.estwrite.nproc = 0;
matlabbatch{1}.spm.tools.cat.estwrite.opts.tpm = {'D:/software/neuroscience/Matlab2016b/toolbox/spm12/tpm/TPM.nii'};
matlabbatch{1}.spm.tools.cat.estwrite.opts.affreg = 'mni';
matlabbatch{1}.spm.tools.cat.estwrite.opts.biasstr = 0.5;
matlabbatch{1}.spm.tools.cat.estwrite.extopts.APP = 1070;
matlabbatch{1}.spm.tools.cat.estwrite.extopts.LASstr = 0.5;
matlabbatch{1}.spm.tools.cat.estwrite.extopts.gcutstr = 0;
matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.darteltpm = {'D:/software/neuroscience/Matlab2016b/toolbox/spm12/toolbox/cat12/templates_1.50mm/Template_1_IXI555_MNI152.nii'};
matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.shootingtpm = {'D:/software/neuroscience/Matlab2016b/toolbox/spm12/toolbox/cat12/templates_1.50mm/Template_0_IXI555_MNI152_GS.nii'};
matlabbatch{1}.spm.tools.cat.estwrite.extopts.registration.regstr = 0;
matlabbatch{1}.spm.tools.cat.estwrite.extopts.vox = 1.5;
matlabbatch{1}.spm.tools.cat.estwrite.extopts.restypes.fixed = [1 0.1];
matlabbatch{1}.spm.tools.cat.estwrite.output.surface = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.neuromorphometrics = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.lpba40 = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.cobra = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.ROImenu.atlases.hammers = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.GM.native = 0;
matlabbatch{1}.spm.tools.cat.estwrite.output.GM.mod = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.GM.dartel = 0;
matlabbatch{1}.spm.tools.cat.estwrite.output.WM.native = 0;
matlabbatch{1}.spm.tools.cat.estwrite.output.WM.mod = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.WM.dartel = 0;
matlabbatch{1}.spm.tools.cat.estwrite.output.bias.warped = 1;
matlabbatch{1}.spm.tools.cat.estwrite.output.jacobian.warped = 1;
matlabbatch{1}.spm.tools.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}.spm.tools.cat.tools.calcvol.data_xml(1) = cfg_dep('CAT12: Segmentation: CAT Report', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','catreport', '()',{':'}));
matlabbatch{3}.spm.tools.cat.tools.calcvol.calcvol_TIV = 1;
matlabbatch{3}.spm.tools.cat.tools.calcvol.calcvol_name = 'TIV.txt';
matlabbatch{4}.spm.tools.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}.spm.tools.cat.stools.surfresamp.merge_hemi = 1;
matlabbatch{4}.spm.tools.cat.stools.surfresamp.mesh32k = 1;
matlabbatch{4}.spm.tools.cat.stools.surfresamp.fwhm_surf = 15;
matlabbatch{4}.spm.tools.cat.stools.surfresamp.nproc = 0;
matlabbatch{5}.spm.tools.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}.spm.tools.cat.stools.surfextract.GI = 1;
matlabbatch{5}.spm.tools.cat.stools.surfextract.FD = 0;
matlabbatch{5}.spm.tools.cat.stools.surfextract.SD = 1;
matlabbatch{5}.spm.tools.cat.stools.surfextract.nproc = 0;
matlabbatch{6}.spm.tools.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