1 __author__ = "WSX" 2 import cv2 as cv 3 import numpy as np 4 #高斯模糊 基于权重(卷积) 5 #高斯模糊 去燥效果很好 6 7 #高斯模糊 8 def guss_blur(img): #去燥 基于卷积 9 dst = cv.blur(img , (5 ,5)) #卷积核大小(1*3) 10 cv.imshow("Show", dst) 11 12 def deal( number ): 13 if number > 255: 14 return 255 15 elif number < 0: 16 return 0 17 else: 18 return number 19 20 def guss_noise(img): #加燥,自己写的 21 h,w,c = img.shape 22 for i in range(h): 23 for j in range(w): 24 s = np.random.normal(0 , 20 ,3) 25 b = img[i ,j ,0] 26 g = img[i, j, 1] 27 r = img[i, j, 2] 28 img[i, j, 0] = deal(b + s[0]) 29 img[i, j, 1] = deal(g + s[1]) 30 img[i, j, 2] = deal(r + s[2]) 31 cv.imshow("noise", img) 32 33 #cv.GaussianBlur(img ,(5,5) ,15) 高斯模糊 5*5 34 35 def main(): 36 img = cv.imread("1.JPG") 37 cv.namedWindow("Show", cv.WINDOW_AUTOSIZE) 38 #guss_blur(img) 39 guss_noise(img) 40 cv.waitKey(0) 41 cv.destroyAllWindows() 42 43 main()