% settings % - intensity threshold: values < 10 are treated as relative threshold! ithresh = 1.5; % - combine as sum or mask summask = true; % - if combine as sum, threshold ? subthresh = 0.75; % load MDM file mdm = xff('*.mdm', 'Please specify the MDM file to create a mask for...'); % loop over VTCS for vc = 1:size(mdm.XTC_RTC, 1) % load first VTC vtc = xff(mdm.XTC_RTC{vc, 1}); if ~isxff(vtc, 'vtc') clearxffobjects({vtc}); error('Not a VTC file!'); end % create mask if vc == 1 msk = xff('new:msk'); msk.Resolution = vtc.Resolution; msk.XStart = vtc.XStart; msk.XEnd = vtc.XEnd; msk.YStart = vtc.YStart; msk.YEnd = vtc.YEnd; msk.ZStart = vtc.ZStart; msk.ZEnd = vtc.ZEnd; % test layout else if msk.Resolution ~= vtc.Resolution || ... msk.XStart ~= vtc.XStart || ... msk.XEnd ~= vtc.XEnd || ... msk.YStart ~= vtc.YStart || ... msk.YEnd ~= vtc.YEnd || ... msk.ZStart ~= vtc.ZStart || ... msk.ZEnd ~= vtc.ZEnd vtc.ClearObject; msk.ClearObject; error(sprintf('VTC %d (%s) mismatches layout!', vc, mdm.XTC_RTC{vc, 1})); end end % compute the mean over time mvtc = squeeze(mean(vtc.VTCData)); % clear VTC vtc.ClearObject; % threshold if ithresh < 10 mask = (mvtc >= (ithresh .* mean(mvtc(:)))); else mask = (mvtc >= ithresh); end % store or combine if vc == 1 combined = mask; else % sum or and mask? if summask combined = combined + mask; else combined = combined & mask; end end end % combine across subjects required (summed mask) if summask % subject threshold combined = (combined >= (subthresh * size(mdm.XTC_RTC, 1))); end % set in mask msk.Mask = uint8(combined); % save mask msk.SaveAs; % clear msk and mdm msk.ClearObject; mdm.ClearObject;