在 python 中将两张图像相乘,其中一张图像的透明度为 50%
我正在努力完成这项任务:将两张图像相乘,其中一张的透明度为 50%。 也就是说,要获得结果,就像在 Photoshop 中添加两个图层一样,为其中一个图层指定不透明度 = 50%,并将叠加模式设置为“正片叠底” 使用CV2. 乘法有效,但无法考虑 Alpha 通道。我将 Alpha 通道作为另一列添加到数组中。
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)
在这种情况下,图像会相乘,但不考虑 alpha 通道
纹理:
结构:
资源:
我试图得到这个结果:
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:
facture:
res:
I'm trying to get this result:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论