1.通过中值模糊处理椒盐噪声
源码:
import cv2 as cv
def median_blur_demo(image):
dst = cv.medianBlur(image, 5)
cv.imshow("median_blur_demo", dst)
src = cv.imread("/home/jon/opencv-python-picture/lenanoise.png")
cv.imshow("normal", src)
median_blur_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
图像对比:
很明显还是可以看出来,中值滤波虽然处理了椒盐噪声,但是还是牺牲了一些清晰度的
2.通过均值模糊实现图像的模糊处理
源码:
import cv2 as cv
def blur_demo(image):
#值越大,模糊越强烈
dst = cv.blur(image, (5, 5))
cv.imshow("blur_demo", dst)
src = cv.imread("/home/jon/opencv-python-picture/example.png")
cv.imshow("normal", src)
blur_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
图像对比:
3.通过自定义模糊提供图像的对比度
源码:
import cv2 as cv
import numpy as np
def custom_blur_demo(image):
#kernel = np.ones([5, 5], np.float32)/25
kernel = np.array([[0, -1, 0],[-1, 5, -1],[0, -1, 0]], np.float32)
dst = cv.filter2D(image, -1, kernel=kernel)
cv.imshow("custom_blur_demo", dst)
src = cv.imread("/home/jon/opencv-python-picture/example.png")
cv.imshow("normal", src)
custom_blur_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
图像对比: