Home > fmri > fsl > save_avw_hdr.m

save_avw_hdr

PURPOSE ^

SAVE_AVW_HDR(img,fname,vtype,vsize)

SYNOPSIS ^

function save_avw_hdr(img,fname,vtype,vsize)

DESCRIPTION ^

 SAVE_AVW_HDR(img,fname,vtype,vsize) 

  Create and save an analyse header file
   for either a 2D or 3D or 4D array (automatically determined).

  vtype is 1 character: 'b' unsigned byte, 's' short, 'i' int, 
                        'f' float, 'd' double
  vsize is a vector [x y z tr] containing the voxel sizes in mm and
  the tr in seconds  (defaults: [1 1 1 3])

  The filename (fname) must be a basename (no extensions)

  See also: SAVE_AVW, SAVE_AVW_IMG, READ_AVW, READ_AVW_HDR, READ_AVW_IMG
            SAVE_AVW_COMPLEX

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function save_avw_hdr(img,fname,vtype,vsize)
0002 % SAVE_AVW_HDR(img,fname,vtype,vsize)
0003 %
0004 %  Create and save an analyse header file
0005 %   for either a 2D or 3D or 4D array (automatically determined).
0006 %
0007 %  vtype is 1 character: 'b' unsigned byte, 's' short, 'i' int,
0008 %                        'f' float, 'd' double
0009 %  vsize is a vector [x y z tr] containing the voxel sizes in mm and
0010 %  the tr in seconds  (defaults: [1 1 1 3])
0011 %
0012 %  The filename (fname) must be a basename (no extensions)
0013 %
0014 %  See also: SAVE_AVW, SAVE_AVW_IMG, READ_AVW, READ_AVW_HDR, READ_AVW_IMG
0015 %            SAVE_AVW_COMPLEX
0016 
0017 % swap first and second argument in case save_avw_img convention is
0018 % used
0019 check=length(size(fname));
0020 if(check~=2)
0021    tmp=img;
0022    img=fname;
0023    fname=tmp;
0024 end
0025 
0026 % remove headerfile
0027 fname2=strcat(fname,'.hdr');
0028 tmpstr1=sprintf('!touch %s', fname2);
0029 tmpstr2=sprintf('!rm %s', fname2);
0030 
0031 eval(tmpstr1);
0032 eval(tmpstr2);
0033 
0034 % establish dynamic range
0035 imgmax=ceil(max(max(max(max(img)))));
0036 imgmin=floor(min(min(min(min(img)))));
0037 
0038 % create file to use as input into header program
0039 dims = [size(img) 1 1];
0040 
0041 if(nargin==2)
0042   vtype='s';
0043   vsize=[1 1 1 3];
0044 elseif(nargin==3)
0045   tmp=size(vtype);
0046   if(tmp(2)==1)
0047      vsize=[1 1 1 3];
0048   else
0049      vsize=vtype;
0050      if size(vsize,2)==3
0051     vsize=[vsize 3];
0052      end;
0053      vtype='s';
0054   end
0055 else
0056   tmp=size(vtype);
0057   if(tmp(2)==3)
0058      tmp2=vtype;
0059      vtype=vsize;
0060      vsize=tmp2;
0061   end
0062 end
0063 
0064 if (length(vsize)<3),
0065   vsize(3)=1;
0066 end
0067 if (length(vsize)<4),
0068   vsize(4)=3;
0069 end
0070 
0071 dtype=0;
0072 if (vtype=='b'),
0073   dtype=2;
0074 end
0075 if (vtype=='s'),
0076   dtype=4;
0077 end
0078 if (vtype=='i'),
0079   dtype=8;
0080 end
0081 if (vtype=='f'),
0082   dtype=16;
0083 end
0084 if (vtype=='d'),
0085   dtype=64;
0086 end
0087 
0088 
0089 % call avwcreatehd program
0090 
0091 tmp=sprintf('! $FSLDIR/etc/matlab/saveTOanalyze %d %d %d %d %6.4f %6.4f %6.4f %6.4f 0 0 0 %d %s  \n',dims(1),dims(2),dims(3),dims(4),vsize(1),vsize(2),vsize(3),vsize(4),dtype,fname);
0092 eval(tmp);
0093 disp(' ');
0094

Generated on Wed 20-Mar-2019 04:00:51 by m2html © 2003