A study of SPM 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.

datatypeconv.m
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Data type converter
%Convert the data type (uint8, int16, int32, float32, float64)
%Usage
%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
spm_jobman(‘run’,matlabbatch);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Download datatypeconv.m

コメントを残す

This site uses Akismet to reduce spam. Learn how your comment data is processed.