前言
需要pip install pillow
代码
import os
from PIL import Image
from PIL.ImageChops import multiply
# 15. alpha混合
# out = (1.0-alpha)*image_1 + alpha*image_2
file_name1 = "parrot.png"
file_name2 = "hill.png"
file_path1 = os.path.join(images_dir,file_name1)
file_path2 = os.path.join(images_dir,file_name2)
im1 = Image.open(file_path1)
im2 = Image.open(file_path2)
im1 = im1.convert('RGBA')
im2 = im2.convert('RGBA')
# 大小必须相同
im2 = im2.resize((im1.width,im1.height),Image.BILINEAR)
im = Image.blend(im1,im2,alpha=0.5).show()
# 16. 图像的叠加: 将1个图像叠加到另一个图像的顶部
multiply(im1,im2).show()