ImageChops
(信道操作)模块¶
这个 ImageChops
模块包含许多算术图像操作,称为通道操作(“chops”)。这些可以用于各种用途,包括特殊效果、图像合成、算法绘制等。
有关更多的预制操作,请参见 ImageOps
.
此时,大多数通道操作仅针对8位图像(例如“l”和“rgb”)。
功能¶
大多数通道操作采用一个或两个图像参数并返回新图像。除非另有说明,否则通道操作的结果总是被限制在0到max的范围内(对于此模块中操作支持的所有模式,该范围为255)。
-
PIL.ImageChops.
add
(image1, image2, scale=1.0, offset=0)[源代码]¶ 添加两个图像,将结果除以比例并添加偏移量。如果忽略,则比例默认为1.0,偏移为0.0。至少一个图像必须具有模式“1”。
out = ((image1 + image2) / scale + offset)
- 返回类型
-
PIL.ImageChops.
add_modulo
(image1, image2)[源代码]¶ 添加两个图像,而不剪切结果。至少一个图像必须具有模式“1”。
out = ((image1 + image2) % MAX)
- 返回类型
-
PIL.ImageChops.
blend
(image1, image2, alpha)[源代码]¶ 使用恒定的透明度权重混合图像。Alias
PIL.Image.Image.blend()
.- 返回类型
-
PIL.ImageChops.
composite
(image1, image2, mask)[源代码]¶ 使用透明蒙版创建合成。Alias
PIL.Image.Image.composite()
.- 返回类型
-
PIL.ImageChops.
darker
(image1, image2)[源代码]¶ 比较两个图像(逐像素),并返回包含较暗值的新图像。至少一个图像必须具有模式“1”。
out = min(image1, image2)
- 返回类型
-
PIL.ImageChops.
difference
(image1, image2)[源代码]¶ 返回两幅图像之间逐像素差的绝对值。至少一个图像必须具有模式“1”。
out = abs(image1 - image2)
- 返回类型
-
PIL.ImageChops.
duplicate
(image)[源代码]¶ 复制频道。Alias
PIL.Image.Image.copy()
.- 返回类型
-
PIL.ImageChops.
lighter
(image1, image2)[源代码]¶ 比较两个图像(逐像素),并返回包含较浅值的新图像。至少一个图像必须具有模式“1”。
out = max(image1, image2)
- 返回类型
-
PIL.ImageChops.
logical_and
(image1, image2)[源代码]¶ 两个图像之间的逻辑和。至少一个图像必须具有模式“1”。
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)[源代码]¶ 将两个图像叠加在一起。
如果将图像与实心黑色图像相乘,则结果为黑色。如果与纯白图像相乘,则图像不受影响。至少一个图像必须具有模式“1”。
out = image1 * image2 / MAX
- 返回类型
-
PIL.ImageChops.
offset
(image, xoffset, yoffset=None)¶ 返回数据被给定距离偏移的图像的副本。数据环绕边缘。如果 yoffset 如果省略,则假定等于 X偏移.
-
PIL.ImageChops.
screen
(image1, image2)[源代码]¶ 将两个倒置的图像叠加在一起。至少一个图像必须具有模式“1”。
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
- 返回类型