import cv2 as cv
import numpy as np
#均值模糊 去噪
def blur_demo(image):
blur_image=cv.blur(image,(7,7))
cv.imshow("blur_demo",blur_image)
#中值模糊 去除 椒盐噪声
def median_blur_demo(image):
blur_image = cv.medianBlur(image,5)
cv.imshow("median_blur_demo", blur_image)
#锐化 自定义模糊
def custom_blur_demo(image):
#拉普拉斯算子 [[0,-1,0],[-1,5,-1],[0,-1,0]]
kernel=np.array([[0,-1,0],[-1,5,-1],[0,-1,0]],np.float32)
#锐化 相加等于1 边缘相加等于0
dst=cv.filter2D(image,-1,kernel=kernel)
cv.imshow("custom",dst)
src=cv.imread("hui.jpg")
cv.namedWindow("yuantu",cv.WINDOW_AUTOSIZE)
cv.imshow("yuantu",src)
custom_blur_demo(src)
blur_demo(src)
median_blur_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()