You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
736 B

import cv2
import matplotlib.pyplot as plt
# 读取图片
source = cv2.imread('D:/Python/SpatialProcessing/ImageSmoothing/img/moon.jpg', cv2.IMREAD_UNCHANGED)
source = cv2.cvtColor(source, cv2.COLOR_BGR2RGB) # 转成RGB 方便后面显示
# 均值滤波
result1 = cv2.blur(source, (7, 7))
# 中值滤波
result2 = cv2.medianBlur(source, 5)
# 高斯滤波
result3 = cv2.GaussianBlur(source, (5, 5), 0)
# 显示图形
titles = ['原始图片', '均值滤波', '中值滤波', '高斯滤波']
images = [source, result1, result2, result3]
plt.rcParams['font.sans-serif'] = ['SimHei']
for i in range(4):
plt.subplot(2, 2, i + 1), plt.imshow(images[i], 'gray')
plt.title(titles[i])
plt.xticks([]), plt.yticks([])
plt.show()