Python PIL ImageChops.subtract()方法
PIL是Python成像库,它为Python解释器提供了图像编辑功能。ImageChops模块包含一些算术图像操作,称为通道操作(”chops”)。这些可以用于各种目的,包括特殊效果、图像合成、算法绘画等等。
PIL.ImageChops.subtract()方法对两幅图像进行减法,将结果除以比例,再加上偏移。如果省略,scale默认为1.0,offset默认为0.0。至少有一个图像必须有模式 “1”。
语法: PIL.ImageChops.subtract(image1, image2, scale=1.0, offset=0)
Parameters:
image1: first image
image2: second image
scale: numeric value
offset: numeric value
返回类型: Image
Image1:
Image2:
# 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()
输出: