import cv2
#图像平滑处理
img = cv2.imread('lenaNoise.png')
#图像的显示
cv2.imshow('image',img)
#等待时间,毫秒,0表示任意键终止
cv2.waitKey(0)
cv2.destroyAllWindows()
运行结果:图中白点为噪声
均值滤波:
#均值滤波
#简单的平均卷积操作
blur = cv2.blur(img, (3, 3))#取3*3的矩阵 一般取奇数矩阵
cv2.imshow('blur',blur)
cv2.waitKey(0)
cv2.destroyAllWindows()
运行结果:
中值滤波:
中值滤波主要去除椒盐噪声和斑点噪声
#中值滤波
#相当于用中值代替
median = cv2.medianBlur(img, 5)
cv2.imshow('median',median)
cv2.waitKey(0)
cv2.destroyAllWindows()