如何使用 Python Pillow 定义模糊半径?
Posted
技术标签:
【中文标题】如何使用 Python Pillow 定义模糊半径?【英文标题】:How to define radius for blur with Python Pillow? 【发布时间】:2016-08-31 14:24:56 【问题描述】:我正在尝试使用Pillow 模糊图像,使用the ImageFilter 如下:
from PIL import ImageFilter
blurred_image = im.filter(ImageFilter.BLUR)
这很好用,只是它的设定半径对我来说太小了。我想模糊图像,以至于几乎无法识别它。在文档中我看到the radius is set to 2 by default,但我真的不明白如何将其设置为更大的值?
有人知道如何使用 Pillow 增加模糊半径吗?欢迎所有提示!
【问题讨论】:
高斯模糊的一个有趣特性是,当您多次运行它时,结果是更宽的高斯模糊。尝试做两次。 【参考方案1】:Image.filter()
采用 ImageFilter
,因此您可以创建一个具有所需半径的 ImageFilter.GaussianBlur
实例,并作为命名参数传入。
blurred_image = im.filter(ImageFilter.GaussianBlur(radius=50))
您甚至可以像这样使其更简洁:
blurred_image = im.filter(ImageFilter.GaussianBlur(50))
【讨论】:
我仍在使用的版本(Image 1.1.7,Ubuntu 12.04)有一个错误。参数被忽略。解决方法:filter = ImageFilter.GaussianBlur(); filter.radius=50
、blurred_image = im.filter(filter)
。只是为了节省您的搜索时间,以防您遇到与我相同的问题。
我刚刚问过For PIL.ImageFilter.GaussianBlur how what kernel is used and does the radius parameter relate to standard deviation?以上是关于如何使用 Python Pillow 定义模糊半径?的主要内容,如果未能解决你的问题,请参考以下文章