OpenCV-Python之高斯模糊

1.高斯噪声函数

//将范围限制在0~255之间
def thresholdfn(pv):
    if pv > 255:
        pv = 255
    elif pv < 0:
        pv = 0
    else:
        return pv
//定义高斯噪声函数
def gaussian_demo(image):
    h, w, c = image.shape
    for row in range(h):
        for col in range(w):
            s = np.random.normal(0, 20, 3)
            b = image[row, col, 0]
            g = image[row, col, 1]
            r = image[row, col, 2]
            b = thresholdfn(b + s[0])
            g = thresholdfn(g + s[1])
            r = thresholdfn(r + s[2])
    cv.imshow('gaussian_demo', image)

2.测试程序

image = cv.imread('./data/lena.jpg', 1)
cv.imshow('source image', image)
t1 = cv.getTickCount()
gaussian_demo(image)
t2 = cv.getTickCount()
time = (t2 - t1) / cv.getTickFrequency()
print(time)
dst = cv.GaussianBlur(image, (0, 0), 20)
cv.imshow('GaussianBlur image', dst)
cv.waitKey(0)
cv.destroyAllWindows()

测试结果:
time: 7.665542534869055


全部评论

相关推荐

看到这个内容真是闹麻了。。。。。。现在有了AI以后很多人面试都会作弊吗?&nbsp;那对老老实实面试的人岂不是不公平....
重生之我要干前端:放宽心,作弊很明显的,面试官也不是傻子,而且这世上更多的肯定是依靠自己的知识的人,所以放宽心提升自己最重要
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
仁者伍敌:难怪小公司那么挑剔,让你们这些大佬把位置拿了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务