I have to masks, for example these:
I want to merge them in one image, but the first and the second mask must have different colors, so the desired result is:
I know I can convert them both to BGR colorspace, then replace colors and merge them like this:
img1 = cv2.cvtColor(mask1, cv2.COLOR_GRAY2BGR)
img1[np.where((img1==[255, 255, 255]).all(axis=2))] = [0, 0, 255]
img2 = cv2.cvtColor(mask2, cv2.COLOR_GRAY2BGR)
img2[np.where((img2==[255, 255, 255]).all(axis=2))] = [0, 255, 0]
img = cv2.bitwise_or(img1, img2)
But it seems like there should be a simpler and more optimal way to do that. Is there such way?


