【发布时间】:2016-05-07 10:39:04
【问题描述】:
编辑
任何有类似问题的人 - 我找到了另一个 SO 答案 here,这是一个很好的 Python 解决方案,它利用了 NumPy 的速度。
请考虑以下问题:
我有两张相同大小的图片。一个是具有不同不透明度的红色正方形:
第二个,一个蓝色的正方形,比红色的小,没有不透明但周围是白色的。
到目前为止,我正在为这个项目使用 OpenCV 的 python 绑定(在阅读了关于水印here 之后,我有这个:
redSquare = cv2.imread('redSquare.png', cv2.IMREAD_UNCHANGED)
(rH, rW) = redSquare.shape[:2]
blueSquare = cv2.imread('blueSquare.png')
(h, w) = blueSquare.shape[:2]
blueSquare = np.dstack([blueSquare, np.ones((h,w), dtype = 'uint8') * 255])
overlay = np.zeros((h,w,4), dtype = 'uint8')
overlay[0:rH, 0:rW] = redSquare
output = blueSquare .copy()
cv2.addWeighted(overlay, 0.5, output, 0.5, 0, output)
cv2.imwrite('imageAdded.png', output)
现在我通过使用加权相加了解到,我使用每个 0.5,而我真的想要每个 1.0,但是当我尝试增加两者的权重时,只有一个增加,另一个减少。
如果有人对我如何实现这一点有所了解,最好是在 Python 中,但如果你知道 C++ 中的一种方法,我相信我可以复制它。
谢谢。
【问题讨论】:
-
请提供带有alpha通道的红色图像。
-
好的,请稍等,我会编辑。
标签: python opencv image-manipulation