0001 function saveinr(vol,fname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 fid=fopen(fname,'wb');
0018 if(fid==-1)
0019 error('You do not have permission to save mesh files.');
0020 end
0021 dtype=class(vol);
0022 if(islogical(vol) | strcmp(dtype,'uint8'))
0023 btype='unsigned fixed';
0024 dtype='uint8';
0025 bitlen=8;
0026 elseif(strcmp(dtype,'uint16'))
0027 btype='unsigned fixed';
0028 dtype='uint16';
0029 bitlen=16;
0030 elseif(strcmp(dtype,'float'))
0031 btype='float';
0032 dtype='float';
0033 bitlen=32;
0034 elseif(strcmp(dtype,'double'))
0035 btype='float';
0036 dtype='double';
0037 bitlen=64;
0038 else
0039 error('volume format not supported');
0040 end
0041 header=sprintf(['#INRIMAGE-4#{\nXDIM=%d\nYDIM=%d\nZDIM=%d\nVDIM=1\nTYPE=%s\n' ...
0042 'PIXSIZE=%d bits\nCPU=decm\nVX=1\nVY=1\nVZ=1\n'],size(vol),btype,bitlen);
0043 header=[header char(10*ones(1,256-4-length(header))) '##}' char(10)];
0044 fwrite(fid,header,'char');
0045 fwrite(fid,vol,dtype);
0046 fclose(fid);