📜  Python PIL |复合()方法

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

Python PIL |复合()方法

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 PIL.Image.composite()方法通过使用透明蒙版混合图像来创建合成图像。在这里,蒙版是另一个在合成时保持透明的图像。
# Importing Image module from PIL package
from PIL import Image
  
# creating a image1 object and converting it to mode 'L'
im1 = Image.open(r"C:\Users\sadow984\Desktop\c2.PNG").convert('L')
  
im1.show()

显示图像1:

# Importing Image module from PIL package
from PIL import Image
  
# creating a image1 object and converting it to mode 'L'
im2 = Image.open(r"C:\Users\sadow984\Desktop\i2.PNG").convert('L')
im2.show()

显示图像2:

# Importing Image module from PIL package
from PIL import Image
  
# creating a image1 object and converting it to mode 'L'
mask = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG").convert('L')
mask.show()

显示蒙版图像:

# Importing Image module from PIL package
from PIL import Image
  
# creating a image1 object and converting it to mode 'L'
im1 = Image.open(r"C:\Users\sadow984\Desktop\c2.PNG").convert('L')
  
# creating a image2 object and converting it to mode 'L'
im2 = Image.open(r"C:\Users\sadow984\Desktop\i2.PNG").convert('L')
  
# creating a mask image object and converting it to mode 'L'
mask = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG").convert('L')
  
# compositing all the three images
im3 = Image.composite(im1, im2, mask)
  
# to show specified image 
im3.show()

输出: [合成图像]