'multiply two images with 50% transparency of one of them in python

I'm struggling with the task: to multiply two images, 50% transparency of one of them. That is, to get the result, as if you add two layers in Photoshop, assign opacity = 50% to one of them and set the overlay mode "Multiply" Using cv2. Multiplication works, but it is not possible to take into account the alpha channel. I add the alpha channel as another column to the array.

texture = cv2.imread(test_texture)[0:2048, 0:2048]
facture = cv2.imread(facture_file)[0:2048, 0:2048]

texture_rgba = cv2.cvtColor(texture, cv2.COLOR_RGB2RGBA)
texture_rgba[:, :, 3] = 255

facture_rgba = cv2.cvtColor(facture, cv2.COLOR_RGB2RGBA)
facture_rgba[:, :, 3] = 120

res = multiply(texture_rgba.astype(float)/255 , facture_rgba.astype(float)/255)

cv2.imshow('res',res)
cv2.waitKey(0)

in this case, the images are multiplied, but without taking into account the alpha channel

texture:

texture

facture:

facture

res: res

I'm trying to get this result:

result



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source