7、高斯模糊

均值模糊的扩展,权重均值模糊,效果比均值模糊好,应用场景毛玻璃

高斯分布,即正态分布

正态分布

src = cv.imread('./image.png')
cv.namedWindow('image', cv.WINDOW_AUTOSIZE)
cv.imshow("image", src)

dst0 = cv.GaussianBlur(src,(0,0),15) #标准差15
dst1 = cv.GaussianBlur(src,(3,3),0)#标准差0
dst2 = cv.GaussianBlur(src,(5,5),0)

cv.imshow("Gaussian blur0", dst0)
cv.imshow("Gaussian blur3", dst1)
cv.imshow("Gaussian blur5", dst2)

高斯模糊

高斯模糊源码:其实就是模糊中间那个像素

#均值 6*6 1 。 * 【6*6】/36 = mean -》P
import cv2
import numpy as np
img = cv2.imread('image11.jpg',1)
cv2.imshow('src',img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
dst = np.zeros((height,width,3),np.uint8)
for i in range(3,height-3):
    for j in range(3,width-3):
        sum_b = int(0)
        sum_g = int(0)
        sum_r = int(0)
        for m in range(-3,3):#-3 -2 -1 0 1 2
            for n in range(-3,3):
                (b,g,r) = img[i+m,j+n]
                sum_b = sum_b+int(b)
                sum_g = sum_g+int(g)
                sum_r = sum_r+int(r)
            
        b = np.uint8(sum_b/36)
        g = np.uint8(sum_g/36)
        r = np.uint8(sum_r/36)
        dst[i,j] = (b,g,r)
cv2.imshow('dst',dst)
cv2.waitKey(0)

你可能感兴趣的:(7、高斯模糊)