覆盖图像并在每个像素位置显示较亮的像素 [英] overlay an image and show lighter pixel at each pixel location

查看:134
本文介绍了覆盖图像并在每个像素位置显示较亮的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个黑白图像,我希望将它们与最终图像合并,以显示两个图像中每个像素位置的较亮/白色像素.我尝试了以下代码,但是没有用.

I have two black and white images that I would like to merge with the final image showing the lighter/ white pixel at each pixel location in both images. I tried the following code but it did not work.

background=Image.open('ABC.jpg').convert("RGBA")
overlay=Image.open('DEF.jpg').convert("RGBA")
background_width=1936
background_height=1863
background_width,background_height = background.size
overlay_resize= overlay.resize((background_width,background_height),Image.ANTIALIAS)
background.paste(overlay_resize, None, overlay_resize)
overlay=background.save("overlay.jpg")
fn=np.maximum(background,overlay)
fn1=PIL.Image.fromarray(fn)
plt.imshow(fnl)
plt.show()

我收到的错误消息是无法处理此数据类型.任何人都可以提供的任何帮助或建议都将是巨大的.

The error message I get is cannot handle this data type. Any help or advice anyone could give would be great.

推荐答案

我认为您过于复杂了.您只需要读取两张图像并使其成为灰度numpy阵列,然后在每个位置选择两个像素中的较亮的颜色即可.

I think you are over-complicating things. You just need to read in both images and make them greyscale numpy arrays, then choose the lighter of the two pixels at each location.

因此,从这两张图片开始:

So starting with these two images:

#!/usr/local/bin/python3

import numpy as np
from PIL import Image

# Open two input images and convert to greyscale numpy arrays
bg=np.array(Image.open('a.png').convert('L'))
fg=np.array(Image.open('b.png').convert('L'))

# Choose lighter pixel at each location
result=np.maximum(bg,fg)

# Save
Image.fromarray(result).save('result.png')

您将获得:

关键字::numpy,Python,图像,图像处理,撰写,混合,混合模式,变亮,更亮,Photoshop,等效,变暗,覆盖.

Keywords: numpy, Python, image, image processing, compose, blend, blend mode, lighten, lighter, Photoshop, equivalent, darken, overlay.

这篇关于覆盖图像并在每个像素位置显示较亮的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆