% mask_batch.m
% apply a single mask to many images (e.g. a series of functional images)
%
% 05/06/2004 - dara@psych.stanford.edu


% mask image
maskfile = spm_get(1,'IMAGE',{'Select mask'});

% images to apply mask on
maskTargets = spm_get(Inf,'IMAGE',{'Select images to apply mask'});

% directory to put masked images. will have same name as input images (maskedTargets)
outputDir = spm_get(-1,'',{'Select directory for output images'});

%f = spm_input('Evaluated Function',2,'s');
f = 'i1.*i2';

for image=1:length(maskTargets),

  P=[maskfile;maskTargets(image,:)];

  % get output file name
  [PATHSTR,NAME,EXT,VERSN] = fileparts(maskTargets{image});
  outfilename=[NAME EXT];
  Q = fullfile(outputDir{1},outfilename);

  Q = spm_imcalc_ui(P,Q,f)

end
