Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


GE_convertVolume.m

Go to the documentation of this file.
00001 function status = GE_convertVolume(inDir,runnum,outName)
00002 %
00003 % status = GE_convertVolume(inDir,runnum,outName)
00004 %
00005 %GE_convertVolume
00006 %
00007 % Version 3.1
00008 %
00009 % Converts a series of GE slices into Analyze format for SPM.
00010 % inDir is the name of the directory containing the first file of
00011 % the series, e.g. 003
00012 % runnum is the run number of the set you want to convert
00013 % outName is used for naming the Analyze files
00014 % status = 1 if there is an error.
00015 %
00016 % Modified to use spm functions
00017 %
00018 % Souheil J. Inati  
00019 % Dartmouth College
00020 % September 2001
00021 % souheil.inati@dartmouth.edu
00022 %
00023 
00024 status = 1;
00025 
00026 if (nargin < 3)
00027         error('Not enough input arguments.')
00028         return
00029 end
00030 
00031 % Create the name of the first file in inDir
00032 firstfile = fullfile(inDir,'I.001');
00033 
00034 % Read the Header from the first file
00035 [su_hdr,ex_hdr,se_hdr,im_hdr,pix_hdr,im_offset] = GE_readHeader(firstfile);
00036 
00037 % The image Dimensions
00038 Nx =  im_hdr.imatrix_X; % X Voxels
00039 Ny =  im_hdr.imatrix_Y; % Y Voxels
00040 Nz =  im_hdr.slquant;   % Z Voxels
00041 volSize = [Nx Ny Nz];
00042 
00043 % Read in the volume
00044 [imageVol, lastfile] = GE_readVolume(inDir, runnum, volSize, pix_hdr.img_depth, im_offset);
00045 
00046 % Is the first image the first or the last?
00047 if (se_hdr.end_loc - se_hdr.start_loc) > 0
00048   scandir = 1;
00049 else
00050   scandir = -1;
00051 end
00052 
00053 % Compute the M matrix
00054 M = GE_createSPMmat(im_hdr,scandir);
00055 
00056 % Create the SPM volume
00057 V.fname = outName;
00058 V.dim = [volSize spm_type('int16')]; % short ints
00059 V.mat = M;
00060 V.pinfo = [1 0 0]';
00061 V = spm_create_image(V);
00062 
00063 % Write out the SPM Volume
00064 % Don't use spm_write_vol because that sets a scale factor.
00065 for i = 1:Nz
00066   V = spm_write_plane(V,squeeze(imageVol(:,:,i)),i);
00067 end
00068 
00069 % Done with vol
00070 fprintf('Wrote %s.img.\n',outName);
00071 
00072 % Done
00073 fprintf('\nConversion Finished. \n');
00074 
00075 status = 0;
00076 
00077 return
00078 
00079 
 

Powered by Plone

This site conforms to the following standards: