Home > vbmeg > external > bioelectromagnetism > avw_read.m

avw_read

PURPOSE ^

avw_read - read Analyze format data image (*.img)

SYNOPSIS ^

function [ avw, machine ] = avw_read(fileprefix,IMGorient,machine)

DESCRIPTION ^

 avw_read - read Analyze format data image (*.img)
 
 [ avw, machine ] = avw_read([fileprefix], [orient], [machine])
 
 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.

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [ avw, machine ] = avw_read(fileprefix,IMGorient,machine)
0002 
0003 % avw_read - read Analyze format data image (*.img)
0004 %
0005 % [ avw, machine ] = avw_read([fileprefix], [orient], [machine])
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 % Returned values:
0044 %
0045 % avw.hdr - a struct with image data parameters.
0046 % avw.img - a 3D matrix of image data (double precision).
0047 %
0048 % All going well, the returned 3D matrix in avw.img will
0049 % correspond with the default ANALYZE coordinate system,
0050 % which is a Left-handed coordinate system (radiological
0051 % orientation):
0052 %
0053 % X-Y plane is Transverse/Axial
0054 % X-Z plane is Coronal
0055 % Y-Z plane is Sagittal
0056 %
0057 % X axis runs from patient Right (low X) to patient Left (high X)
0058 % Y axis runs from Posterior (low Y) to Anterior (high Y)
0059 % Z axis runs from Inferior (low Z) to Superior (high Z)
0060 %
0061 % See also: avw_hdr_read, avw_img_read (both called by this function),
0062 %           avw_write, avw_img_write, avw_hdr_write,
0063 %           avw_view, avw_flip
0064 %
0065 
0066 
0067 % $Revision: 1332 $ $Date:: 2011-02-24 15:57:20 +0900#$
0068 
0069 % Licence:  GNU GPL, no express or implied warranties
0070 % History:  07/2003, Darren.Weber_at_radiology.ucsf.edu
0071 %                    The Analyze format is copyright
0072 %                    (c) Copyright, 1986-1995
0073 %                    Biomedical Imaging Resource, Mayo Foundation
0074 %                    - created this wrapper for avw_img_read, see
0075 %                      that function for extensive comments
0076 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0077 
0078 if ~exist('fileprefix','var'),
0079   [fileprefix, pathname, filterindex] = uigetfile('*.hdr','locate an Analyze .hdr file');
0080   if pathname, cd(pathname); end
0081   if ~fileprefix,
0082     error('no .hdr file specified');
0083   end
0084 end
0085 if ~exist('IMGorient','var'), IMGorient = ''; end
0086 if ~exist('machine','var'), machine = 'ieee-le'; end
0087 
0088 if findstr('.hdr',fileprefix),
0089     fileprefix = strrep(fileprefix,'.hdr','');
0090 end
0091 if findstr('.img',fileprefix),
0092     fileprefix = strrep(fileprefix,'.img','');
0093 end
0094 
0095 % MAIN
0096 
0097 fid = fopen(sprintf('%s.img',fileprefix),'r',machine);
0098 if fid < 0,
0099     msg = sprintf('...cannot open file %s.img\n\n',fileprefix);
0100     error(msg);
0101 else
0102     % avw_img_read will call avw_hdr_read also
0103     avw = avw_img_read(fileprefix,IMGorient,machine);
0104 end
0105 
0106 return

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005