图像平滑滤波

import cv2 as cv
import numpy as np

def gauss_noise(image, mean = 0, var = 0.001):
    """
    添加高斯噪声
    :param image: 图像
    :param mean: 均值
    :param var: 方差
    :return: 添加噪声后的图像
    """
    image = np.array(image/255, dtype = float)
    noise = np.random.normal(mean, var ** 0.5, image.shape)
    out = image + noise
    if out.min() < 0:
        low_clip = -1.
    else:
        low_clip = 0.
    out = np.clip(out, low_clip, 1.0)
    out = np.uint8(out*255)

    return out


img = cv.imread('1.png')
img = gauss_noise(img) #原图加入高斯噪声

blur = cv.blur(img, (5, 5)) #平均滤波
gauss = cv.GaussianBlur(img, (5, 5), 0) #高斯滤波
median = cv.medianBlur(img,5)   #中值滤波
bilateral = cv.bilateralFilter(img, 5, 150, 150)  #双边滤波

cv.imshow('Image', img)
cv.imshow('blur', blur)
cv.imshow('gauss', gauss)
cv.imshow('median', median)
cv.imshow('bilateral', bilateral)

cv.waitKey()
cv.destroyAllWindows()

 

你可能感兴趣的:(计算机视觉)