How to define radius for blur with Python Pillow?

柔情痞子 提交于 2020-08-04 03:38:28

问题


I'm trying to blur an image with Pillow, using the ImageFilter as follows:

from PIL import ImageFilter
blurred_image = im.filter(ImageFilter.BLUR)

This works fine, except that it has a set radius which is way too small for me. I want to blur the image so much that it can be barely recognised anymore. In the docs I see that the radius is set to 2 by default, but I don't really understand how I can set it to a larger value?

Does anybody have any idea how I could increase the blur radius with Pillow? All tips are welcome!


回答1:


Image.filter() takes an ImageFilter so you can create an ImageFilter.GaussianBlur instance with whatever radius you want, passed in as a named argument.

blurred_image = im.filter(ImageFilter.GaussianBlur(radius=50))

You can even make it more concise like so:

blurred_image = im.filter(ImageFilter.GaussianBlur(50))


来源:https://stackoverflow.com/questions/37056684/how-to-define-radius-for-blur-with-python-pillow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!