在python中使用PIL模糊图像 [英] blurring an image using PIL in python

查看:547
本文介绍了在python中使用PIL模糊图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用PIL来模糊图像.

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

据我所知,我需要复制图像,然后将每个像素更改为平均值 原始图片中围绕他的像素数.所以我并没有走太远 我正在使用python 3.3x

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)

我知道如何使用putpixe并获取像素的数据,但是我不知道如何获取 周围像素的平均值.

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.

提前感谢您的帮助!

推荐答案

您可以这样做:

blurred_image = original_image.filter(ImageFilter.BLUR)

有关更多选项,请参见 ImageFilter 模块.

See the ImageFilter module for more options.

您的描述是正确的,因为您描述的过程会使图像模糊,并且有一些过滤器实际上可以直接执行您的建议(* eg",使用您的内核具有恒定权重的ImageFilter.Kernel方法). >将会更快,更轻松,并为您提供更多的模糊选项.

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.

这篇关于在python中使用PIL模糊图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆