📜  Python PIL | BoxBlur() 方法

📅  最后修改于: 2022-05-13 01:54:58.236000             🧑  作者: Mango

Python PIL | BoxBlur() 方法

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImageFilter 模块包含一组预定义过滤器的定义,可与 Image.filter() 方法一起使用。
PIL.ImageFilter.BoxBlur()通过将每个像素设置为在每个方向上扩展半径像素的方形框中像素的平均值来模糊图像。支持任意大小的浮动半径。使用优化的实现,该实现在相对于任何半径值的图像大小的线性时间内运行。

Syntax: PIL.ImageFilter.BoxBlur()

Partameters: 
radius: Size of the box in one direction. Radius 0 does not blur, returns an identical image. Radius 1 takes 1 pixel in each direction, i.e. 9 pixels in total.

使用的图像:

Python3
# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
     
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(0))
     
im2.show()


Python3
# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
     
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(2))
     
im2.show()


Python3
# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
     
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(8))
     
im2.show()


输出:

Python3

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
     
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(2))
     
im2.show()

输出:

Python3

# Importing Image and ImageFilter module from PIL package 
from PIL import Image, ImageFilter
     
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(8))
     
im2.show()

输出: