Home > fmri > utils > GE2SPM > GE_convertVolume.m

GE_convertVolume

PURPOSE ^

SYNOPSIS ^

function status = GE_convertVolume(inDir,runnum,outName)

DESCRIPTION ^

 status = GE_convertVolume(inDir,runnum,outName)

GE_convertVolume

 Converts a series of GE slices into Analyze format for SPM.
 inDir is the name of the directory containing the first file of
 the series, e.g. 003
 runnum is the run number of the set you want to convert
 outName is used for naming the Analyze files
 status = 1 if there is an error.

 Souheil J. Inati  
 Dartmouth College
 May 2000
 souheil.inati@dartmouth.edu

 08/30/04  Petr Janata -- added some filename handling (checking for alternate firstfile)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status = GE_convertVolume(inDir,runnum,outName)
0002 %
0003 % status = GE_convertVolume(inDir,runnum,outName)
0004 %
0005 %GE_convertVolume
0006 %
0007 % Converts a series of GE slices into Analyze format for SPM.
0008 % inDir is the name of the directory containing the first file of
0009 % the series, e.g. 003
0010 % runnum is the run number of the set you want to convert
0011 % outName is used for naming the Analyze files
0012 % status = 1 if there is an error.
0013 %
0014 % Souheil J. Inati
0015 % Dartmouth College
0016 % May 2000
0017 % souheil.inati@dartmouth.edu
0018 %
0019 % 08/30/04  Petr Janata -- added some filename handling (checking for alternate firstfile)
0020 
0021 status = 1;
0022 
0023 if (nargin < 3)
0024         error('Not enough input arguments.')
0025         return
0026 end
0027 
0028 % Create the name of the first file in inDir
0029 firstfile = fullfile(inDir,'I.001');
0030 
0031 % On rare occassions, it might be the case that the I is lowercase.  Check to
0032 % see if this is the case
0033 if ~exist(firstfile)
0034   new_first = fullfile(inDir,'i.001');
0035   if exist(new_first)
0036     fprintf('Expected I.001, found i.001.  Using i.001\n');
0037     firstfile = new_first;
0038   else
0039     error(sprintf('Could not locate first file in image: %s\n', firstfile));
0040   end
0041 end 
0042 
0043 % Generate the Analyze header and other info from the first file
0044 [header, orient, im_offset, adwcount] = GE_createSPMHeader(firstfile);
0045 volSize =  [header.dim(2) header.dim(3) header.dim(4)];
0046 % Reorient the header to SPM orientation
0047 header = GE_reorientHeader(header, orient); 
0048 
0049 % Read in the volume
0050 [imageVol, lastfile] = GE_readVolume(inDir, runnum, volSize, header.bitpix, im_offset);
0051 
0052 % Reorient the volume to SPM orientation
0053 imageVol = GE_reorientImage(imageVol, orient);
0054 
0055 % Write the SPM header file
0056 outFile = strcat(outName,'.hdr');
0057 status = GE_writeSPMHeader(outFile,header);
0058 
0059 % Write out the Analyze File
0060 outFile = [outName sprintf('.img')];
0061 [fid,message] = fopen(outFile,'w');
0062 if (fid == -1)
0063   fprintf('Cannot Open %s for writing.\n',outFile);
0064   error(message);
0065 end
0066 
0067 fwrite(fid,reshape(imageVol,1,prod(size(imageVol))),'int16');
0068 status = fclose(fid);
0069 
0070 % Done with vol
0071 fprintf('Wrote %s.img.\n',outName);
0072 
0073 % Done
0074 fprintf('\nConversion Finished. \n');
0075 
0076 return

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