%datatypeconv.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%