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!

kramer65
  • 50,427
  • 120
  • 308
  • 488
  • 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. – Mark Ransom May 05 '16 at 17:30

1 Answers1

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))
Dmiters
  • 2,011
  • 3
  • 23
  • 31
  • 5
    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. – Alfe Feb 01 '17 at 13:30
  • I've just asked [For PIL.ImageFilter.GaussianBlur how what kernel is used and does the radius parameter relate to standard deviation?](https://stackoverflow.com/q/62968174/3904031) – uhoh Jul 18 '20 at 11:52