python - 使用PIL/Pillow对两张两张黑白图像进行OR操作

标签 python python-imaging-library

我想使用 PIL/Pillow 对两张图片执行 OR 操作。目前我正在做这样的事情:

def image_union(figure1, figure2):

    image1 = Image.open(figure1.visualFilename)
    image2 = Image.open(figure2.visualFilename)

    blended = Image.blend(image1, image2, .5)
    output = ImageOps.grayscale(blended)
    output.save('out-' + figure1.name + '-' + figure2.name + '.png')

    return blended

我想对这两张图片进行 OR:

enter image description here

enter image description here

但上面的操作返回以下内容,而我希望与星星相连的两个底部圆圈是全黑的:

enter image description here

最佳答案

使用ImageChops.darker而不是 Image.blend

blended = ImageChops.darker(image1, image2)

关于python - 使用PIL/Pillow对两张两张黑白图像进行OR操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36015118/

相关文章:

python - 为什么 [[]]*10 是在 python 中创建 10 个空列表的列表而不是 [[]*10] 的方法?

python - 我如何为 M2M Django 做分页

c++ - 如何同时处理一个 C++ 类的多个成员?

python - 有人可以帮我查明 Bcrypt 失败的原因(ValueError : Password must be non-empty)

python - 如何使用 PIL 将矩形图像映射到四边形?

python-3.x - 使用PIL加载图像时,是否可以忽略EXIF方向数据?

python - Scrapy 和 Pycharm - Stange 导入错误 - 没有名为 [在此处插入 scrapyproject 的名称] 的模块

python - Django - 如何安装 Python 图像库 (PIL)

python - 使用 Django 调整图像大小?

python - 将 ImageGrab 与 pywin32 的 GetWindowRect 中的 bbox 一起使用