I need to create stochastic boolean masks for a set of images. Each mask is an array of 1s with 6 random squares, in which the values are 0. The length of the squares are 56 pixels. The mask can be created with the following code:
mask = np.ones(shape=(3, h, w))
for _ in range(6):
x_coordinate = np.random.randint(0, w)
y_coordinate = np.random.randint(0, h)
mask[:, x_coordinate: x_coordinate + 56, y_coordinate: y_coordinate + 56] = 0
Now the tricky thing that I want to do is vectorize this process for a batch of images. Is this even possible? Right now, I'm just calling this function using a simple for-loop for each image in my batch, but I was wondering if there was a way to avoid the for-loop altogether.
ALSO: the mask must be different for each image in the batch (can't use the same mask for each image)