Here are two images in the drive, one is masked and another one is real image:
CodePudding user response:
your code just needs an additional /255
.
import cv2
import numpy as np
img = cv2.imread('im010.jpg')
mask = cv2.imread('im010.png')
img_foreground = np.array((mask/255)*(img/255))
cv2.imshow('', img_foreground)
cv2.waitKey()
that's because, when you look at the values, they're floats, right? and when they're floats, they must be in the range of 0.0 to 1.0, because that's what imshow
expects.
when you give it values scaled differently, it still maps 1.0 to white. any larger value is still white.