%loop through image and apply mask randomly for i = 1 : step.h : input.h - window.h-step.h for j = 1 : step.w : input.w - window.w-step.w % extract part of the image window.current = input.image(i : i + window.h - 1, j : j + window.w - 1, :); % apply mask randomly color = round(rand(1) * 5) + 1; mask.current = mask.(fn{color}); % apply end end