function runROIImageMaskMode(args)

subjects = args.subjects;
   
nSubjects = size(subjects);
sessionlist = args.sessionList;


for s = 1:nSubjects
    subjectStruct{s}.dir = fullfile(args.basedir,cell2mat(subjects(s)));
    d = load(fullfile(subjectStruct{s}.dir,'results','SPM.mat'));
    subjectStruct{s}.des = d.SPM;
    subjectStruct{s}.name = cell2mat(subjects(s));
    subjectStruct{s}.roiFile = ui_selectRoiImage(...
        sprintf('Select ROI Files for %s',subjectStruct{s}.name),...
        fullfile(subjectStruct{s}.dir,'results','roi'));
end



for s = 1:nSubjects
    % load image data
   
    disp('fetching volume definitions, please wait');
    subjectStruct{s}.volumes = spm_vol(getImageFileList(subjectStruct{s}.dir,sessionlist,args.mask));

    disp('computing volume values, please wait');
    
    rawData = calculateRoiImageData(subjectStruct{s}.volumes,subjectStruct{s}.roiFile);
    % calculate psth
    pstopts.des = subjectStruct{s}.des;
    pstopts.eventList = args.eventList;
    pstopts.sessionList = sessionlist;
    
    assignin('base','pstopts',pstopts);
    assignin('base','rawData',rawData);

    disp('computing psth');
    subjectStruct{s}.psth    = calculatePST(args.timeline,pstopts,rawData);
    disp('done');
end

assignin('base','subjectStruct',subjectStruct);

end