我正在尝试将两个图像叠加在一起,以模拟使用 MatLab 叠加的图像的结果。不幸的是,我无法为这个项目使用 MatLab,而且我使用混合的方法没有给出预期的结果。
关于如何仅使用 Python 完成图像叠加的任何想法?
这是我尝试使用混合方法的代码部分。但是,它会产生发光效果:
# Blend method from
# http://www.deepskycolors.com/archive/2010/04/21/formulas-for-Photoshop-blending-modes.html
target = img_1 / 255.0
blend = img_2 / 255.0
output_img = (target > 0.5) * (1 - (1-2*(target-0.5)) * (1-blend)) + (target <= 0.5) * ((2*target) * blend)
output_img = output_img*255.0
这是我开始使用的两张图片:
最佳答案
你可以用 Pillow 做到这一点:
from PIL import Image
im1 = Image.open("background.jpg")
im2 = Image.open("bird.jpg")
newimg = Image.blend(im1, im2, alpha=0.5)
newimg.save("blended.jpg")
我得到这个结果:
关于python - 使用 Python 将两个图像叠加在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56469966/