How to define radius for blur with Python Pillow?
Asked Answered
F

1

11

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!

For answered 5/5, 2016 at 17:27 Comment(1)
One of the interesting properties of a Gaussian blur is that when you run it multiple times, the result is a wider Gaussian blur. Try doing it twice.Priscillaprise
S
15

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))
Schuyler answered 5/5, 2016 at 17:33 Comment(2)
The version I'm still using (Image 1.1.7, Ubuntu 12.04) has a bug. Parameter is ignored. Workaround: filter = ImageFilter.GaussianBlur(); filter.radius=50, blurred_image = im.filter(filter). Just to save you the searching in case you've got the same problem as I had.Baptize
I've just asked For PIL.ImageFilter.GaussianBlur how what kernel is used and does the radius parameter relate to standard deviation?Monopolize

© 2022 - 2024 — McMap. All rights reserved.