Python PIL | ImageChops.add_modulo() 和 ImageChops.difference() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。
ImageChops.add_modulo() 方法 –
此方法用于添加两个图像而不剪切它们,这与剪切图像的 ImageChops.add() 不同。
Syntax: ImageChops.add_modulo(image1, image2)
Parameters:
image1 is the first image
image2 is the second image
Return Value: It returns an Image.
Note: Both the images should be of same MODE.
# This will import Image and ImageChops modules
from PIL import Image, ImageChops
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\download.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\images.PNG")
# here adding image1 and image2
im3 = ImageChops.add_modulo(im, im2)
# showing resultant image
im3.show()
输出:
ImageChops.difference() 方法 –
该方法用于获取两幅图像之间逐像素差异的绝对值。
Syntax: ImageChops.difference(image1, image2)
Parameters:
image1 first image
image2 second image
Return Value: It returns an Image.
# This will import Image and ImageChops modules
from PIL import Image, ImageChops
# Opening Images
im = Image.open(r"C:\Users\Admin\Pictures\download.png")
im2 = Image.open(r"C:\Users\Admin\Pictures\images.PNG")
# here getting absolute difference
# of image1 and image2
im3 = ImageChops.difference(im, im2)
# showing resultant image
im3.show()
输出:
使用的图像: