I'm trying to apply a binary mask to an RGB image with numpy
I found this https://stackoverflow.com/a/26843467/4628384 but I don't have permissions to write a comment yet. Anyway I'm running into a problem; Any help much appreciated.
def masktoRGB(self,image,image_mask):
# create mask with same dimensions as image
mask = np.zeros_like(image)
# copy your image_mask to all dimensions (i.e. colors) of your image
for i in range(3):
mask[:,:,i] = image_mask.copy()
# apply the mask to your image
# tried to swap axes, not a solution
#image = image.swapaxes(0,1)
#this gives the error:
masked_image = image[mask]
print(mask.shape)
print(image.shape)
print(image_mask.shape)
return masked_image
this gives me:
IndexError: index 213 is out of bounds for axis 0 with size 212
print output:
(188, 212, 3) (188, 212, 3) (188, 212)
image and image_mask are the same image, except the first is RGB and the second is mode L