返回介绍

ImageFilter Module

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

The ImageFilter module contains definitions for a pre-defined set of filters, which can be be used with the Image.filter() method.

Example: Filter an image

from PIL import ImageFilter

im1 = im.filter(ImageFilter.BLUR)

im2 = im.filter(ImageFilter.MinFilter(3))
im3 = im.filter(ImageFilter.MinFilter)  # same as MinFilter(3)

Filters

The current version of the library provides the following set of predefined image enhancement filters:

  • BLUR
  • CONTOUR
  • DETAIL
  • EDGE_ENHANCE
  • EDGE_ENHANCE_MORE
  • EMBOSS
  • FIND_EDGES
  • SMOOTH
  • SMOOTH_MORE
  • SHARPEN
class PIL.ImageFilter.GaussianBlur(radius=2)

Gaussian blur filter.

参数:radius – Blur radius.
class PIL.ImageFilter.UnsharpMask(radius=2, percent=150, threshold=3)

Unsharp mask filter.

See Wikipedia’s entry on digital unsharp masking for an explanation of the parameters.

class PIL.ImageFilter.Kernel(size, kernel, scale=None, offset=0)

Create a convolution kernel. The current version only supports 3x3 and 5x5 integer and floating point kernels.

In the current version, kernels can only be applied to “L” and “RGB” images.

参数:
  • size – Kernel size, given as (width, height). In the current version, this must be (3,3) or (5,5).
  • kernel – A sequence containing kernel weights.
  • scale – Scale factor. If given, the result for each pixel is divided by this value. the default is the sum of the kernel weights.
  • offset – Offset. If given, this value is added to the result, after it has been divided by the scale factor.
class PIL.ImageFilter.RankFilter(size, rank)

Create a rank filter. The rank filter sorts all pixels in a window of the given size, and returns the rank‘th value.

参数:
  • size – The kernel size, in pixels.
  • rank – What pixel value to pick. Use 0 for a min filter, size * size / 2 for a median filter, size * size - 1 for a max filter, etc.
class PIL.ImageFilter.MedianFilter(size=3)

Create a median filter. Picks the median pixel value in a window with the given size.

参数:size – The kernel size, in pixels.
class PIL.ImageFilter.MinFilter(size=3)

Create a min filter. Picks the lowest pixel value in a window with the given size.

参数:size – The kernel size, in pixels.
class PIL.ImageFilter.MaxFilter(size=3)

Create a max filter. Picks the largest pixel value in a window with the given size.

参数:size – The kernel size, in pixels.
class PIL.ImageFilter.ModeFilter(size=3)

Create a mode filter. Picks the most frequent pixel value in a box with the given size. Pixel values that occur only once or twice are ignored; if no pixel value occurs more than twice, the original pixel value is preserved.

参数:size – The kernel size, in pixels.

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

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

发布评论

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