Masking BGR image using a 2D mask Masking BGR image using a 2D mask numpy numpy

Masking BGR image using a 2D mask


Try to use a mask with the same shape as the image (actually, this will be a 3D mask). After generating your image_mask, do

# create mask with same dimensions as imagemask = numpy.zeros_like(image)# copy your image_mask to all dimensions (i.e. colors) of your imagefor i in range(3):     mask[:,:,i] = image_mask.copy()# apply the mask to your imagemasked_image = image[mask]

This way I avoid masked arrays in numpy for the time being.


Maybe this alternative approach would be easier in similar cases:

image[image_mask,:] = np.nan