gpt4 book ai didi

python - 用python wand合成两个图像

转载 作者:太空狗 更新时间:2023-10-29 21:29:27 26 4
gpt4 key购买 nike

我需要使用 python wand(用于 python 的 image-magick 绑定(bind))来创建合成图像,但除了简单地将前景图像复制粘贴到背景图像之外,我在弄清楚如何做其他事情时遇到了一些麻烦。我想要的是,假设我有两张图片:

foreground

enter image description here

都是jpeg,我想去掉猫的白色背景,然后贴在房间上。其他 python 图像模块的答案,如 PIL,也很好,我只需要一些东西来自动化合成过程。提前致谢。

最佳答案

您可以使用 Image.composite() 实现此目的方法:

import urllib2

from wand.image import Image
from wand.display import display


fg_url = 'http://i.stack.imgur.com/Mz9y0.jpg'
bg_url = 'http://i.stack.imgur.com/TAcBA.jpg'

bg = urllib2.urlopen(bg_url)
with Image(file=bg) as bg_img:
fg = urllib2.urlopen(fg_url)
with Image(file=fg) as fg_img:
bg_img.composite(fg_img, left=100, top=100)
fg.close()
display(bg_img)
bg.close()

关于python - 用python wand合成两个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15144483/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com