看到微信的红包照片之后,就想了解下高斯模糊。最近实习学了Python操作OpenCV,没有好好玩过,今天恰好有空,就试了用Python+OpenCV实现图像高斯模糊。
1. 环境
使用Ubuntu 14.04和Python 2.7.6,OpenCV需要安装,使用:
apt-get install python-opencv
在python中import cv2,没有报错信息则安装成功。
2. 高斯模糊
高斯模糊本质上是低通滤波器,输出图像的每个像素点是原图像上对应像素点与周围像素点的加权和,原理并不复杂。做久了卷积神经网络看这个分外亲切,就是用高斯分布权值矩阵与原始图像矩阵做卷积运算而已。摘录wiki上两段原文:
Mathematically, applying a Gaussian blur to an image is the same as convolving the image with a Gaussian function.
数学上讲,对图像做高斯模糊等同于将图像与高斯函数卷积。
Since the Fourier transform of a Gaussian is another Gaussian, applying a Gaussian blur has the effect of reducing the image’s high-frequency components; a Gaussian blur is thus a low pass