[dims,scales,bpp,endian] = READ_AVW_HDR(fname) Extracts the 4 dimensions (dims), 4 scales (scales) and bytes per pixel (bpp) for voxels contained in the Analyze or nifti header file (fname) Also returns endian = 'l' for little-endian or 'b' for big-endian NB: the name must be the basename of the file (no extensions) See also: READ_AVW, READ_AVW_IMG, SAVE_AVW, SAVE_AVW_HDR, SAVE_AVW_IMG
0001 function [dims,scales,bpp,endian,datatype] = read_avw_hdr(fname) 0002 % [dims,scales,bpp,endian] = READ_AVW_HDR(fname) 0003 % 0004 % Extracts the 4 dimensions (dims), 0005 % 4 scales (scales) and bytes per pixel (bpp) for voxels 0006 % contained in the Analyze or nifti header file (fname) 0007 % Also returns endian = 'l' for little-endian or 'b' for big-endian 0008 % NB: the name must be the basename of the file (no extensions) 0009 % 0010 % See also: READ_AVW, READ_AVW_IMG, SAVE_AVW, SAVE_AVW_HDR, SAVE_AVW_IMG 0011 0012 fnhdr=strcat(fname,'.hdr'); 0013 0014 % open file in big-endian 0015 endian='b'; 0016 fid=fopen(fnhdr,'r','b'); 0017 testval = fread(fid,1,'int32'); 0018 % check if this gives the correct header size - if not use little-endian 0019 if (testval~=348), 0020 fclose(fid); 0021 fid=fopen(fnhdr,'r','l'); 0022 endian='l'; 0023 testval = fread(fid,1,'int32'); 0024 if (testval~=348), 0025 disp('Can not read this file format'); 0026 return; 0027 end 0028 end 0029 % ditch the remaining initial header stuff 0030 dummy=fread(fid,36,'char'); 0031 % ditch dim[0] = No. dimensions 0032 dummy=fread(fid,1,'int16'); 0033 dims=fread(fid,4,'int16'); 0034 dummy=fread(fid,3,'int16'); 0035 dummy=fread(fid,14,'char'); 0036 datatype=fread(fid,1,'int16'); 0037 bpp=fread(fid,1,'int16'); 0038 dummy=fread(fid,2,'char'); 0039 dummy=fread(fid,1,'float'); 0040 scales=fread(fid,4,'float'); 0041 fclose(fid); 0042 return;