A study of SPM8 script: Data type converter

I’m learning how to make a script for SPM.
Below is a simple script which converts the data type of the image file.
It should work for both SPM8 and SPM5.

%Data type converter
%Convert the data type (uint8, int16, int32, float32, float64)
%Change the value at line 26(options.dtype) to the datatype you want.
%Kiyotaka Nemoto 2 Jan 2010
P = spm_select(Inf,’image’,'Select Files to be converted’);
for i=1:size(P,1)
ref = deblank(P(i,:));
[pth,nam,ext] = spm_fileparts(ref);
odir = pth;
cvt = ['d' nam '.nii'];
matlabbatch{1}.spm.util.imcalc.input = {ref};
matlabbatch{1}.spm.util.imcalc.output = cvt;
matlabbatch{1}.spm.util.imcalc.outdir = {odir};
matlabbatch{1}.spm.util.imcalc.expression = ‘i1′;
matlabbatch{1}.spm.util.imcalc.options.dmtx = 0;
matlabbatch{1}.spm.util.imcalc.options.mask = 0;
matlabbatch{1}.spm.util.imcalc.options.interp = 1;
matlabbatch{1}.spm.util.imcalc.options.dtype = 4;
% uint8=2; int16=4; int32=8; float32=16; float64=64

Download datatypeconv.m

Print Friendly, PDF & Email


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください