% settings (80% of masks must have a set voxel) gthresh = 0.8; % locate masks % - this could be enhanced by changing the pattern, e.g. using % 'SK*_TAL*.msk' to locate only masks of subjects beginning with SK in TAL space % - additionally, the startfolder and depth could be altered mskfiles = findfiles(pwd, '*.msk'); % alternative: mskfiles = findfiles([pwd '/SK*/VTC*/RUN*'], 'SK*TAL*.msk', 'depth=1'); % loop over masks msk = []; for mc = 1:numel(mskfiles) % clear old mask if ~isempty(msk) msk.ClearObject; end % load mask msk = xff(mskfiles{mc}); % for first mask if mc == 1 % copy data mask = uint16(msk.Mask); % otherwise else % add data mask = mask + uint16(msk.Mask); end end % threshold mask mask = uint8(mask >= uint16(ceil(gthresh * numel(mskfiles)))); % store msk.Mask = mask; % save msk.SaveAs; % clear object msk.ClearObject;