【opencv自学笔记】06:高斯模糊

加高斯噪声,高斯模糊

import cv2 as cv
import numpy as np

#计时,装饰器
def decorate_time(func):
    def wrapper(src):
        t1=cv.getTickCount()
        func(src)
        t2=cv.getTickCount()
        print('time used %f'%((t2-t1)/cv.getTickFrequency()))
    return wrapper


def clamp(pv):
    if pv>255:
        return 255
    elif pv<0:
        return 0
    else:
        return pv

@decorate_time
def gussian_noise(image):
    h,w,ch=image.shape
    for row in range(h):
        for col in range(w):
            for c in range(ch):
                image[row,col,c]=clamp(image[row,col,c]+np.random.normal(0,20))
    cv.imshow('gussian_noise',image)


src=cv.imread("D:/Study/opencv/code/1.jpg")
cv.imshow('src',src)

gussian_noise(src)
#dst=cv.GaussianBlur(src,(0,0),15)  #毛玻璃效果
dst=cv.GaussianBlur(src,(5,5),0)#知道ksize即可求出sigmaX,知道sigmaX即可求出ksize,因此有一个为0
cv.imshow('Gussian Blur',dst)
cv.waitKey(0)
cv.destroyAllWindows()

 

你可能感兴趣的:(笔记)