Python PIL | ImageChops.darker() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。
ImageChops.darker()
方法用于逐像素比较两个图像,并返回包含较暗值的新图像。
Syntax: ImageChops.darker(image1, image2)
Parameters:
image1: It is the image object or image path of first image.
image2: It is the image object or image path of second image.
Return Value: An Image
Note: Both images should be of same MODE.
代码#1:
# importing Image class from PIL package
from PIL import ImageChops, Image
# opening images to compare
im1 = Image.open(r"C:\Users\Admin\Pictures\download.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\images.png")
# Checking and returning a copy
# of image contating darker pixels
im = ImageChops.darker(im1, im2)
# showing image
im.show()
输出:
代码#2:
# importing Image class from PIL package
from PIL import ImageChops, Image
# opening images to compare
im1 = Image.open(r"C:\Users\Admin\Pictures\geeks.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\capture.png")
# Checking and returning a copy
# of image contating darker pixels
im = ImageChops.darker(im1, im2)
# showing image
im.show()
输出:
注意:不要与Image.blend()
方法混淆。这个方法完全不同