gra.png1067×522 175 KB

I want to make an image like (1). (Black is 0 and white is 1)
And I want to multiply this by the image like (2).
Finally, I want to combine the two pictures as follows.
(gradation * image1) + ((1 - gradation) * image2)
Is there any tool in pytorch(or cv2… or any fast python modules) that can create these gradation image?