avw_read - read Analyze format data image (*.img) [ avw, machine ] = avw_read([fileprefix], [orient], [machine], [verbose]) This function calls avw_hdr_read and avw_img_read, providing just a slightly easier command line function call. fileprefix - a string, the filename without the .img extension. A gui prompt appears if this argument is missing. orient - read a specified orientation, integer values: '', use header history orient field 0, transverse unflipped (LAS*) 1, coronal unflipped (LA*S) 2, sagittal unflipped (L*AS) 3, transverse flipped (LPS*) 4, coronal flipped (LA*I) 5, sagittal flipped (L*AI) where * follows the slice dimension and letters indicate +XYZ orientations (L left, R right, A anterior, P posterior, I inferior, & S superior). It is rare, but a dataset might be stored in the 3-5 orientations. For more information about orientation, see the documentation in the mri_toolbox doc directory and the extensive comments in avw_img_read and avw_hdr_read. See also the avw_flip function for any orthogonal reorientation (although this should not be necessary and must be done with great care, try not to invalidate the Analyze orientation specifications). machine - a string, see machineformat in fread for details. The default here is 'ieee-le' but the routine will automatically switch between little and big endian to read any such Analyze header. It reports the appropriate machine format and can return the machine value. verbose - the default is to output processing information to the command window. If verbose = 0, this will not happen. Returned values: avw.hdr - a struct with image data parameters. avw.img - a 3D matrix of image data (double precision). All going well, the returned 3D matrix in avw.img will correspond with the default ANALYZE coordinate system, which is a Left-handed coordinate system (radiological orientation): X-Y plane is Transverse/Axial X-Z plane is Coronal Y-Z plane is Sagittal X axis runs from patient Right (low X) to patient Left (high X) Y axis runs from Posterior (low Y) to Anterior (high Y) Z axis runs from Inferior (low Z) to Superior (high Z) See also: avw_hdr_read, avw_img_read (both called by this function), avw_write, avw_img_write, avw_hdr_write, avw_view, avw_flip
0001 function [ avw, machine ] = avw_read(fileprefix,IMGorient,machine,verbose) 0002 0003 % avw_read - read Analyze format data image (*.img) 0004 % 0005 % [ avw, machine ] = avw_read([fileprefix], [orient], [machine], [verbose]) 0006 % 0007 % This function calls avw_hdr_read and avw_img_read, providing 0008 % just a slightly easier command line function call. 0009 % 0010 % fileprefix - a string, the filename without the .img extension. 0011 % A gui prompt appears if this argument is missing. 0012 % 0013 % orient - read a specified orientation, integer values: 0014 % 0015 % '', use header history orient field 0016 % 0, transverse unflipped (LAS*) 0017 % 1, coronal unflipped (LA*S) 0018 % 2, sagittal unflipped (L*AS) 0019 % 3, transverse flipped (LPS*) 0020 % 4, coronal flipped (LA*I) 0021 % 5, sagittal flipped (L*AI) 0022 % 0023 % where * follows the slice dimension and letters indicate +XYZ 0024 % orientations (L left, R right, A anterior, P posterior, 0025 % I inferior, & S superior). 0026 % 0027 % It is rare, but a dataset might be stored in the 3-5 0028 % orientations. For more information about orientation, see the 0029 % documentation in the mri_toolbox doc directory and the 0030 % extensive comments in avw_img_read and avw_hdr_read. 0031 % See also the avw_flip function for any orthogonal 0032 % reorientation (although this should not be necessary 0033 % and must be done with great care, try not to invalidate 0034 % the Analyze orientation specifications). 0035 % 0036 % machine - a string, see machineformat in fread for details. 0037 % The default here is 'ieee-le' but the routine 0038 % will automatically switch between little and big 0039 % endian to read any such Analyze header. It 0040 % reports the appropriate machine format and can 0041 % return the machine value. 0042 % 0043 % verbose - the default is to output processing information to the command 0044 % window. If verbose = 0, this will not happen. 0045 % 0046 % Returned values: 0047 % 0048 % avw.hdr - a struct with image data parameters. 0049 % avw.img - a 3D matrix of image data (double precision). 0050 % 0051 % All going well, the returned 3D matrix in avw.img will 0052 % correspond with the default ANALYZE coordinate system, 0053 % which is a Left-handed coordinate system (radiological 0054 % orientation): 0055 % 0056 % X-Y plane is Transverse/Axial 0057 % X-Z plane is Coronal 0058 % Y-Z plane is Sagittal 0059 % 0060 % X axis runs from patient Right (low X) to patient Left (high X) 0061 % Y axis runs from Posterior (low Y) to Anterior (high Y) 0062 % Z axis runs from Inferior (low Z) to Superior (high Z) 0063 % 0064 % See also: avw_hdr_read, avw_img_read (both called by this function), 0065 % avw_write, avw_img_write, avw_hdr_write, 0066 % avw_view, avw_flip 0067 % 0068 0069 0070 % $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $ 0071 0072 % Licence: GNU GPL, no express or implied warranties 0073 % History: 07/2003, Darren.Weber_at_radiology.ucsf.edu 0074 % The Analyze format is copyright 0075 % (c) Copyright, 1986-1995 0076 % Biomedical Imaging Resource, Mayo Foundation 0077 % - created this wrapper for avw_img_read, see 0078 % that function for extensive comments 0079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0080 0081 if ~exist('fileprefix','var'), 0082 [fileprefix, pathname, filterindex] = uigetfile('*.hdr','locate an Analyze .hdr file'); 0083 if pathname, cd(pathname); end 0084 if ~fileprefix, 0085 error('no .hdr file specified'); 0086 end 0087 end 0088 if isempty(fileprefix), 0089 [fileprefix, pathname, filterindex] = uigetfile('*.hdr','locate an Analyze .hdr file'); 0090 if pathname, cd(pathname); end 0091 if ~fileprefix, 0092 error('no .hdr file specified'); 0093 end 0094 end 0095 0096 if ~exist('IMGorient','var'), IMGorient = ''; end 0097 if ~exist('machine','var'), machine = 'ieee-le'; end 0098 if ~exist('verbose','var'), verbose = 1; end 0099 0100 if isempty(IMGorient), IMGorient = ''; end 0101 if isempty(machine), machine = 'ieee-le'; end 0102 if isempty(verbose), verbose = 1; end 0103 0104 if findstr('.hdr',fileprefix), 0105 fileprefix = strrep(fileprefix,'.hdr',''); 0106 end 0107 if findstr('.img',fileprefix), 0108 fileprefix = strrep(fileprefix,'.img',''); 0109 end 0110 0111 % MAIN 0112 0113 fid = fopen(sprintf('%s.img',fileprefix),'r',machine); 0114 if fid < 0, 0115 msg = sprintf('...cannot open file %s.img\n\n',fileprefix); 0116 error(msg); 0117 else 0118 % avw_img_read will call avw_hdr_read also 0119 avw = avw_img_read(fileprefix,IMGorient,machine,verbose); 0120 end 0121 0122 return