0001 function [imageVol, lastfile] = GE_readVolume(startDir, passnum, volSize, depth, im_offset)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
0032 filenum = (passnum-1)*nZ + i;
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
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
0055 fseek(fid,im_offset,-1);
0056
0057 buffer = fread(fid,sliceSize,sprintf('int%d',depth));
0058
0059 imageVol(:,:,i) = reshape(buffer, nX, nY);
0060
0061
0062 status = fclose(fid);
0063
0064
0065 lastfile = imageFile;
0066 end
0067
0068 return