Home > fmri > utils > GE2SPM > GE_readVolume.m

GE_readVolume

PURPOSE ^

SYNOPSIS ^

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

DESCRIPTION ^

GE_readVolume
 
 [imageVol, 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
 May 2000
 souheil.inati@dartmouth.edu

 Modifications:

 02/19/01 PJ  If file is not found, imageVol is set to empty and function
 returns.
 08/30/04 PJ  Improved (generalized) file name construction

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 % [imageVol, 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 % May 2000
0013 % souheil.inati@dartmouth.edu
0014 %
0015 % Modifications:
0016 %
0017 % 02/19/01 PJ  If file is not found, imageVol is set to empty and function
0018 % returns.
0019 % 08/30/04 PJ  Improved (generalized) file name construction
0020 
0021 
0022 % initialize some variables
0023 nX = volSize(1);
0024 nY = volSize(2);
0025 nZ = volSize(3);
0026 sliceSize = nX*nY;
0027 imageVol = zeros(nX, nY, nZ);
0028 [path_stem, path_start] = fileparts(startDir);
0029 
0030 for i = 1:nZ
0031         % Make the filename
0032         filenum = (passnum-1)*nZ + i;   % file no.
0033         filep = ceil(filenum/999) - 1;
0034         filen = filenum - 999*filep;
0035         path_num = str2num(path_start) + 20*filep;
0036     path_now = sprintf('%03d',path_num);
0037         path = fullfile(path_stem, path_now);
0038     stub = sprintf('%03d', filen);
0039     if exist(fullfile(path,sprintf('I.%s', stub)))
0040       imageFile = fullfile(path,sprintf('I.%s', stub));
0041     elseif exist(fullfile(path,sprintf('i.%s', stub)))
0042       imageFile = fullfile(path,sprintf('i.%s', stub));
0043     end
0044     
0045         % Open the file
0046     [fid,message] = fopen(imageFile,'r','b');
0047     if (fid == -1)
0048           fprintf('Cannot Open %s.\n',imageFile);
0049           passnum
0050       imageVol = [];
0051       return
0052     end
0053 
0054     % Skip to the data
0055     fseek(fid,im_offset,-1);
0056     % Read the slice
0057     buffer = fread(fid,sliceSize,sprintf('int%d',depth));
0058     % append the slice to the imageSet
0059     imageVol(:,:,i) = reshape(buffer, nX, nY);
0060 
0061         % Close the file
0062     status = fclose(fid);
0063 
0064         % Set the lastfile
0065         lastfile = imageFile;
0066 end
0067 
0068 return

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