在 python 中将两张图像相乘,其中一张图像的透明度为 50%

发布于 2025-01-13 13:12:03 字数 917 浏览 7 评论 0原文

我正在努力完成这项任务:将两张图像相乘,其中一张的透明度为 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 通道

纹理:

texture

结构:

facture

资源: res

我试图得到这个结果:

结果

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文