ImageChops
(信道操作)模块#
这个 ImageChops
模块包含许多算术图像操作,称为通道操作(“chops”)。这些可以用于各种用途,包括特殊效果、图像合成、算法绘制等。
有关更多的预制操作,请参见 ImageOps
.
此时,大多数通道操作仅针对8位图像(例如“l”和“rgb”)。
功能#
大多数通道操作采用一个或两个图像参数并返回新图像。除非另有说明,否则通道操作的结果总是被限制在0到max的范围内(对于此模块中操作支持的所有模式,该范围为255)。
- PIL.ImageChops.add(image1, image2, scale=1.0, offset=0)[源代码]#
将两个图像相加,按比例划分结果并添加偏移量。如果省略,则缩放默认为1.0,而偏移则默认为0.0。**
out = ((image1 + image2) / scale + offset)
- 返回类型:
- PIL.ImageChops.add_modulo(image1, image2)[源代码]#
添加两个图像,而不剪裁结果。**
out = ((image1 + image2) % MAX)
- 返回类型:
- PIL.ImageChops.blend(image1, image2, alpha)[源代码]#
使用恒定透明度权重混合图像。的别名
PIL.Image.blend()
。- 返回类型:
- PIL.ImageChops.composite(image1, image2, mask)[源代码]#
使用透明蒙版创建合成。的别名
PIL.Image.composite()
。- 返回类型:
- PIL.ImageChops.darker(image1, image2)[源代码]#
逐个像素比较两个图像,并返回包含较暗的值的新图像。**
out = min(image1, image2)
- 返回类型:
- PIL.ImageChops.difference(image1, image2)[源代码]#
返回两个图像之间逐个像素差异的绝对值。**
out = abs(image1 - image2)
- 返回类型:
- PIL.ImageChops.duplicate(image)[源代码]#
复制频道。Alias
PIL.Image.Image.copy()
.- 返回类型:
- PIL.ImageChops.lighter(image1, image2)[源代码]#
逐个像素比较两个图像,并返回包含较亮值的新图像。**
out = max(image1, image2)
- 返回类型:
- PIL.ImageChops.logical_and(image1, image2)[源代码]#
两个映像之间的逻辑AND。
这两个图像都必须具有模式“1”。如果您想要在模式不是“1”的图像上执行逻辑与操作,请尝试
multiply()
取而代之的是使用黑白蒙版作为第二张图像。**out = ((image1 and image2) % MAX)
- 返回类型:
- PIL.ImageChops.logical_or(image1, image2)[源代码]#
两个图像之间的逻辑或。
这两个图像都必须具有模式“1”。**
out = ((image1 or image2) % MAX)
- 返回类型:
- PIL.ImageChops.logical_xor(image1, image2)[源代码]#
两个映像之间的逻辑异或。
这两个图像都必须具有模式“1”。**
out = ((bool(image1) != bool(image2)) % MAX)
- 返回类型:
- PIL.ImageChops.multiply(image1, image2)[源代码]#
将两个图像叠加在一起。
如果将图像与纯色黑色图像相乘,则结果为黑色。如果与纯白图像相乘,则该图像不受影响。**
out = image1 * image2 / MAX
- 返回类型:
- PIL.ImageChops.offset(image, xoffset, yoffset=None)[源代码]#
返回数据偏移了给定距离的图像的副本。数据环绕边缘。如果
yoffset
被省略,则假定它等于xoffset
。- 参数:
image -- 输入图像。
xoffset -- 水平距离。
yoffset -- 垂直距离。如果省略,则两个距离都设置为相同的值。
- 返回类型:
- PIL.ImageChops.screen(image1, image2)[源代码]#
将两个反转的图像叠加在彼此的顶部。**
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
- 返回类型: