# coding = utf-8
# 导入必要的莫快
from PIL import Image
import numpy as np
from scipy.ndimage import filters # 引入滤波模块
import matplotlib.pyplot as plt
# 利用scipy进行高斯模糊处理
im = np.array(Image.open('./wfz.jpg'))
index = 141 # 画1行4列的图,与 1,4,1 同
plt.subplot(index)
plt.imshow(im)
<matplotlib.image.AxesImage at 0x238e5cc0>
for sigma in (2, 5, 10): # 模糊参数,值越大越模糊
im_blur = np.zeros(im.shape, dtype=np.uint8)
for i in range(3): # 对图像的每一个通道都应用高斯滤波
im_blur[:,:,i] = filters.gaussian_filter(im[:,:,i], sigma)
index += 1
plt.subplot(index)
plt.imshow(im_blur)
# 输出图像
plt.show()