0001 function img = read_avw_img(filename);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 fnimg=strcat(filename,'.img');
0012
0013 [dims,scales,bpp,endian,datatype] = read_avw_hdr(filename);
0014 fp=fopen(fnimg,'r',endian);
0015 if (datatype==4),
0016 dat=fread(fp,'short');
0017 elseif (datatype==2),
0018 dat=fread(fp,'char');
0019 elseif (datatype==8),
0020 dat=fread(fp,'int');
0021 elseif (datatype==64),
0022 dat=fread(fp,'double');
0023 elseif (datatype==16),
0024 dat=fread(fp,'float32');
0025 end
0026 fclose(fp);
0027
0028 nvox = prod(dims);
0029 if (length(dat)<nvox),
0030 error('Cannot open image as .img file does not contain as many voxels as the .hdr specifies');
0031 elseif (length(dat)>nvox),
0032 disp('WARNING::truncating .img data as it contains more voxels than specified in the .hdr');
0033 dat = dat(1:nvox);
0034 end
0035
0036
0037 if (dims(4)>1),
0038 img = reshape(dat,dims(1),dims(2),dims(3),dims(4));
0039 else
0040 img = reshape(dat,dims(1),dims(2),dims(3));
0041 end
0042
0043 clear dat;
0044
0045
0046
0047