Python PIL | ImageChops.subtract() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImageChops 模块包含许多算术图像操作,称为通道操作(“chops”)。这些可用于各种目的,包括特殊效果、图像合成、算法绘画等。
PIL.ImageChops.subtract()
方法减去两个图像,将结果除以比例并添加偏移量。如果省略,则比例默认为 1.0,偏移为 0.0。至少其中一个图像必须具有模式“1”。
Syntax: PIL.ImageChops.subtract(image1, image2, scale=1.0, offset=0)
Parameters:
image1: first image
image2: second image
scale: numeric value
offset: numeric value
Return Type: Image
图片1:
图片2:
# Importing Image and ImageChops module from PIL package
from PIL import Image, ImageChops
# creating a image1 object
im1 = Image.open(r"C:\Users\sadow984\Desktop\a2.PNG")
# creating a image2 object
im2 = Image.open(r"C:\Users\sadow984\Desktop\x5.PNG")
# applying subtract method
im3 = ImageChops.add(im1, im2, scale = 1.0, offset = 2)
im3.show()
输出:
# Importing Image and ImageChops module from PIL package
from PIL import Image, ImageChops
# creating a image1 object
im1 = Image.open(r"C:\Users\sadow984\Desktop\a2.PNG")
# creating a image2 object
im2 = Image.open(r"C:\Users\sadow984\Desktop\x5.PNG")
# applying subtract method
im3 = ImageChops.add(im1, im2, scale = 1.0, offset = 2)
im3.show()
输出: