📜  Python PIL |混合()方法

📅  最后修改于: 2022-05-13 01:54:20.515000             🧑  作者: Mango

Python PIL |混合()方法

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 PIL.Image.blend()方法通过在两个输入图像之间插值,使用恒定的 alpha 创建一个新图像。

图片1:

图片2:

# Importing Image module from PIL package 
from PIL import Image
  
# creating a image1 object and convert it to mode 'P'
im1 = Image.open(r"C:\Users\sadow984\Desktop\i2.PNG").convert('L')
  
# creating a image2 object and convert it to mode 'P'
im2 = Image.open(r"C:\Users\sadow984\Desktop\c2.PNG").convert('L')
  
# alpha is 0.0, a copy of the first image is returned
im3 = Image.blend(im1, im2, 0.0)
  
# to show specified image 
im3.show()

输出:

# Importing Image module from PIL package 
from PIL import Image
  
# creating a image1 object and convert it to mode 'P'
im1 = Image.open(r"C:\Users\sadow984\Desktop\i2.PNG").convert('L')
  
# creating a image2 object and convert it to mode 'P' 
im2 = Image.open(r"C:\Users\sadow984\Desktop\c2.PNG").convert('L')
  
# alpha is 1.0, a copy of the second image is returned
im3 = Image.blend(im1, im2, 0.0)
  
# to show specified image 
im3.show()

输出: