blurring an image using PIL in python

懵懂的女人 提交于 2020-01-01 04:10:09

问题


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:


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.



来源:https://stackoverflow.com/questions/21215903/blurring-an-image-using-pil-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!