均值模糊的扩展,权重均值模糊,效果比均值模糊好,应用场景毛玻璃
虽然kernel是3*3的核,但是会拆分成x,y进行2次,速度反而快了 (这是一种加速的手段)
如果是二维的话,有9次乘法,1次除法
如果是一维的话,就是3次乘法1次除法,在做3次乘法1次除法,一共是6次乘法和2次除法
给图片增加噪声
def clamp(pv):
if pv > 255:
return 255
elif pv < 0:
return 0
else:
return pv
def gaussian_noise(img):
h,w,ch = img.shape
for row in range(h):
for col in range(w):
s = np.random.normal(0, 20, 3)
b = img[row, col, 0]
g = img[row, col, 1]
r = img[row, col, 2]
img[row, col, 0] = clamp(b + s[0])
img[row, col, 1] = clamp(g + s[1])
img[row, col, 2] = clamp(r + s[2])
cv.imshow("noise img", img)
高斯模糊API
dst = GaussianBlur(src, (0,0), 15)
毛玻璃效果 会保留特征
dst = GaussianBlur(src, (5,5), 0)