当前位置: 首页 > news >正文

使用SPM进行核磁数据预处理

前期准备:在MATLAB中安装SPM

下载SPM安装包并解压:SPM12 Software - Statistical Parametric Mapping

点击设置路径→添加并包含子文件夹...→找到刚才存放spm12的文件夹→选择文件夹→保存→关闭。

然后在matlab命令窗口中输入SPM即可启动,然后选择fMRI,也可以直接输入SPM fMRI,如果成功启动,说明安装成功

二、SPM单个被试预处理

略 

三、使用spm Batch 功能对核磁数据进行预处理

前几个tr存在匀场的过程(每个序列开始前的空扫时间,然后除以tr时间都得到tr数),在数据处理时需要把这部分内容去掉 ,去掉时需要确保是最开始的前几个tr,可以根据tr的名字进行辨别。

搭建batch框架

1.三个dicom import (t1加flanker1,flanker2)

二、时间矫正

点dependency选择数据,

Siemens磁共振ascending interleaved扫描特殊的地方,
如果总层数为偶数(如32层), 就从第2层开始, 接下来4、6、8…32,1、3、5…31, 此时slice order为[2:2:32 1:2:31]
如果总层数为奇数(如33层), 就从第1层开始, 接下来3、5、7…33,2、4、6…32, 此时slice order为[1:2:33 2:2:32]
其他扫描仪不存在这样的问题,都从第1层开始,32层:[1:2:31 2:2:32],33层:[1:2:33 2:2:32]

三、头动矫正

不要超过3mm

四、结构像与功能像对齐

五,分割

Segment将大脑图像分割为包括灰质、白质、脑脊液等结构
同时还可以生成参数文件,帮助接下来大脑空间标准化

六,标准化

voxel size改为[3 3 3]
中国人被试的bounding box建议[-90 -126 -72;90 90 108]

七、平滑

四、批处理核磁数据

为每个需要处理的被试建立输出文件夹

batch editor 窗口点击view,选择show.mcode,然后改一改代码

%-----------------------------------------------------------------------
% Job saved on 09-Aug-2025 18:04:43 by cfg_util (rev $Rev: 7345 $)
% spm SPM - SPM12 (7771)
% cfg_basicio BasicIO - Unknownparentdir    = 'D:\学习\批处理';  % 定义储存各被试源文件的上级文件夹
cd(parentdir);   % 进入这个上级文件夹
allsubjects  = dir('sub*');%查找该文件夹下的所有被试
numsubjects  = numel(allsubjects);       % 数找到了多少被试
for i=1:numsubjects    % 对每个被试进行循环cursubject = allsubjects(i).name;  % 找到当前被试的名字matlabbatch=cell(1);%% 查找结构像%  查找第i个被试的anat文件夹的绝对路径curanat = fullfile(parentdir,cursubject,'anat');%  查找第i个被试的anat下的所有dcm文件alldcms = dir(fullfile(curanat,'*.dcm'));% 再把alldcms中每个文件添加上绝对路径,这样才能让spm的batch找到文件alldcms = fullfile(curanat,{alldcms.name}');matlabbatch{1}.spm.util.import.dicom.data = alldcms;   % 把刚刚结构像的文件告诉给matlabbatch{1}.spm.util.import.dicom.data% 接下来指定anat的输出文件夹curanatout=fullfile('D:\学习\批处理\output',cursubject,'anat');if ~exist(curanatout,'dir')mkdir(curanatout);end%%%%matlabbatch{1}.spm.util.import.dicom.root = 'flat';
matlabbatch{1}.spm.util.import.dicom.outdir = {curanatout};
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;
%%%% 查找flanker1%  查找第i个被试的flanker1文件夹的绝对路径curflanker1 = fullfile(parentdir,cursubject,'flanker1');%  查找第i个被试的anat下的所有dcm文件alldcms = dir(fullfile(curflanker1,'*.dcm'));% 再把alldcms中每个文件添加上绝对路径,这样才能让spm的batch找到文件alldcms = fullfile(curflanker1,{alldcms.name}');matlabbatch{2}.spm.util.import.dicom.data = alldcms(5:end,1);  curfucout=fullfile('D:\学习\批处理\output',cursubject,'flanker1');if ~exist(curfucout,'dir')mkdir(curfucout);end%%
matlabbatch{2}.spm.util.import.dicom.root = 'flat';
matlabbatch{2}.spm.util.import.dicom.outdir =  {curfucout};
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;
%%%% 查找flanker2%  查找第i个被试的flanker2文件夹的绝对路径curflanker2 = fullfile(parentdir,cursubject,'flanker2');%  查找第i个被试的flanker2下的所有dcm文件alldcms = dir(fullfile(curflanker2,'*.dcm'));% 再把alldcms中每个文件添加上绝对路径,这样才能让spm的batch找到文件alldcms = fullfile(curflanker2,{alldcms.name}');matlabbatch{3}.spm.util.import.dicom.data = alldcms(5:end,1);%% 接下来指定flanker2的输出文件夹curfucout=fullfile('D:\学习\批处理\output',cursubject,'flanker2');if ~exist(curfucout,'dir')mkdir(curfucout);end%%
matlabbatch{3}.spm.util.import.dicom.root = 'flat';
matlabbatch{3}.spm.util.import.dicom.outdir = {curfucout};
matlabbatch{3}.spm.util.import.dicom.protfilter = '.*';
matlabbatch{3}.spm.util.import.dicom.convopts.format = 'nii';
matlabbatch{3}.spm.util.import.dicom.convopts.meta = 0;
matlabbatch{3}.spm.util.import.dicom.convopts.icedims = 0;
matlabbatch{4}.spm.temporal.st.scans{1}(1) = cfg_dep('DICOM Import: Converted Images', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
matlabbatch{4}.spm.temporal.st.scans{2}(1) = cfg_dep('DICOM Import: Converted Images', substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
matlabbatch{4}.spm.temporal.st.nslices = 32;
matlabbatch{4}.spm.temporal.st.tr = 2;
matlabbatch{4}.spm.temporal.st.ta = 1.9375;
matlabbatch{4}.spm.temporal.st.so = [2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31];
matlabbatch{4}.spm.temporal.st.refslice = 32;
matlabbatch{4}.spm.temporal.st.prefix = 'a';
matlabbatch{5}.spm.spatial.realign.estwrite.data{1}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 1)', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
matlabbatch{5}.spm.spatial.realign.estwrite.data{2}(1) = cfg_dep('Slice Timing: Slice Timing Corr. Images (Sess 2)', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{2}, '.','files'));
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.sep = 4;
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.interp = 2;
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
matlabbatch{5}.spm.spatial.realign.estwrite.eoptions.weight = '';
matlabbatch{5}.spm.spatial.realign.estwrite.roptions.which = [2 1];
matlabbatch{5}.spm.spatial.realign.estwrite.roptions.interp = 4;
matlabbatch{5}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
matlabbatch{5}.spm.spatial.realign.estwrite.roptions.mask = 1;
matlabbatch{5}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
matlabbatch{6}.spm.spatial.coreg.estimate.ref(1) = cfg_dep('Realign: Estimate & Reslice: Mean Image', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','rmean'));
matlabbatch{6}.spm.spatial.coreg.estimate.source(1) = cfg_dep('DICOM Import: Converted Images', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
matlabbatch{6}.spm.spatial.coreg.estimate.other = {''};
matlabbatch{6}.spm.spatial.coreg.estimate.eoptions.cost_fun = 'nmi';
matlabbatch{6}.spm.spatial.coreg.estimate.eoptions.sep = [4 2];
matlabbatch{6}.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{6}.spm.spatial.coreg.estimate.eoptions.fwhm = [7 7];
matlabbatch{7}.spm.spatial.preproc.channel.vols(1) = cfg_dep('Coregister: Estimate: Coregistered Images', substruct('.','val', '{}',{6}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','cfiles'));
matlabbatch{7}.spm.spatial.preproc.channel.biasreg = 0.001;
matlabbatch{7}.spm.spatial.preproc.channel.biasfwhm = 60;
matlabbatch{7}.spm.spatial.preproc.channel.write = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(1).tpm = {'D:\MATLAB\spm12\tpm\TPM.nii,1'};
matlabbatch{7}.spm.spatial.preproc.tissue(1).ngaus = 1;
matlabbatch{7}.spm.spatial.preproc.tissue(1).native = [1 0];
matlabbatch{7}.spm.spatial.preproc.tissue(1).warped = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(2).tpm = {'D:\MATLAB\spm12\tpm\TPM.nii,2'};
matlabbatch{7}.spm.spatial.preproc.tissue(2).ngaus = 1;
matlabbatch{7}.spm.spatial.preproc.tissue(2).native = [1 0];
matlabbatch{7}.spm.spatial.preproc.tissue(2).warped = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(3).tpm = {'D:\MATLAB\spm12\tpm\TPM.nii,3'};
matlabbatch{7}.spm.spatial.preproc.tissue(3).ngaus = 2;
matlabbatch{7}.spm.spatial.preproc.tissue(3).native = [1 0];
matlabbatch{7}.spm.spatial.preproc.tissue(3).warped = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(4).tpm = {'D:\MATLAB\spm12\tpm\TPM.nii,4'};
matlabbatch{7}.spm.spatial.preproc.tissue(4).ngaus = 3;
matlabbatch{7}.spm.spatial.preproc.tissue(4).native = [1 0];
matlabbatch{7}.spm.spatial.preproc.tissue(4).warped = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(5).tpm = {'D:\MATLAB\spm12\tpm\TPM.nii,5'};
matlabbatch{7}.spm.spatial.preproc.tissue(5).ngaus = 4;
matlabbatch{7}.spm.spatial.preproc.tissue(5).native = [1 0];
matlabbatch{7}.spm.spatial.preproc.tissue(5).warped = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(6).tpm = {'D:\MATLAB\spm12\tpm\TPM.nii,6'};
matlabbatch{7}.spm.spatial.preproc.tissue(6).ngaus = 2;
matlabbatch{7}.spm.spatial.preproc.tissue(6).native = [0 0];
matlabbatch{7}.spm.spatial.preproc.tissue(6).warped = [0 0];
matlabbatch{7}.spm.spatial.preproc.warp.mrf = 1;
matlabbatch{7}.spm.spatial.preproc.warp.cleanup = 1;
matlabbatch{7}.spm.spatial.preproc.warp.reg = [0 0.001 0.5 0.05 0.2];
matlabbatch{7}.spm.spatial.preproc.warp.affreg = 'mni';
matlabbatch{7}.spm.spatial.preproc.warp.fwhm = 0;
matlabbatch{7}.spm.spatial.preproc.warp.samp = 3;
matlabbatch{7}.spm.spatial.preproc.warp.write = [1 1];
matlabbatch{7}.spm.spatial.preproc.warp.vox = NaN;
matlabbatch{7}.spm.spatial.preproc.warp.bb = [NaN NaN NaNNaN NaN NaN];
matlabbatch{8}.spm.spatial.normalise.write.subj.def(1) = cfg_dep('Segment: Forward Deformations', substruct('.','val', '{}',{7}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','fordef', '()',{':'}));
matlabbatch{8}.spm.spatial.normalise.write.subj.resample(1) = cfg_dep('Realign: Estimate & Reslice: Resliced Images (Sess 1)', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{1}, '.','rfiles'));
matlabbatch{8}.spm.spatial.normalise.write.subj.resample(2) = cfg_dep('Realign: Estimate & Reslice: Resliced Images (Sess 2)', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','sess', '()',{2}, '.','rfiles'));
matlabbatch{8}.spm.spatial.normalise.write.woptions.bb = [-90 -126 -7290 90 108];
matlabbatch{8}.spm.spatial.normalise.write.woptions.vox = [3 3 3];
matlabbatch{8}.spm.spatial.normalise.write.woptions.interp = 4;
matlabbatch{8}.spm.spatial.normalise.write.woptions.prefix = 'w';
matlabbatch{9}.spm.spatial.smooth.data(1) = cfg_dep('Normalise: Write: Normalised Images (Subj 1)', substruct('.','val', '{}',{8}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('()',{1}, '.','files'));
matlabbatch{9}.spm.spatial.smooth.fwhm = [8 8 8];
matlabbatch{9}.spm.spatial.smooth.dtype = 0;
matlabbatch{9}.spm.spatial.smooth.im = 0;
matlabbatch{9}.spm.spatial.smooth.prefix = 's';
save(fullfile(parentdir,cursubject,'batch.mat'),'matlabbatch');spm_jobman('run',matlabbatch);
end

http://www.dtcms.com/a/323419.html

相关文章:

  • 【无标题】六边形结构在二维拓扑量子色动力学模型中确实具有独特优势,并构建完整的二维拓扑量子色动力学模型。
  • Redis三种特殊数据类型
  • 【深度学习2】logistic回归以及梯度下降
  • synchronized和RentrantLock用哪个?
  • Datawhale AI夏令营第三期,多模态RAG方向 Task2
  • 小白成长之路-Docker部署
  • 第二十八天(cookiesessiontokeny验证)
  • JVM性能调优的原则有哪些?
  • 深入理解C++构造函数与初始化列表
  • P1025 [NOIP 2001 提高组] 数的划分 题解
  • 【嵌入式DIY实例-Arduino篇】-水质检测系统
  • SQL面试题及详细答案150道(01-20) --- 基础概念与语法篇
  • python踩坑之识别错误...
  • 如何分析需求的可行性
  • Spring——Spring懒加载设计使用场景
  • 深入解析进程创建与终止机制
  • Linux 信号处理标志sa_flags详解
  • MPU-6050 超实用入门
  • 一文详解 C++ 继承体系
  • [C/C++线程安全]_[中级]_[多线程如何使用共享锁提升性能]
  • EP06:【DL 第二弹】动态计算图与梯度下降入门
  • 【C/C++】具有C风格的强制类型转换:显式类型转换、隐式类型转换,C语言强制类型转换
  • 第六章:【springboot】框架springboot原理、springboot父子工程与Swagger
  • 算法题(183):质量检测
  • 《答客难》东方朔
  • 网络原理-初识
  • FreeRTOS入门知识(初识RTOS任务调度)(三)
  • AVL树的四种旋转
  • 【Python 语法糖小火锅 · 第 4 涮】
  • 资深全栈工程师面试题总结