avw_write - write Analyze files (*.img & *.hdr) This function is a wrapper for avw_hdr_write and avw_img_write. avw_write(avw,fileprefix,[IMGorient],[machine],[verbose]) where the input avw is a struct (see avw_read): avw.hdr - a struct with image data parameters. avw.img - a 3D matrix of image data (double precision). fileprefix - a string, the filename without the .img extension. If empty, may use avw.fileprefix IMGorient - optional int; force writing of specified orientation, as follows: [], if empty, will use avw.hdr.hist.orient field 0, transverse/axial unflipped (default, radiological) 1, coronal unflipped 2, sagittal unflipped 3, transverse/axial flipped 4, coronal flipped 5, sagittal flipped This function will set avw.hdr.hist.orient and write the image data in a corresponding order. This function is in alpha development, it has not been exhaustively tested (as of 07/2003). See the comments and notes throughout avw_hdr_read and avw_img_read for more information and documentation on the Analyze orientation options. Orientations 3-5 are NOT recommended! They are part of the Analyze format, but only used in Analyze for faster raster graphics during movies. (Also see the copy of the Analyze 7.5 format pdf in the mri_toolbox doc folder; although the code is largely self sufficient, that pdf is the authoritative description). machine - optional string; see machineformat in fread for details. The default here is 'ieee-le'. verbose - the default is to output processing information to the command window. If verbose = 0, this will not happen. Tip: to change the data type, set avw.hdr.dime.datatype to: 1 Binary ( 1 bit per voxel) 2 Unsigned character ( 8 bits per voxel) 4 Signed short ( 16 bits per voxel) 8 Signed integer ( 32 bits per voxel) 16 Floating point ( 32 bits per voxel) 32 Complex, 2 floats ( 64 bits per voxel), not supported 64 Double precision ( 64 bits per voxel) 128 Red-Green-Blue (128 bits per voxel), not supported See also: avw_read, avw_hdr_write, avw_img_write avw_hdr_read, avw_img_read avw_view
0001 function avw_write(avw, fileprefix, IMGorient, machine, verbose) 0002 0003 % avw_write - write Analyze files (*.img & *.hdr) 0004 % 0005 % This function is a wrapper for 0006 % avw_hdr_write and avw_img_write. 0007 % 0008 % avw_write(avw,fileprefix,[IMGorient],[machine],[verbose]) 0009 % 0010 % where the input avw is a struct (see avw_read): 0011 % 0012 % avw.hdr - a struct with image data parameters. 0013 % avw.img - a 3D matrix of image data (double precision). 0014 % 0015 % fileprefix - a string, the filename without the .img 0016 % extension. If empty, may use avw.fileprefix 0017 % 0018 % IMGorient - optional int; force writing of specified 0019 % orientation, as follows: 0020 % 0021 % [], if empty, will use avw.hdr.hist.orient field 0022 % 0, transverse/axial unflipped (default, radiological) 0023 % 1, coronal unflipped 0024 % 2, sagittal unflipped 0025 % 3, transverse/axial flipped 0026 % 4, coronal flipped 0027 % 5, sagittal flipped 0028 % 0029 % This function will set avw.hdr.hist.orient and write the 0030 % image data in a corresponding order. This function is in 0031 % alpha development, it has not been exhaustively tested 0032 % (as of 07/2003). 0033 % 0034 % See the comments and notes throughout avw_hdr_read and 0035 % avw_img_read for more information and documentation on 0036 % the Analyze orientation options. Orientations 3-5 are 0037 % NOT recommended! They are part of the Analyze format, 0038 % but only used in Analyze for faster raster graphics 0039 % during movies. (Also see the copy of the Analyze 7.5 0040 % format pdf in the mri_toolbox doc folder; although 0041 % the code is largely self sufficient, that pdf is the 0042 % authoritative description). 0043 % 0044 % machine - optional string; see machineformat in fread 0045 % for details. The default here is 'ieee-le'. 0046 % 0047 % verbose - the default is to output processing information to 0048 % the command window. If verbose = 0, this will not 0049 % happen. 0050 % 0051 % Tip: to change the data type, set avw.hdr.dime.datatype to: 0052 % 0053 % 1 Binary ( 1 bit per voxel) 0054 % 2 Unsigned character ( 8 bits per voxel) 0055 % 4 Signed short ( 16 bits per voxel) 0056 % 8 Signed integer ( 32 bits per voxel) 0057 % 16 Floating point ( 32 bits per voxel) 0058 % 32 Complex, 2 floats ( 64 bits per voxel), not supported 0059 % 64 Double precision ( 64 bits per voxel) 0060 % 128 Red-Green-Blue (128 bits per voxel), not supported 0061 % 0062 % See also: avw_read, avw_hdr_write, avw_img_write 0063 % avw_hdr_read, avw_img_read 0064 % avw_view 0065 % 0066 0067 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $ 0068 0069 % Licence: GNU GPL, no express or implied warranties 0070 % History: 05/2002, Darren.Weber@flinders.edu.au 0071 % The Analyze 7.5 format is copyright 0072 % (c) Copyright, 1986-1995 0073 % Biomedical Imaging Resource, Mayo Foundation 0074 % This code attempts to respect the integrity of 0075 % the format, although no guarantee is given that 0076 % it has been exhaustively tested for compatibility 0077 % with Analyze software (it should be though). 0078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0079 0080 0081 %------------------------------------------------------------------------ 0082 % Check inputs 0083 0084 if ~exist('avw','var'), 0085 doc avw_write; 0086 msg = sprintf('\n...no input avw.\n'); 0087 error(msg); 0088 elseif isempty(avw), 0089 msg = sprintf('\n...empty input avw.\n'); 0090 error(msg); 0091 elseif ~isfield(avw,'img'), 0092 msg = sprintf('\n...empty input avw.img\n'); 0093 error(msg); 0094 end 0095 0096 if ~exist('fileprefix','var'), 0097 if isfield(avw,'fileprefix'), 0098 if ~isempty(avw.fileprefix), 0099 fileprefix = avw.fileprefix; 0100 else 0101 fileprefix = []; 0102 end 0103 else 0104 fileprefix = []; 0105 end 0106 end 0107 if isempty(fileprefix), 0108 [fileprefix, pathname, filterindex] = uiputfile('*.hdr','Specify an output Analyze .hdr file'); 0109 if pathname, cd(pathname); end 0110 if ~fileprefix, 0111 doc avw_write; 0112 error('no output .hdr file specified'); 0113 end 0114 end 0115 0116 if findstr('.hdr',fileprefix), 0117 % fprintf('AVW_WRITE: Removing .hdr extension from ''%s''\n',fileprefix); 0118 fileprefix = strrep(fileprefix,'.hdr',''); 0119 end 0120 if findstr('.img',fileprefix), 0121 % fprintf('AVW_WRITE: Removing .img extension from ''%s''\n',fileprefix); 0122 fileprefix = strrep(fileprefix,'.img',''); 0123 end 0124 0125 if ~exist('IMGorient','var'), IMGorient = ''; end 0126 if ~exist('machine','var'), machine = 'ieee-le'; end 0127 if ~exist('verbose','var'), verbose = 1; end 0128 0129 if isempty(IMGorient), IMGorient = ''; end 0130 if isempty(machine), machine = 'ieee-le'; end 0131 if isempty(verbose), verbose = 1; end 0132 0133 0134 %------------------------------------------------------------------------ 0135 % MAIN 0136 0137 version = '[$Revision: 1.1 $]'; 0138 0139 avw_img_write(avw,fileprefix,IMGorient,machine,verbose); 0140 0141 % MUST write header after the image, to ensure any 0142 % orientation changes during image write are saved 0143 % in the header. The header is saved by avw_img_write, so it's 0144 % not necessary to call it here. If it were called here, it 0145 % would be called as such: 0146 % avw_hdr_write(avw,fileprefix,machine,verbose); 0147 0148 return