zoukankan      html  css  js  c++  java
  • 高斯模糊和高斯双边滤波

    import cv2 as cv
    import numpy as np
    def clamp(x):
        if x >255:
            return 255
        if x <0 :
            return 0
        return x
    def gussian_noise(image):
        h, w, c = image.shape[:3]
        for h_each in range(h):
            for w_each in range(w):
                noise = np.random.normal(0, 20, 3)
                image[h_each, w_each, 0] = clamp(image[h_each, w_each, 0] + noise[0])
                image[h_each, w_each, 1] = clamp(image[h_each, w_each, 1] + noise[1])
                image[h_each, w_each, 2] = clamp(image[h_each, w_each, 2] + noise[2])
    
    
    src = cv.imread("d:/a.jfif")
    cv.imshow("src", src)
    gussian_noise(src)
    
    
    cv.imshow("noise", src)
    dst = cv.GaussianBlur(src, (0, 0), 3)
    cv.imshow("result", dst)
    dst2 = cv.bilateralFilter(src,0,100, 5)
    cv.imshow("dst2", dst2)
    cv.waitKey(0)
    cv.GaussianBlur(src, (0, 0), 3)是高斯滤波,
    cv.bilateralFilter(src,0,100, 5)是高斯双边滤波,可以保留边缘


  • 相关阅读:
    Java集合的Stack、Queue、Map的遍历
    LinkedHashMap的实现原理
    HashSet的实现原理
    HashMap的实现原理
    leetcode526
    leetcode406
    leetcode413
    leetcode513
    leetcode338
    leetcode419
  • 原文地址:https://www.cnblogs.com/loubin/p/12296468.html
Copyright © 2011-2022 走看看