0001 function [V] = load_dir(dir_name, filtstr,dims)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 d = dir(dir_name);
0014
0015
0016
0017
0018
0019
0020 fidx = find(~[d.isdir]);
0021
0022 fnames = char(d.name);
0023
0024 img_idx = [];
0025 for f = fidx
0026 if findstr(fnames(f,:),'.img')
0027 img_idx(end+1) = f;
0028 end
0029 end
0030
0031 if nargin > 1
0032 img_idx = img_idx(strmatch(filtstr,fnames(img_idx,:)));
0033 end
0034
0035 nimg = length(img_idx);
0036 disp(sprintf('Found %d .img files', nimg));
0037
0038 if nargin < 3
0039 dims = [64 64 27];
0040 end
0041
0042 V = zeros(dims(1),dims(2),dims(3),nimg);
0043
0044 disp('Loading files ...')
0045
0046 for iimg = 1:nimg
0047 curr_fname = fullfile(dir_name, deblank(fnames(img_idx(iimg),:)));
0048 fid = fopen(curr_fname,'rb','l');
0049 if fid == -1
0050 error(sprintf('Could not open file %s', curr_fname))
0051 end
0052 V(:,:,:,iimg) = reshape(fread(fid,inf,'integer*2'), size(V,1),size(V,2),size(V,3));
0053 fclose(fid);
0054 end