0001 function [AllVolume, VoxelSize, ImgFileList, Header] =rest_to4d(ADataDir)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 theFileList = dir(ADataDir);
0015 ImgFileList ={};
0016 for x = 3:size(struct2cell(theFileList),2)
0017 if strcmpi(theFileList(x).name(end-3:end), '.hdr')
0018 if strcmpi(theFileList(x).name(1:end-4), theFileList(x+1).name(1:end-4))
0019 ImgFileList=[ImgFileList; {theFileList(x).name(1:end-4)}];
0020 else
0021 error('*.{hdr,img} should be pairwise. Please re-examin them.');
0022 end
0023 end
0024 end
0025 clear theFileList;
0026
0027 if size(ImgFileList,1)<10,
0028 warning('There are too few time points.(i.e. The number of the time points is less than 10)');
0029 end
0030
0031
0032
0033 fprintf('\n\t Read 3D EPI functional images: "%s".', ADataDir);
0034 theDataType ='double';
0035 for x = 1:size(ImgFileList,1),
0036 rest_waitbar(x/size(ImgFileList,1), ...
0037 ImgFileList{x}, ...
0038 'Build 3D+time Dataset','Child','NeedCancelBtn');
0039 theFilename = fullfile(ADataDir,ImgFileList{x});
0040
0041
0042 [theOneTimePoint, VoxelSize, Header] = rest_readfile(theFilename);
0043
0044
0045 if theDataType=='uint16',
0046 AllVolume(:,:,:,x) = uint16(theOneTimePoint);
0047 elseif theDataType=='double',
0048 AllVolume(:,:,:,x) = (theOneTimePoint);
0049 else
0050 rest_misc('ComplainWhyThisOccur');
0051 end
0052 if x==1,
0053 tmpData=theOneTimePoint(0~=theOneTimePoint);
0054 if 0
0055 theDataType ='uint16';
0056 AllVolume =uint16(AllVolume);
0057 AllVolume(:,:,:,x) = uint16(theOneTimePoint);
0058 clear tmpData
0059
0060 AllVolume =repmat(AllVolume, [1,1,1, size(ImgFileList,1)]);
0061 else
0062
0063 theDataType ='double';
0064 AllVolume =repmat(AllVolume, [1,1,1, size(ImgFileList,1)]);
0065 end
0066 end
0067 if ~mod(x,5)
0068 fprintf('.');
0069 end
0070 end
0071 VoxelSize = VoxelSize';
0072 fprintf('\n');