图像处理----图像模糊(高斯模糊)

python-图像模糊操作:包括均值模糊,中值模糊,高斯模糊和双边滤波。本文主要讲其中的高斯模糊。

图像的高斯模糊时非常经典的图像卷积例子。本质上,图像模糊就是将(灰度)图像I和一个高斯核进行卷积操作:高斯模糊通常是其他图像处理操作的一部分,比如图像插值操作,兴趣点计算,以及很多其他应用。scipy有用来做滤波处理的scipy.ndimage.filters模块。该模块使用快速一维分离的方式来计算卷积。scipy.ndimage.filters.gaussian_filter(a,b),其中b参数代表标准差(\sigma

代码如下:

from PIL import Image
from numpy import *
from scipy.ndimage import filters

# im = Image.open('D:\\software\\pycharm\\PycharmProjects\\computer-version\\data\\tu3.jpg')  # 打开原图
# # im_gray = im.convert('L')  # 转化为灰度图像
# # im.show()  #显示原始灰度图像


im_gray = array(Image.open('D:\\software\\pycharm\\PycharmProjects\\computer-version\\data\\tu3.jpg').convert('L'))
im_gray2 = filters.gaussian_filter(im_gray,2)

image_2 =Image.fromarray(im_gray2)  #Image.fromarray() 函数将数组对象作为输入,并返回由数组对象制作的图像对象。
# image_1.show()  #标准差为2时的高斯滤波器

im_gray3 = filters.gaussian_filter(im_gray2,5)
image_3 =Image.fromarray(im_gray3)
# image_3.show()  #标准差为2时的高斯滤波器

im_gray4 = filters.gaussian_filter(im_gray,10)
image_4 =Image.fromarray(im_gray4)
# image_4.show()  #标准差为2时的高斯滤波器

原始灰度图如下:

\sigma=2)结果如下: 

 (\sigma=5)结果如下: 

 (\sigma=10)结果如下: 

 结论:标准差\sigma越大,图像就越模糊。

猜你喜欢

转载自blog.csdn.net/qq_44896301/article/details/129208247