status = GE_convertADW(inDir,outStem,starttime,nvols) GE_convertADW Converts a series of GE slices acquired on the Advanced Development Workstation into Analyze format for SPM. inDir is the name of the first directory containing the series, e.g. 003 outStem is the stem used for naming the Analyze files starttime is the time point number to start nvols is the number of volumes (time points) to convert status = 1, error status = 0, all is well eg GE_convert('DATA/00023/003','converted',5,27) Will convert 27 time points starting at the 5th time point named converted_i0001.img, converted_i0002.img, ..., converted_i0027.img and their associated header files. Assumes the data is stored as 003/I.001 through 003/I.999 and then 023/I.001 through 023/I.999, etc. Remember to skip the template images ie 1 time point for the first run. You don't need to do this for subsequent runs. Souheil J. Inati Dartmouth College May 2000 souheil.inati@dartmouth.edu Modification history: 02/19/01 PJ Checks to see that volumes contain data, and quits the conversion if they don't
0001 function status = GE_convertADW(inDir,outStem,starttime,nvols) 0002 % 0003 % status = GE_convertADW(inDir,outStem,starttime,nvols) 0004 % 0005 %GE_convertADW 0006 % 0007 % Converts a series of GE slices acquired on the Advanced 0008 % Development Workstation into Analyze format for SPM. 0009 % inDir is the name of the first directory containing the 0010 % series, e.g. 003 0011 % outStem is the stem used for naming the Analyze files 0012 % starttime is the time point number to start 0013 % nvols is the number of volumes (time points) to convert 0014 % 0015 % status = 1, error 0016 % status = 0, all is well 0017 % 0018 % eg GE_convert('DATA/00023/003','converted',5,27) 0019 % Will convert 27 time points starting at the 5th time point 0020 % named converted_i0001.img, converted_i0002.img, ..., 0021 % converted_i0027.img and their associated header files. 0022 % 0023 % Assumes the data is stored as 003/I.001 through 003/I.999 and 0024 % then 023/I.001 through 023/I.999, etc. 0025 % Remember to skip the template images ie 1 time point for the 0026 % first run. You don't need to do this for subsequent runs. 0027 % 0028 % Souheil J. Inati 0029 % Dartmouth College 0030 % May 2000 0031 % souheil.inati@dartmouth.edu 0032 % 0033 % Modification history: 0034 % 0035 % 02/19/01 PJ Checks to see that volumes contain data, and quits the conversion 0036 % if they don't 0037 0038 status = 0; 0039 0040 if (nargin < 4) 0041 error('Not enough input arguments.') 0042 status = 1; 0043 return 0044 end 0045 0046 % Create the name of the first file in inDir 0047 firstfile = fullfile(inDir,'I.001'); 0048 0049 % Generate the Analyze header and other info from the first file 0050 [header, orient, im_offset, adwcount] = GE_createSPMHeader(firstfile); 0051 volSize = [header.dim(2) header.dim(3) header.dim(4)]; 0052 % Reorient the header to SPM orientation 0053 header = GE_reorientHeader(header, orient); 0054 0055 % Loop over the volumes until there is no more looping to be done. 0056 for i = 1:nvols 0057 passnum = starttime + i - 1; 0058 0059 % Create analyze file name 0060 % vol_str = sprintf('000%d',i); 0061 % vol_str = vol_str(length(vol_str)-3:length(vol_str)); 0062 outName = [outStem sprintf('_i%04d',i)]; 0063 0064 % Read in the volume 0065 [imageVol, lastfile] = GE_readVolume(inDir, passnum, volSize, ... 0066 header.bitpix, im_offset); 0067 0068 % Check to see that there is data in imageVol 0069 if isempty(imageVol) 0070 status = 1; 0071 break 0072 end 0073 0074 % Reorient the volume to SPM orientation 0075 imageVol = GE_reorientImage(imageVol, orient); 0076 0077 % Write the SPM header file 0078 outFile = strcat(outName,'.hdr'); 0079 status = GE_writeSPMHeader(outFile,header); 0080 0081 % Write out the Analyze File 0082 outFile = [outName sprintf('.img')]; 0083 [fid,message] = fopen(outFile,'w'); 0084 if (fid == -1) 0085 fprintf('Cannot Open %s for writing.\n',outFile); 0086 status = 1; 0087 error(message); 0088 end 0089 0090 fwrite(fid,reshape(imageVol,1,prod(size(imageVol))),'int16'); 0091 status = fclose(fid); 0092 0093 % Done with vol 0094 if (status == 0) 0095 fprintf('Wrote %s\n',outName); 0096 else 0097 error('Error converting %s\n', outName); 0098 end 0099 0100 end 0101 0102 % Done 0103 fprintf('\nConversion Finished. \n'); 0104 0105 return