[英]overlay an image and show lighter pixel at each pixel location
我有两个黑白图像,我想将它们与最终图像合并,显示两个图像中每个像素位置的较亮/白色像素。 我尝试了以下代码,但没有用。
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()
我得到的错误消息是无法处理这种数据类型。 任何人都可以提供的任何帮助或建议都会很棒。
我认为你把事情复杂化了。 您只需要读取两个图像并使它们成为灰度numpy
数组,然后在每个位置选择两个像素中较numpy
一个。
所以从这两个图像开始:
#!/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、等效、变暗、叠加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.