Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define radius for blur with Python Pillow?

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!

like image 771
kramer65 Avatar asked May 05 '16 17:05

kramer65


People also ask

How do you blur an image in a pillow Python?

PIL. ImageFilter. GaussianBlur(): This method creates a Gaussian blur filter. The filter uses radius as a parameter and by changing the value of this radius, the intensity of the blur over the image gets changed.

What is Radius in Blur?

radius. The radius of the blur, specified as a <length> . It defines the value of the standard deviation to the Gaussian function, i.e., how many pixels on the screen blend into each other; thus, a larger value will create more blur. A value of 0 leaves the input unchanged.

How do you blur the background in Python?

Practical Data Science using Python Blurring an image can be done by reducing the level of noise in the image by applying a filter to an image. Image blurring is one of the important aspects of image processing. The ImageFilter class in the Pillow library provides several standard image filters.


1 Answers

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))
like image 110
Dmiters Avatar answered Oct 09 '22 06:10

Dmiters