import cv2 as cv
import matplotlib.pyplot as plt
# 1图像读取
img = cv.imread('./image/pic1.jpg')
# 2均值滤波
blur = cv.blur(img, (5, 5))
# 3图像显示
plt.rc("font", family='Microsoft YaHei')
plt.figure(figsize=(10, 8), dpi=100)
plt.subplot(121), plt.imshow(img[:, :, ::-1]), plt.title('原图')
plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.imshow(blur[:, :, ::-1]), plt.title('均值滤波后结果')
plt.xticks([]), plt.yticks([])
plt.show()
# 1图像读取
img = cv.imread('./image/pic2.jpg')
# 2高斯滤波
blur = cv.GaussianBlur(img, (3, 3), 1)
# 3图像显示
plt.figure(figsize=(10, 8), dpi=100)
plt.subplot(121), plt.imshow(img[:, :, ::-1]), plt.title('原图')
plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.imshow(blur[:, :, ::-1]), plt.title('高斯滤波后结果')
plt.xticks([]), plt.yticks([])
plt.show()
# 1图像读取
img = cv.imread('./image/pic2.jpg')
# 2中值滤波
blur = cv.medianBlur(img, 5)
# 3图像展示
plt.figure(figsize=(10, 8), dpi=100)
plt.subplot(121), plt.imshow(img[:, :, ::-1]), plt.title('原图')
plt.xticks([]), plt.yticks([])
plt.subplot(122), plt.imshow(blur[:, :, ::-1]), plt.title('中值滤波后结果')
plt.xticks(), plt.yticks()
plt.show()
![图片[1]-python图像均值、高斯和中值滤波源代码-给我网盘资源](https://kngzs.cc/wp-content/uploads/2024/04/1.png)
![图片[2]-python图像均值、高斯和中值滤波源代码-给我网盘资源](https://kngzs.cc/wp-content/uploads/2024/04/2.png)
![图片[3]-python图像均值、高斯和中值滤波源代码-给我网盘资源](https://kngzs.cc/wp-content/uploads/2024/04/3.png)
THE END