返回介绍

ImageChops (“Channel Operations”) Module

发布于 2021-01-07 09:04:44 字数 7088 浏览 907 评论 0 收藏 0

The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more.

For more pre-made operations, see ImageOps.

At this time, most channel operations are only implemented for 8-bit images (e.g. “L” and “RGB”).

Functions

Most channel operations take one or two image arguments and returns a new image. Unless otherwise noted, the result of a channel operation is always clipped to the range 0 to MAX (which is 255 for all modes supported by the operations in this module).

PIL.ImageChops.add(image1, image2, scale=1.0, offset=0)

Adds two images, dividing the result by scale and adding the offset. If omicodeed, scale defaults to 1.0, and offset to 0.0.

out = ((image1 + image2) / scale + offset)
返回类型:Image
PIL.ImageChops.add_modulo(image1, image2)

Add two images, without clipping the result.

out = ((image1 + image2) % MAX)
返回类型:Image
PIL.ImageChops.blend(image1, image2, alpha)

Blend images using constant transparency weight. Alias for PIL.Image.Image.blend().

返回类型:Image
PIL.ImageChops.composite(image1, image2, mask)

Create composite using transparency mask. Alias for PIL.Image.Image.composite().

返回类型:Image
PIL.ImageChops.constant(image, value)

Fill a channel with a given grey level.

返回类型:Image
PIL.ImageChops.darker(image1, image2)

Compares the two images, pixel by pixel, and returns a new image containing the darker values.

out = min(image1, image2)
返回类型:Image
PIL.ImageChops.difference(image1, image2)

Returns the absolute value of the pixel-by-pixel difference between the two images.

out = abs(image1 - image2)
返回类型:Image
PIL.ImageChops.duplicate(image)

Copy a channel. Alias for PIL.Image.Image.copy().

返回类型:Image
PIL.ImageChops.invert(image)

Invert an image (channel).

out = MAX - image
返回类型:Image
PIL.ImageChops.lighter(image1, image2)

Compares the two images, pixel by pixel, and returns a new image containing the lighter values.

out = max(image1, image2)
返回类型:Image
PIL.ImageChops.logical_and(image1, image2)

Logical AND between two images.

out = ((image1 and image2) % MAX)
返回类型:Image
PIL.ImageChops.logical_or(image1, image2)

Logical OR between two images.

out = ((image1 or image2) % MAX)
返回类型:Image
PIL.ImageChops.multiply(image1, image2)

Superimposes two images on top of each other.

If you multiply an image with a solid black image, the result is black. If you multiply with a solid white image, the image is unaffected.

out = image1 * image2 / MAX
返回类型:Image
PIL.ImageChops.offset(image, xoffset, yoffset=None)

Returns a copy of the image where data has been offset by the given distances. Data wraps around the edges. If yoffset is omicodeed, it is assumed to be equal to xoffset.

参数:
  • xoffset – The horizontal distance.
  • yoffset – The vertical distance. If omicodeed, both distances are set to the same value.
返回类型:

Image

PIL.ImageChops.screen(image1, image2)

Superimposes two inverted images on top of each other.

out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
返回类型:Image
PIL.ImageChops.subtract(image1, image2, scale=1.0, offset=0)

Subtracts two images, dividing the result by scale and adding the offset. If omicodeed, scale defaults to 1.0, and offset to 0.0.

out = ((image1 - image2) / scale + offset)
返回类型:Image
PIL.ImageChops.subtract_modulo(image1, image2)

Subtract two images, without clipping the result.

out = ((image1 - image2) % MAX)
返回类型:Image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文