返回介绍

ImageOps Module

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

The ImageOps module contains a number of ‘ready-made’ image processing operations. This module is somewhat experimental, and most operators only work on L and RGB images.

Only bug fixes have been added since the Pillow fork.

1.1.3 新版功能.

PIL.ImageOps.autocontrast(image, cutoff=0, ignore=None)

Maximize (normalize) image contrast. This function calculates a histogram of the input image, removes cutoff percent of the lightest and darkest pixels from the histogram, and remaps the image so that the darkest pixel becomes black (0), and the lightest becomes white (255).

参数:
  • image – The image to process.
  • cutoff – How many percent to cut off from the histogram.
  • ignore – The background pixel value (use None for no background).
返回:

An image.

PIL.ImageOps.colorize(image, black, white)

Colorize grayscale image. The black and white arguments should be RGB tuples; this function calculates a color wedge mapping all black pixels in the source image to the first color, and all white pixels to the second color.

参数:
  • image – The image to colorize.
  • black – The color to use for black input pixels.
  • white – The color to use for white input pixels.
返回:

An image.

PIL.ImageOps.crop(image, border=0)

Remove border from image. The same amount of pixels are removed from all four sides. This function works on all image modes.

也可以参考

crop()

参数:
  • image – The image to crop.
  • border – The number of pixels to remove.
返回:

An image.

PIL.ImageOps.deform(image, deformer, resample=2)

Deform the image.

参数:
  • image – The image to deform.
  • deformer – A deformer object. Any object that implements a getmesh method can be used.
  • resample – What resampling filter to use.
返回:

An image.

PIL.ImageOps.equalize(image, mask=None)

Equalize the image histogram. This function applies a non-linear mapping to the input image, in order to create a uniform distribution of grayscale values in the output image.

参数:
  • image – The image to equalize.
  • mask – An optional mask. If given, only the pixels selected by the mask are included in the analysis.
返回:

An image.

PIL.ImageOps.expand(image, border=0, fill=0)

Add border to the image

参数:
  • image – The image to expand.
  • border – Border width, in pixels.
  • fill – Pixel fill value (a color value). Default is 0 (black).
返回:

An image.

PIL.ImageOps.fit(image, size, method=0, bleed=0.0, centering=(0.5, 0.5))

Returns a sized and cropped version of the image, cropped to the requested aspect ratio and size.

This function was contributed by Kevin Cazabon.

参数:
  • size – The requested output size in pixels, given as a (width, height) tuple.
  • method – What resampling method to use. Default is PIL.Image.NEAREST.
  • bleed – Remove a border around the outside of the image (from all four edges. The value is a decimal percentage (use 0.01 for one percent). The default value is 0 (no border).
  • centering – Control the cropping position. Use (0.5, 0.5) for center cropping (e.g. if cropping the width, take 50% off of the left side, and therefore 50% off the right side). (0.0, 0.0) will crop from the top left corner (i.e. if cropping the width, take all of the crop off of the right side, and if cropping the height, take all of it off the bocodeom). (1.0, 0.0) will crop from the bocodeom left corner, etc. (i.e. if cropping the width, take all of the crop off the left side, and if cropping the height take none from the top, and therefore all off the bocodeom).
返回:

An image.

PIL.ImageOps.flip(image)

Flip the image vertically (top to bocodeom).

参数:image – The image to flip.
返回:An image.
PIL.ImageOps.grayscale(image)

Convert the image to grayscale.

参数:image – The image to convert.
返回:An image.
PIL.ImageOps.invert(image)

Invert (negate) the image.

参数:image – The image to invert.
返回:An image.
PIL.ImageOps.mirror(image)

Flip image horizontally (left to right).

参数:image – The image to mirror.
返回:An image.
PIL.ImageOps.posterize(image, bits)

Reduce the number of bits for each color channel.

参数:
  • image – The image to posterize.
  • bits – The number of bits to keep for each channel (1-8).
返回:

An image.

PIL.ImageOps.solarize(image, threshold=128)

Invert all pixel values above a threshold.

参数:
  • image – The image to posterize.
  • threshold – All pixels above this greyscale level are inverted.
返回:

An image.

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

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

发布评论

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