Home > fmri > fsl > save_avw_img.m

save_avw_img

PURPOSE ^

SAVE_AVW_IMG(img,fname,vtype)

SYNOPSIS ^

function save_avw_img(img,fname,vtype);

DESCRIPTION ^

  SAVE_AVW_IMG(img,fname,vtype)

  Save an array (img) as an analyse file (only the .img) 
   for either a 2D or 3D or 4D array (automatically determined)
 
  vtype is a single character string: 'b' (unsigned) byte, 's' short, 
                                      'i' int, 'f' float, or 'd' double

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

  See also: SAVE_AVW, SAVE_AVW_HDR, SAVE_AVW_COMPLEX,
            READ_AVW, READ_AVW_HDR, READ_AVW_IMG, READ_AVW_COMPLEX

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function save_avw_img(img,fname,vtype);
0002 %  SAVE_AVW_IMG(img,fname,vtype)
0003 %
0004 %  Save an array (img) as an analyse file (only the .img)
0005 %   for either a 2D or 3D or 4D array (automatically determined)
0006 %
0007 %  vtype is a single character string: 'b' (unsigned) byte, 's' short,
0008 %                                      'i' int, 'f' float, or 'd' double
0009 %
0010 %  The filename (fname) must be a basename (no extensions)
0011 %
0012 %  See also: SAVE_AVW, SAVE_AVW_HDR, SAVE_AVW_COMPLEX,
0013 %            READ_AVW, READ_AVW_HDR, READ_AVW_IMG, READ_AVW_COMPLEX
0014 %
0015 
0016 % swap first and second argument in case save_avw_img convention is
0017 % used
0018 check=length(size(fname));
0019 if(check~=2)
0020    tmp=img;
0021    img=fname;
0022    fname=tmp;
0023 end
0024 
0025 fnimg=strcat(fname,'.img');
0026 
0027 fp=fopen(fnimg,'w');
0028 dims = size(img);
0029 
0030 %% DEFUNCT
0031 %% flip y dimension to be consistent with MEDx
0032 %% dat=flipdim(img,2);
0033 
0034 dat = img;
0035 dat = reshape(dat,prod(dims),1);
0036 
0037 switch vtype
0038   case 'd'
0039     vtype2='double';
0040   case 'f'
0041     vtype2='float';
0042   case 'i'
0043     vtype2='int32';
0044   case 's'
0045     vtype2='short';
0046   case 'b'
0047     vtype2='uchar';
0048 end;
0049 
0050 fwrite(fp,dat,vtype2);
0051 fclose(fp);
0052

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003