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


全部评论

相关推荐

落叶随风呀:学校不好就放两栏,专业能力往前移, 政治面貌不是党员不如不写,籍贯湖南衡阳,或者湖南,浅尝辄止 基本信息排版不够美观,没有对齐 简历上花里胡哨的东西去掉 项目我不评价,因为我能力有限,且对mcu了解不足 但是这份简历掌握的水平,你可以海投试试,工作没问题但是工资应该不会高,因为搞mcu的小公司多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务