matlab怎么使用 spm_vol,SPM12批量处理预处理数据
之前写过一篇https://www.jianshu.com/p/8f16cbbfd962,当时只是初步学会,还未熟练应用。
经过几次实践,现总结下通用的流程。
从一个问题出发:
问题:我想计算海马体积、内嗅皮层体积和内嗅皮层厚度等等。
思路:经调研,使用软件CAT12和FreeSurfer都可以处理,但FreeSurfer更加耗时,而且之前我也总结过CAT12与Freesurfer的对比https://github.com/Galory/daily-paper-neuroscience/blob/master/2018/08/29.md。决定选择使用CAT12。
过程:
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.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)就是要循环的次数,之后再把原来的代码放入这个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就可以了。
这里附上完整代码:
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
matlab怎么使用 spm_vol,SPM12批量处理预处理数据相关推荐
- matlab premnmx归一化函数的使用 1、premnmx 预处理数据使数据的最小值和最大值分别为-1和1. [PN,minp,maxp,TN,mint,maxt] = premnmx(P,T)
matlab premnmx归一化函数的使用 1.premnmx 预处理数据使数据的最小值和最大值分别为-1和1. [PN,minp,maxp,TN,mint,maxt] = premnmx(P,T) ...
- 用matlab批量对mat数据进行小波分析,批量输出图像并保存
用matlab批量对mat数据进行小波分析,批量输出图像并保存 代码 代码 clc; clear; A = cell(305 ,1);for i = 1:305 m = strcat(num2str( ...
- 利用MATLAB批量读写tif数据(Landsat78)
利用MATLAB批量读写tif数据(Landsat7&8) 代码来源于:批量读写 代码如下: clc;clear %% 读取NDVI-tif文件 file_path_N = 'E:\';% 图 ...
- GLASS数据预处理/MRT工具批量处理MODIS数据
GLASS数据预处理/MRT工具批量处理MODIS数据 准备工作 处理步骤 准备工作 1.数据准备:进行网站批量下载MRT数据,存储方式为数据–年份–天(例如GLASSFVC数据为8天分辨率,001. ...
- SNAP批量处理Sentinel-1A数据
SNAP批量处理Sentinel-1A数据 通常情况,使用SNAP处理单景影像有两种方式,一是在SNAP中按照预处理步骤一个功能一个功能地处理数据,另一种是创建流程图直接运行得到最终的结果. 然而,当 ...
- 利用matlab处理表格数据,/如何用matlab处理多个excel表格中的数据
excel最大可处理多少条数据 理论上可以处理59999条(行)数据 但是实际上同一个工作表中无法处理这么多数. Excel 怎样做一个客户多个数据的表 1.首先,简单描述问题,在如下的表格中想姓名一 ...
- matlab打开dat形式文件_matlab的各种数据读取(txt,dat,mat等格式),文件打开关闭...
MATLAB提供了多种方式从磁盘读入文件或将数据输入到工作空间,即读取数据,又叫导入数据:将工作空间的变量存储到磁盘文件中称为存写数据,又叫导出数据.至于选择哪种机制,则根据下面两个因素决定: ● 用 ...
- 图像+预处理+数据增强+总结
图像+预处理+数据增强+总结 图像与处理的中间和最终结果的不同版本,本身就是图像数据增强的一部分. 染色归一化 数据增强 Image augmentation for machine learning ...
- SAP QM QA08批量维护QMAT数据
SAP QM QA08批量维护QMAT数据 笔者所在的Y项目上有启用SAP QM模块,并且需要为每个物料激活超过5个以上不同的检验类型.大多数下项目上数据迁移阶段,物料主数据收集模板都会单独为QMAT ...
- SAP IQ09 可以批量查询序列号数据
SAP IQ09 可以批量查询序列号数据 事务代码IQ09,输入物料号等信息, 执行, 修改Layout,增加显示'批次'与'库存批次'字段信息, 回车, 正常情况下,物料的序列号主数据里,主批次字段 ...
最新文章
- lombok @Builder 是如何实现的
- linux php gd库安装,Linux系统gd库安装步骤说明
- 单目视觉标定:世界坐标系、相机坐标系、图像坐标系、像素坐标系——简单粗暴,粗暴
- 紫光物联linux登录账号,紫光展锐打造操作系统生态,赋能万物互联智能时代
- 【重难点】【JVM 01】OOM 出现的原因、方法区、类加载机制、JVM 中的对象
- algorithm头文件下的reverse()
- 标定小觅相机MYNT-EYE-S2110使用kalibr标定
- sccm2012 客户端推送安装故障解决一例
- 我不应该用计算机做题,中考答题涂卡必须用2B铅笔,看到电脑扫描的试卷,才明白有多重要...
- Echarts:Vue3中使用Echarts
- .NET反编译之manager,base.AutoScaleMode修复
- vector的哈希值 Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C
- (萌新的数电学习)用 VHDL语言设计一个异或门
- sketchup 图片转模型_紫天学习星球教学:如何在SU里把JPG图片变成三维模型
- laydate设置只选择年月
- winrar去掉烦人的广告 亲测有效
- Unity制作随机数字抽奖小案例
- FTP主动跟被动模式区别
- 设置共享文件夹之Mac技巧
- 迪文DGUS智能屏如何轻松实现3D动画