Home > bioelectromagnetism > ge_series2avw.m

ge_series2avw

PURPOSE ^

ge_series2avw - converts a GE series to Analyze

SYNOPSIS ^

function [ avw ] = ge_series2avw(examPath,seriesPath)

DESCRIPTION ^

 ge_series2avw - converts a GE series to Analyze
 
 avw = ge_series2avw(examPath,seriesPath)
 
 Converts a series of GE slices into an Analyze 
 avw struct (see avw_read), which can be output
 as an Analyze .hdr/.img pair using avw_write.
 
 examPath   - string path to an exam directory, 
              which contains series directories 
              below it
 seriesPath - the series to convert
              (integer or string argument)
 
 examPath is the name of the directory containing 
 the series subdirectories (e.g., series 1), which 
 contain the series image files (*.MR or I.*).  
 This function calls ge_series_read.
 
 The function will attempt to reorient the GE 
 3D volume into radiological orientation 
 (axial LAS, which is the default Analyze 
 orientation).  The resulting data should
 be SPM compatible when output with avw_write.
 
 This function is in alpha development (as of 03/2003) 
 although a prior version has been tested with 
 Ax,Sag,Cor slices (with slice direction going both 
 ways). It was also tested for oblique axial, but 
 not on double obliques or anything more complicated.  
 The function does not provide information for an 
 SPM compatible .mat file.
 
 see also ge_series_read,
          avw_view, avw_read, avw_write

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ avw ] = ge_series2avw(examPath,seriesPath)
0002 
0003 % ge_series2avw - converts a GE series to Analyze
0004 %
0005 % avw = ge_series2avw(examPath,seriesPath)
0006 %
0007 % Converts a series of GE slices into an Analyze
0008 % avw struct (see avw_read), which can be output
0009 % as an Analyze .hdr/.img pair using avw_write.
0010 %
0011 % examPath   - string path to an exam directory,
0012 %              which contains series directories
0013 %              below it
0014 % seriesPath - the series to convert
0015 %              (integer or string argument)
0016 %
0017 % examPath is the name of the directory containing
0018 % the series subdirectories (e.g., series 1), which
0019 % contain the series image files (*.MR or I.*).
0020 % This function calls ge_series_read.
0021 %
0022 % The function will attempt to reorient the GE
0023 % 3D volume into radiological orientation
0024 % (axial LAS, which is the default Analyze
0025 % orientation).  The resulting data should
0026 % be SPM compatible when output with avw_write.
0027 %
0028 % This function is in alpha development (as of 03/2003)
0029 % although a prior version has been tested with
0030 % Ax,Sag,Cor slices (with slice direction going both
0031 % ways). It was also tested for oblique axial, but
0032 % not on double obliques or anything more complicated.
0033 % The function does not provide information for an
0034 % SPM compatible .mat file.
0035 %
0036 % see also ge_series_read,
0037 %          avw_view, avw_read, avw_write
0038 %
0039 
0040 
0041 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0042 
0043 % Souheil J. Inati  <souheil.inati@nyu.edu> at 03/2003
0044 % Dartmouth College, May 2000
0045 %
0046 % Darren.Weber@flinders.edu.au, March 2003
0047 % - Substantially redesigned file handling and function
0048 %   call structures for integration with mri_toolbox at
0049 %   http://eeg.sf.net
0050 % - Requested permission to distribute code under GPL licence
0051 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0052 
0053 if (nargin < 2),
0054     doc ge_series2avw;
0055     error('...not enough input arguments.')
0056     return
0057 end
0058 
0059 
0060 
0061 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0062 % Read in the GE series header and image volume
0063 [ge, lastfile] = ge_series_read(examPath, seriesPath);
0064 
0065 % could try to use lastfile to create avw.fileprefix, but
0066 % it is too variable to be reliable
0067 % avw.fileprefix = lastfile
0068 
0069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0070 % Convert the GE series to an Analyze volume
0071 
0072 % Generate the Analyze header
0073 avw = ge_hdr2avw(ge);
0074 
0075 version = '[$Revision: 1.1 $]';
0076 fprintf('\nGE_SERIES2AVW [v%s]\n',version(12:16));  tic;
0077 
0078 % Check if ADW scan (not sure this is useful, DLW 03/2003)
0079 %if ge.hdr.image.user9 == 0, adwcount = 1;
0080 %else,                    adwcount = ge.hdr.image.user9;
0081 %end
0082 
0083 
0084 % Reorient the GE data into radiological orientation during assignment
0085 % of ge.img into avw.img (leave ge.img in original orientation)
0086 avw = ge_reorient(ge, avw); % see below
0087 
0088 % Write the Analyze files (not doing this)
0089 %avw_write(avw,outName);
0090 
0091 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0092 % This is the original write code, now replace with above (DLW)...
0093 
0094 %outFile = strcat(outName,'.hdr');
0095 %status = ge_writeSPMHeader(outFile,header);
0096 %outFile = [outName sprintf('.img')];
0097 %[fid,message] = fopen(outFile,'w');
0098 %if (fid == -1),
0099 %    fprintf('Cannot Open %s for writing.\n',outFile);
0100 %    error(message);
0101 %end
0102 %fwrite(fid,reshape(imageVol,1,prod(size(imageVol))),'int16');
0103 %status = fclose(fid);
0104 
0105 t=toc; fprintf('...done (%5.2f sec).\n',t);
0106 
0107 return
0108 
0109 
0110 
0111 
0112 
0113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0115 
0116 function [avw] = ge_reorient(ge, avw)
0117 
0118 %ge_reorient - Assigns Analyze header dimensions and volume based on GE orientation
0119 %
0120 % avw = ge_reorient(ge, avw)
0121 %
0122 % reorients the GE 3D volume to be radiological
0123 % orientation (axial LAS, which is SPM compatible)
0124 % based on the GE acquition orientation
0125 %
0126 % This has been tested with Ax,Sag,Cor with slices going
0127 % both ways.  Also for Oblique axial. Don't count on double
0128 % obliques or anything really fancy.
0129 %
0130 
0131 
0132 % Have looked over this orientation code carefully (DLW, 03/2003)
0133 % The above comments are from a previous version, note it
0134 % should be LAS, not RAS !!!!  I have found some inconsistencies
0135 % in the code (03/2003) and fixed it as best I can for now.  Further
0136 % testing with various volumes is required.
0137 
0138 
0139 series_description = deblank(char(ge.hdr.series.se_desc)'); % unreliable!
0140 
0141 fprintf('...checking GE series data orientation.\n');
0142 
0143 % Determine the GE orientation
0144 % orient is 1=axial, 2=sagittal, 3=coronal
0145 % with opposite sign if backwards slice order
0146 ras_start = char(ge.hdr.series.start_ras);
0147 ras_end   = char(ge.hdr.series.end_ras);
0148 if     strcmp(ras_start,'I') & strcmp(ras_end,'S'),
0149     fprintf('...slices are axial from inferior to superior.\n');
0150     orient =  1;
0151 elseif strcmp(ras_start,'S') & strcmp(ras_end,'I'),
0152     fprintf('...slices are axial from superior to inferior.\n');
0153     orient = -1;
0154 elseif strcmp(ras_start,'R') & strcmp(ras_end,'L'),
0155     fprintf('...slices are sagittal from right to left.\n');
0156     orient =  2;
0157 elseif strcmp(ras_start,'L') & strcmp(ras_end,'R'),
0158     fprintf('...slices are sagittal from left to right.\n');
0159     orient = -2;
0160 elseif strcmp(ras_start,'P') & strcmp(ras_end,'A'),
0161     fprintf('...slices are coronal from posterior to anterior.\n');
0162     orient =  3;
0163 elseif strcmp(ras_start,'A') & strcmp(ras_end,'P'),
0164     fprintf('...slices are coronal from anterior to posterior.\n');
0165     orient = -3;
0166 else,
0167     warning('GE orientation unknown!');
0168     orient = 0;
0169 end
0170 
0171 % Get the GE dimensions
0172 nX = ge.hdr.image.imatrix_X;
0173 nY = ge.hdr.image.imatrix_Y;
0174 nZ = ge.hdr.image.slquant;     % slice quantity (Nslices)
0175 pX = ge.hdr.image.pixsize_X;
0176 pY = ge.hdr.image.pixsize_Y;
0177 pZ = ge.hdr.image.slthick + ge.hdr.image.scanspacing;
0178 
0179 [vX vY vZ] = size(ge.img);
0180 
0181 % Reshape into axial radiological orientation (SPM compatible)
0182 % The default Analyze orientation is +X left, +Y anterior, +Z superior (LAS)
0183 
0184 switch orient,
0185     
0186 case  0, % Unknown Orientation
0187     
0188     warning('avw.img = ge.img without reorientation!\n');
0189     avw.img = ge.img;
0190     
0191 case {1, -1}, % Axial
0192     avw.hdr.dime.dim(2:4)    = [ nX nY nZ ];
0193     avw.hdr.dime.pixdim(2:4) = [ pX pY pZ ];
0194     
0195     avw.img = ge.img;
0196     if orient == 1, % Axial (I to S)
0197         % checked this (03/2003), not sure of L/R orient
0198         avw.img = flipdim(avw.img,2); % flip to P to A
0199     elseif orient == -1, % Axial (S to I)
0200         % have not checked this (03/2003)
0201         avw.img = flipdim(avw.img,2); % flip to P to A
0202         avw.img = flipdim(avw.img,3); % flip to I to S
0203     end
0204     
0205 case {2, -2}, % Sagittal
0206     
0207     avw.hdr.dime.dim(2:4)    = [ nZ nX nY ];
0208     avw.hdr.dime.pixdim(2:4) = [ pZ pX pY ];
0209     
0210     avw.img = permute(ge.img,[3 1 2]);
0211     if orient == 2, % Sagittal (R to L)
0212         % have not checked this (03/2003)
0213         avw.img = flipdim(avw.img,2); % flip to P to A?
0214         avw.img = flipdim(avw.img,3); % flip to I to S?
0215     elseif orient == -2, % Sagittal (L to R)
0216         % checked this (03/2003)
0217         avw.img = flipdim(avw.img,1); % flip to R to L
0218         avw.img = flipdim(avw.img,2); % flip to P to A
0219         avw.img = flipdim(avw.img,3); % flip to I to S
0220     end
0221     
0222 case {3, -3}, % Coronal
0223     
0224     avw.hdr.dime.dim(2:4)    = [ nX nZ nY ];
0225     avw.hdr.dime.pixdim(2:4) = [ pX pZ pY ];
0226     
0227     avw.img = permute(ge.img,[1 3 2]);
0228     if orient == 3, % Coronal (P to A)
0229         % have not checked this (03/2003), not sure of L/R orient
0230         avw.img = flipdim(avw.img,3); % flip to I to S?
0231     elseif orient == -3, % Coronal (A to P)
0232         % have not checked this (03/2003), not sure of L/R orient
0233         avw.img = flipdim(avw.img,2); % flip to P to A?
0234         avw.img = flipdim(avw.img,3); % flip to I to S?
0235     end
0236     
0237 end
0238 
0239 % Set the origin to the center of the volume (not sure this is valid, DLW)
0240 %avw.hdr.dime.originator = [floor(avw.hdr.dime.dim(2)/2) ...
0241 %                           floor(avw.hdr.dime.dim(3)/2) ...
0242 %                           floor(avw.hdr.dime.dim(4)/2) 0 0];
0243 
0244 avw.hdr.dime.glmax = max(max(max(avw.img)));
0245 avw.hdr.hist.orient = '0';
0246 
0247 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003