Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

blurring an image using PIL in python

Tags:

I have been trying to blur an image using the PIL.

from what I know i need to copy the image, and then change every pixel to the average of the pixels surrounding him, from the original picture. so I didn't get really far, i'm using python 3.3x

from PIL import Image 

img = Image.open("source")
im = Image.copy(img)

I know how to use putpixe, and get a pixel's data, but I can't figure out how to get the average of the pixels around.

Thanks in advance for the help!

like image 948
Mumfordwiz Avatar asked Jan 19 '14 11:01

Mumfordwiz


People also ask

How do you blur an image in Python PIL?

1. PIL. ImageFilter. BoxBlur(): Blurs the image by setting each pixel to the average value of the pixels in a square box extending radius pixels in each direction.

Which function is used for making image blur?

A filter used for blurring is also called low pass filter, because it allows low frequency to enter and stop high frequency. Here frequency means the change of pixel value. Around edge pixel value changes rapidly as blur image is smooth so high frequency should be filtered out.


1 Answers

You can just do:

blurred_image = original_image.filter(ImageFilter.BLUR)

See the ImageFilter module for more options.

You are correct in that the process you describe would blur the image, and there are filters that essentially directly do what you suggest (*e.g.", using the ImageFilter.Kernel method where you kernel has constant weights). Using ImageFilter will be faster and easier though, and give you more options for blurring and beyond.

like image 157
tom10 Avatar answered Sep 28 '22 12:09

tom10