我有两个黑白图像,我想与最终图像合并,显示两个图像中每个像素位置的较亮/白色像素。我尝试了以下代码,但它没有用。
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
数组,然后在每个位置选择两个像素的较亮部分。
所以从这两张图片开始:
#!/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,等效,变暗,叠加。