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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With