Home > fmri > utils > old > GE2SPM.orig > GE_readVolume.m

GE_readVolume

PURPOSE ^

SYNOPSIS ^

function [imageVol, lastfile] = GE_readVolume(startDir, passnum, volSize, depth, im_offset)

DESCRIPTION ^

GE_readVolume
 
 [imageVo,l lastfile] = GE_readVolume(startDir, passnum, [nX nY nZ], depth, im_offset)

 reads the volume for passnum from the series which is stored
 starting in startDir and returns the name of the last file read

 Souheil J. Inati
 Dartmouth College
 Spring 2000

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [imageVol, lastfile] = GE_readVolume(startDir, passnum, volSize, depth, im_offset)
0002 %
0003 %GE_readVolume
0004 %
0005 % [imageVo,l lastfile] = GE_readVolume(startDir, passnum, [nX nY nZ], depth, im_offset)
0006 %
0007 % reads the volume for passnum from the series which is stored
0008 % starting in startDir and returns the name of the last file read
0009 %
0010 % Souheil J. Inati
0011 % Dartmouth College
0012 % Spring 2000
0013 %
0014 
0015 % initialize some variables
0016 nX = volSize(1);
0017 nY = volSize(2);
0018 nZ = volSize(3);
0019 sliceSize = nX*nY;
0020 imageVol = zeros(nX, nY, nZ);
0021 [path_stem, path_start] = fileparts(startDir);
0022 
0023 for i = 1:nZ
0024         % Make the filename
0025         filenum = (passnum-1)*nZ + i;   % file no.
0026         filep = ceil(filenum/999) - 1;
0027         filen = filenum - 999*filep;
0028         path_num = str2num(path_start) + 20*filep;
0029         path_now = sprintf('00%d',path_num);
0030         path_now = path_now(length(path_now)-2:length(path_now));
0031         path = fullfile(path_stem, path_now);
0032     stub = sprintf('00%d',filen);
0033     stub = stub(length(stub)-2:length(stub));
0034         imageFile = fullfile(path,['I.' stub]);
0035 
0036         % Open the file
0037     [fid,message] = fopen(imageFile,'r','b');
0038     if (fid == -1)
0039           fprintf('Cannot Open %s.\n',imageFile);
0040           passnum
0041       break
0042     end
0043 
0044     % Skip to the data
0045     fseek(fid,im_offset,-1);
0046     % Read the slice
0047     buffer = fread(fid,sliceSize,sprintf('int%d',depth));
0048     % append the slice to the imageSet
0049     imageVol(:,:,i) = reshape(buffer, nX, nY);
0050 
0051         % Close the file
0052     status = fclose(fid);
0053 
0054         % Set the lastfile
0055         lastfile = imageFile;
0056 end
0057 
0058 return

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