I got the following things:
- an Image read with OpenCV (numpy array)
- a binary mask of the same size as the image
- a color string like
'red'
,'blue'
, etc
Q: how do i color the mask before i add it to the image? explicitly: how do i add color channels to a binary mask given a color string
I know how to add the mask (for example with cv2.addWeighted(mask,alpha,image,1-alpha,0,image)
) , but i dont know how to convert the binary mask to color space with a simple color 'string' as input. I know this works in PIL with rgb = PIL.ImageColor.getrgb(color)
, but i dont know how to do this with OpenCV!
EDIT: i managed to get the colors in channel tuples (0,0,0) and currently my workaround is:
mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB)
mask[np.where((mask == [1,1,1]).all(axis = 2))] = color
cv2.addWeighted(mask,alpha,image,1-alpha,0,image)
but the problem is, now the image is greyscale with a colored map... So the first line needs to be exchanged