Python PIL | ImageChops.subtract() 和 ImageChops.subtract_modulo() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。
ImageChops.subtract() 方法 –
此方法减去两个图像,将结果除以比例并添加偏移量。如果省略,则比例默认为 1.0,偏移为 0.0。
Syntax: ImageChops.subtract(image1, image2, scale = 1.0, offset = 0)
Parameters:
image1: first image
image2: second image
scale: it is floating point value (if the value keeps on increasing, resultant image becomes darker and darker)
offset: numeric value (if value keeps on increasing, resultant image becomes lighter)
Return Value: An Image
# This will import Image and ImageChops modules
from PIL import Image, ImageChops
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\images.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\download.PNG")
# subtracting im and im2
im3 = ImageChops.subtract(image1 = im, image2 = im2)
# showing resultant image
im3.show()
输出:
ImageChops.subtract_modulo() 方法 –
此方法也用于减去两个图像,但不裁剪结果。
Syntax: ImageChops.subtract_modulo(image1, image2)
Parameters: This method takes two images as parameters.
Return Value: An Image.
# This will import Image and ImageChops modules
from PIL import Image, ImageChops
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\images.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\download.PNG")
# subtracting im and im2
im3 = ImageChops.subtract_modulo(image1 = im, image2 = im2)
# showing resultant image
im3.show()
输出: