MATLAB-SMP12-fMRI-BOLD图像批量预处理脚本

MATLAB-SMP12-fMRI-BOLD图像批量预处理脚本

使用SMP12对BOLD图像进行批量预处理

直接上代码了
需要修改的参数有slice_number是扫描层数;TR重复时间;slice_order这里是间隔扫描;refslice1是中心位置的图像,根据slice_order确定;path是总目录,总目录下有应该是多个实验对象单独的文件夹,文件存储格式是分层存储每个被试文件夹里应该有结构像(其文件夹识别名称为MPRAGE)和功能像(其文件夹识别名称为BOLD)

clear
%%
spm('defaults', 'fmri');
spm_jobman('initcfg');
%%----------------------------------------------------------------------------------------------------------------------
% 设置基本参数,这个模块内的参数需要根据实际扫描参数进行修改
% slice_number是扫描层数;TR重复时间;slice_order这里是间隔扫描;refslice1是中心位置的图像,根据slice_order确定
slice_number = 36;
TR = 3.2;
TA = TR-TR\slice_number;
slice_order = [2:2:slice_number 1:2:slice_number];
refslice1 = 36;
%%----------------------------------------------------------------------------------------------------------------------
%%----------------------------------------------------------------------------------------------------------------------
%获取目录下文件夹名Folds
%path是总目录,总目录下有应该是多个实验对象单独的文件夹,文件存储格式是分层存储
path = 'E:\project\brain\test'; 
%%----------------------------------------------------------------------------------------------------------------------
d = dir(path);
isub = [d(:).isdir]; %# returns logical vector
Folds = {d(isub).name}';
Folds(ismember(Folds,{'.','..'})) = [];
%%
for n = 1:length(Folds)
    %1级文件夹
    path1=fullfile(path,Folds{n});
    d1 = dir(path1);
    isub1 = [d1(:).isdir]; %# returns logical vector
    Folds1 = {d1(isub1).name}';
    Folds1(ismember(Folds1,{'.','..'})) = [];
    %2级文件夹
    path2=fullfile(path1,Folds1{1});
    d2 = dir(path2);
    isub1 = [d2(:).isdir]; %# returns logical vector
    Folds2 = {d2(isub1).name}';
    Folds2(ismember(Folds2,{'.','..'})) = [];    
    %%----------------------------------------------------------------------------------------------------------------------
    %正则匹配namebold,namet1wi
    %每个被试文件夹里应该有结构像(其文件夹识别名称为MPRAGE)和功能像(其文件夹识别名称为BOLD)
    fbold = Folds2(~cellfun('isempty',regexp(Folds2, 'BOLD', 'match')));
    namebold = fbold{1};
    st1wi = Folds2(~cellfun('isempty',regexp(Folds2, 'MPRAGE', 'match')));
    namet1wi = st1wi{1};
    bold = fullfile(path2,namebold);
    t1wi = fullfile(path2,namet1wi);
   %%----------------------------------------------------------------------------------------------------------------------
    clear matlabbatch
    bold_list = spm_select('FPList', bold, '/*.IMA');  
    bold_list = cellstr(bold_list);
    t1wi_list = spm_select('FPList', t1wi, '/*.IMA'); 
    t1wi_list = cellstr(t1wi_list);
    %%
    matlabbatch{1}.spm.util.import.dicom.data = bold_list;%bold_list
    matlabbatch{1}.spm.util.import.dicom.root = 'series';
    matlabbatch{1}.spm.util.import.dicom.outdir = {path1};%path1
    matlabbatch{1}.spm.util.import.dicom.protfilter = '.*';
    matlabbatch{1}.spm.util.import.dicom.convopts.format = 'nii';
    matlabbatch{1}.spm.util.import.dicom.convopts.meta = 0;
    matlabbatch{1}.spm.util.import.dicom.convopts.icedims = 0;
    %%
    matlabbatch{2}.spm.util.import.dicom.data = t1wi_list;%t1wi_list
    matlabbatch{2}.spm.util.import.dicom.root = 'series';
    matlabbatch{2}.spm.util.import.dicom.outdir = {path1};%path1
    matlabbatch{2}.spm.util.import.dicom.protfilter = '.*';
    matlabbatch{2}.spm.util.import.dicom.convopts.format = 'nii';
    matlabbatch{2}.spm.util.import.dicom.convopts.meta = 0;
    matlabbatch{2}.spm.util.import.dicom.convopts.icedims = 0;
    %%
    matlabbatch{3}.spm.temporal.st.scans{1}(1) = cfg_dep('DICOM Import: Converted Images', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
    matlabbatch{3}.spm.temporal.st.nslices = slice_number; %slice_number
    matlabbatch{3}.spm.temporal.st.tr = TR; %TR
    matlabbatch{3}.spm.temporal.st.ta = TA; %TA
    matlabbatch{3}.spm.temporal.st.so = slice_order; %slice_order
    matlabbatch{3}.spm.temporal.st.refslice = refslice1; %refslice1
    matlabbatch{3}.spm.temporal.st.prefix = 'a';
    %%
    matlabbatch{4}.spm.spatial.realign.estwrite.data{1}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 1)', substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.sep = 4;
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.interp = 2;
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
    matlabbatch{4}.spm.spatial.realign.estwrite.eoptions.weight = '';
    matlabbatch{4}.spm.spatial.realign.estwrite.roptions.which = [2 1];
    matlabbatch{4}.spm.spatial.realign.estwrite.roptions.interp = 4;
    matlabbatch{4}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
    matlabbatch{4}.spm.spatial.realign.estwrite.roptions.mask = 1;
    matlabbatch{4}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
    %%
    matlabbatch{5}.spm.spatial.coreg.estimate.ref(1) = cfg_dep('Realign: Estimate & Reslice: Mean Image', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','rmean'));
    matlabbatch{5}.spm.spatial.coreg.estimate.source(1) = cfg_dep('DICOM Import: Converted Images', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
    matlabbatch{5}.spm.spatial.coreg.estimate.other = {''};
    matlabbatch{5}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
    matlabbatch{5}.spm.spatial.coreg.estimate.eoptions.sep = [4 2];
    matlabbatch{5}.spm.spatial.coreg.estimate.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
    matlabbatch{5}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];
    matlabbatch{6}.spm.spatial.preproc.channel.vols(1) = cfg_dep('Coregister: Estimate: Coregistered Images', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','cfiles'));
    matlabbatch{6}.spm.spatial.preproc.channel.biasreg = 0.001;
    matlabbatch{6}.spm.spatial.preproc.channel.biasfwhm = 60;
    matlabbatch{6}.spm.spatial.preproc.channel.write = [0 1];
    matlabbatch{6}.spm.spatial.preproc.tissue(1).tpm = {'D:\MATLAB\R2018b\toolbox\spm12\tpm\TPM.nii,1'};
    matlabbatch{6}.spm.spatial.preproc.tissue(1).ngaus = 1;
    matlabbatch{6}.spm.spatial.preproc.tissue(1).native = [1 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(1).warped = [0 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(2).tpm = {'D:\MATLAB\R2018b\toolbox\spm12\tpm\TPM.nii,2'};
    matlabbatch{6}.spm.spatial.preproc.tissue(2).ngaus = 1;
    matlabbatch{6}.spm.spatial.preproc.tissue(2).native = [1 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(2).warped = [0 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(3).tpm = {'D:\MATLAB\R2018b\toolbox\spm12\tpm\TPM.nii,3'};
    matlabbatch{6}.spm.spatial.preproc.tissue(3).ngaus = 2;
    matlabbatch{6}.spm.spatial.preproc.tissue(3).native = [1 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(3).warped = [0 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(4).tpm = {'D:\MATLAB\R2018b\toolbox\spm12\tpm\TPM.nii,4'};
    matlabbatch{6}.spm.spatial.preproc.tissue(4).ngaus = 3;
    matlabbatch{6}.spm.spatial.preproc.tissue(4).native = [1 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(4).warped = [0 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(5).tpm = {'D:\MATLAB\R2018b\toolbox\spm12\tpm\TPM.nii,5'};
    matlabbatch{6}.spm.spatial.preproc.tissue(5).ngaus = 4;
    matlabbatch{6}.spm.spatial.preproc.tissue(5).native = [1 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(5).warped = [0 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(6).tpm = {'D:\MATLAB\R2018b\toolbox\spm12\tpm\TPM.nii,6'};
    matlabbatch{6}.spm.spatial.preproc.tissue(6).ngaus = 2;
    matlabbatch{6}.spm.spatial.preproc.tissue(6).native = [0 0];
    matlabbatch{6}.spm.spatial.preproc.tissue(6).warped = [0 0];
    matlabbatch{6}.spm.spatial.preproc.warp.mrf = 1;
    matlabbatch{6}.spm.spatial.preproc.warp.cleanup = 1;
    matlabbatch{6}.spm.spatial.preproc.warp.reg = [0 0.001 0.5 0.05 0.2];
    matlabbatch{6}.spm.spatial.preproc.warp.affreg = 'mni';%%
    matlabbatch{6}.spm.spatial.preproc.warp.fwhm = 0;
    matlabbatch{6}.spm.spatial.preproc.warp.samp = 3;
    matlabbatch{6}.spm.spatial.preproc.warp.write = [0 1];
    matlabbatch{6}.spm.spatial.preproc.warp.vox = NaN;
    matlabbatch{6}.spm.spatial.preproc.warp.bb = [NaN NaN NaN
        NaN NaN NaN];
    %%
    matlabbatch{7}.spm.spatial.normalise.write.subj.def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{6}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
    matlabbatch{7}.spm.spatial.normalise.write.subj.resample(1) = cfg_dep('Realign: Estimate & Reslice: Realigned Images (Sess 1)', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{1}, '.','cfiles'));
    matlabbatch{7}.spm.spatial.normalise.write.woptions.bb = [-78 -112 -70
        78 76 85];
    matlabbatch{7}.spm.spatial.normalise.write.woptions.vox = [3 3 3];%%%333
    matlabbatch{7}.spm.spatial.normalise.write.woptions.interp = 4;
    matlabbatch{7}.spm.spatial.normalise.write.woptions.prefix = 'w';
    %%
    matlabbatch{8}.spm.spatial.normalise.write.subj.def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{6}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
    matlabbatch{8}.spm.spatial.normalise.write.subj.resample(1) = cfg_dep('Segment: Bias Corrected (1)', substruct('.','val', '{}',{6}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','channel', '()',{1}, '.','biascorr', '()',{':'}));
    matlabbatch{8}.spm.spatial.normalise.write.woptions.bb = [-78 -112 -70
        78 76 85];
    matlabbatch{8}.spm.spatial.normalise.write.woptions.vox = [1 1 1]; %%%111
    matlabbatch{8}.spm.spatial.normalise.write.woptions.interp = 4;
    matlabbatch{8}.spm.spatial.normalise.write.woptions.prefix = strcat(Folds{n}, 'sw');
    %%
    matlabbatch{9}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Write: Normalised Images (Subj 1)', substruct('.','val', '{}',{7}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
    matlabbatch{9}.spm.spatial.smooth.fwhm = [6 6 6]; %%%666
    matlabbatch{9}.spm.spatial.smooth.dtype = 0;
    matlabbatch{9}.spm.spatial.smooth.im = 0;
    matlabbatch{9}.spm.spatial.smooth.prefix = strcat(Folds{n}, 's');    
    %%
    spm_jobman('run', matlabbatch);
end   
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
asa983-11-smp-k8.bin是指CISCO公司的ASA设备的系统映像文件。该文件是ASA设备的操作系统文件,用于设备的引导和运行。 将这个文件下载到设备中,可以更新或安装ASA设备的操作系统版本。下载过程中,需要将asa983-11-smp-k8.bin文件保存在合适的位置,一般是设备的闪存(flash)或硬盘(hard disk)中。 下载的方法通常有两种:通过命令行界面(CLI)或通过远程管理工具,如Cisco ASDM。通过CLI下载,可以使用TFTP(Trivial File Transfer Protocol)或FTP(File Transfer Protocol)等协议来从FTP服务器或TFTP服务器中下载该文件。通过远程管理工具下载,可以通过图形用户界面(GUI)操作完成。无论使用哪种方法,都需要提供下载文件的路径和服务器的相关信息。 需要注意的是,在进行下载之前,应该确保设备与下载服务器之间的网络连接是正常的,同时也要确保下载设备的闪存或硬盘有足够的可用空间,以保存asa983-11-smp-k8.bin文件。 一旦下载完成,在设备的操作系统升级或安装过程中,可能需要执行一些额外的步骤,如备份设备的配置文件或重启设备等。 总之,asa983-11-smp-k8.bin是CISCO ASA设备的系统映像文件,可以通过CLI或远程管理工具下载到设备中,用于设备的操作系统升级或安装。下载前需要确保网络连接正常,下载设备有足够的可用空间,并在升级或安装过程中遵循相应的操作步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dr_yingli

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值