0001 function dat=readinr(fname)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 fid=fopen(fname,'rb');
0020 s=fread(fid,256,'uchar');
0021
0022 s=char(s)';
0023
0024 if(regexp(s,'#INRIMAGE-4')~=1)
0025 error('INRIMAGE header was not found')
0026 end
0027
0028 nx=regexp(s,'XDIM\s*=\s*([0-9]+)','tokens');
0029 if(length(nx))
0030 nx=str2num(nx{1}{1});
0031 else
0032 error('no XDIM found');
0033 end
0034
0035 ny=regexp(s,'YDIM\s*=\s*([0-9]+)','tokens');
0036 if(length(ny))
0037 ny=str2num(ny{1}{1});
0038 else
0039 error('no YDIM found');
0040 end
0041
0042 nz=regexp(s,'ZDIM\s*=\s*([0-9]+)','tokens');
0043 if(length(nz))
0044 nz=str2num(nz{1}{1});
0045 else
0046 error('no ZDIM found');
0047 end
0048
0049 nv=regexp(s,'VDIM\s*=\s*([0-9]+)','tokens');
0050 if(length(nv))
0051 nv=str2num(nv{1}{1});
0052 else
0053 nv=1;
0054 end
0055
0056 type=regexp(s,'TYPE=([a-z ]+)','tokens');
0057 if(length(type))
0058 type=type{1}{1};
0059 else
0060 error('no TYPE found');
0061 end
0062
0063 pixel=regexp(s,'PIXSIZE=([0-9]+)','tokens');
0064 if(length(pixel))
0065 pixel=str2num(pixel{1}{1});
0066 else
0067 error('no PIXSIZE found');
0068 end
0069
0070
0071
0072
0073 if(strcmp(type,'unsigned fixed') & pixel==8)
0074 dtype='uint8';
0075 elseif(strcmp(type,'unsigned fixed') & pixel==16)
0076 dtype='uint16';
0077 elseif(strcmp(type,'float') & pixel==32)
0078 dtype='float';
0079 elseif(strcmp(type,'float') & pixel==64)
0080 dtype='double';
0081 else
0082 error('volume format not supported');
0083 end
0084
0085
0086 dat=fread(fid,nx*ny*nz*nv,dtype);
0087 fclose(fid);
0088
0089 if(nv==1)
0090 dat=reshape(dat,[nx,ny,nz]);
0091 else
0092 dat=reshape(dat,[nx,ny,nz,nv]);
0093 end