在Python中使用PIL模块对图片进行高斯模糊处理的教程
2015-05-05 17:05
1196 查看
从一篇文章中看到,PIL 1.1.5 已经内置了高斯模糊,但是并没有在文档中提及,而且PIL的高斯模糊中 radius 是硬编码, 虽然构造方法中有传入 radius 参数,但压根就没有用到 (看这里),所以需要自己进行改造,当然,知道了原因, 修改起来自然非常简单了。
结合帖子中的需求,对局部进行高斯模糊,所以还需要结合使用 crop 和 paste 方法实现局部使用滤镜。
代码如下:
#-*- coding: utf-8 -*- from PIL import Image, ImageFilter class MyGaussianBlur(ImageFilter.Filter): name = "GaussianBlur" def __init__(self, radius=2, bounds=None): self.radius = radius self.bounds = bounds def filter(self, image): if self.bounds: clips = image.crop(self.bounds).gaussian_blur(self.radius) image.paste(clips, self.bounds) return image else: return image.gaussian_blur(self.radius) bounds = (150, 130, 280, 230) image = Image.open('source.jpg') image = image.filter(MyGaussianBlur(radius=29, bounds=bounds)) image.show()
可以看下效果:
您可能感兴趣的文章:
- Python实现PS滤镜中马赛克效果示例
- python简单实现旋转图片的方法
- 在Python下利用OpenCV来旋转图像的教程
- Python中使用PIL库实现图片高斯模糊实例
- python通过pil将图片转换成黑白效果的方法
- Python利用matplotlib生成图片背景及图例透明的效果
- python实现基于两张图片生成圆角图标效果的方法
- Python基于pygame实现图片代替鼠标移动效果
- Python使用Matplotlib实现雨点图动画效果的方法
- Python tkinter实现的图片移动碰撞动画效果【附源码下载】
- Python3实现的画图及加载图片动画效果示例
- Python实现PS滤镜的旋转模糊功能示例
相关文章推荐
- 在Python中使用PIL模块对图片进行高斯模糊处理的教程
- 在Python中使用PIL模块处理图像的教程
- python处理图片之PIL模块简单使用方法
- python处理图片之PIL模块简单使用方法
- 使用Python的PIL模块来进行图片对比
- 使用Python的PIL模块来进行图片对比
- python处理图片之PIL模块简单使用
- 使用Python PIL模块处理图片
- python,使用PIL库对图片进行操作
- (python)图片处理Pillow模块的使用
- Python-使用CSV模块进行文件处理
- Linux上安装Python的PIL和Pillow库处理图片的实例教程
- python使用pil进行图像处理(等比例压缩、裁剪)实例代码
- python图片处理模块PIL(pillow)(1)
- Python图片处理模块PIL(pillow)(2)
- 使用Python的urllib2模块处理url和图片的技巧两则
- 使用Python的urllib2模块处理url和图片的技巧两则
- python,使用PIL库对图片进行操作
- Python宝典第八、九章:Python多媒体编程及使用PIL处理图片
- python使用PIL处理图片的一些收获和经验