Doxygen Source Code Documentation
GE_convertADW.m
Go to the documentation of this file.00001 function status = GE_convertADW(inDir,outStem,starttime,nvols)
00002 %
00003 % status = GE_convertADW(inDir,outStem,starttime,nvols)
00004 %
00005 %GE_convertADW
00006 %
00007 % Version 3.1
00008 %
00009 % Converts a series of GE slices acquired on the Advanced
00010 % Development Workstation into Analyze format for SPM.
00011 % inDir is the name of the first directory containing the
00012 % series, e.g. 003
00013 % outStem is the stem used for naming the Analyze files
00014 % starttime is the time point number to start
00015 % nvols is the number of volumes (time points) to convert
00016 %
00017 % status = 1, error
00018 % status = 0, all is well
00019 %
00020 % eg GE_convert('DATA/00023/003','converted',5,27)
00021 % Will convert 27 time points starting at the 5th time point
00022 % named converted_i0001.img, converted_i0002.img, ...,
00023 % converted_i0027.img and their associated header and mat files.
00024 %
00025 % Assumes the data is stored as 003/I.001 through 003/I.999 and
00026 % then 023/I.001 through 023/I.999, etc.
00027 % Remember to skip the template images ie 1 time point for the
00028 % first run. You don't need to do this for subsequent runs.
00029 %
00030 % Modified to use spm write functions
00031 % Modified to use spm_write_plane instead of spm_write_vol
00032 %
00033 % Souheil J. Inati
00034 % Dartmouth College
00035 % September 2001
00036 % souheil.inati@dartmouth.edu
00037 %
00038
00039 if (nargin < 4)
00040 error('Not enough input arguments.')
00041 return
00042 end
00043
00044 % Create the name of the first file in inDir
00045 firstfile = fullfile(inDir,'I.001');
00046
00047 % Read the Header from the first file
00048 [su_hdr,ex_hdr,se_hdr,im_hdr,pix_hdr,im_offset] = GE_readHeader(firstfile);
00049
00050 % The image Dimensions
00051 Nx = im_hdr.imatrix_X; % X Voxels
00052 Ny = im_hdr.imatrix_Y; % Y Voxels
00053 Nz = im_hdr.slquant; % Z Voxels
00054 volSize = [Nx Ny Nz];
00055
00056 % Is the first image the first or the last?
00057 if (se_hdr.end_loc - se_hdr.start_loc) > 0
00058 scandir = 1;
00059 else
00060 scandir = -1;
00061 end
00062
00063 % Compute the M matrix
00064 M = GE_createSPMmat(im_hdr,scandir);
00065
00066 % Create the template SPM volume structure
00067 V.fname = '';
00068 V.dim = [volSize spm_type('int16')]; % short ints
00069 V.mat = M;
00070 V.pinfo = [1 0 0]';
00071
00072 % Loop over the volumes until there is no more looping to be done.
00073 for i = 1:nvols
00074 passnum = starttime + i - 1;
00075
00076 % Read in the volume
00077 [imageVol, lastfile] = GE_readVolume(inDir, passnum, volSize, ...
00078 pix_hdr.img_depth, im_offset);
00079
00080 % Create analyze file
00081 vol_str = sprintf('000%d',i);
00082 vol_str = vol_str(length(vol_str)-3:length(vol_str));
00083 outName = [outStem sprintf('_i%s.img',vol_str)];
00084 V.fname = outName;
00085 V = spm_create_image(V);
00086
00087 % Write out the SPM Volume
00088 % Don't use spm_write_vol because that sets a scale factor.
00089 for i = 1:Nz
00090 V = spm_write_plane(V,squeeze(imageVol(:,:,i)),i);
00091 end
00092
00093 % Update to the screen
00094 fprintf('Wrote %s\n',outName);
00095
00096 end
00097
00098 % Done
00099 fprintf('\nConversion Finished. \n');
00100
00101 return