Home > fmri > utils > load_dir.m

load_dir

PURPOSE ^

[V] = load_dir(dir_name, filtstr, dims)

SYNOPSIS ^

function [V] = load_dir(dir_name, filtstr,dims)

DESCRIPTION ^

 [V] = load_dir(dir_name, filtstr, dims)

 Loads .img data from directory in dir_name

 Uses strmatch and filtstr to find all .img files that start with filtstr
 dims -- size of image volume (x,y,z).  If this argument is omitted, the
 script defaults to 64x64x27

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [V] = load_dir(dir_name, filtstr,dims)
0002 % [V] = load_dir(dir_name, filtstr, dims)
0003 %
0004 % Loads .img data from directory in dir_name
0005 %
0006 % Uses strmatch and filtstr to find all .img files that start with filtstr
0007 % dims -- size of image volume (x,y,z).  If this argument is omitted, the
0008 % script defaults to 64x64x27
0009 %
0010 
0011 % 05/18/00 PJ
0012 
0013 d = dir(dir_name);
0014 
0015 %
0016 %  Construct list of .img files
0017 %  Haven't figured out a one-liner to do this
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

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