import numpy as np
import cv2
path = "./058.jpg"
img = cv2.imread(path)
# 1.均值滤波
img_mean = cv2.blur(img, (3, 3))
# 2.双边滤波
img_bilater = cv2.bilateralFilter(img, 9, 75, 75)
# 3.高斯滤波
img_Guassian = cv2.GaussianBlur(img, (5, 5), 0)
# 4.中值滤波
img_median = cv2.medianBlur(img, 5)
# 5.快速引导滤波
def guidedfilter(I, p, r, eps):
height, width = I.shape
m_I = cv2.boxFilter(I, -1, (r, r))
m_p = cv2.boxFilter(p, -1, (r, r))
m_Ip = cv2.boxFilter(I * p, -1, (r, r))
cov_Ip = m_Ip - m_I * m_p
m_II = cv2.boxFilter(I * I, -1, (r, r))
var_I = m_II - m_I * m_I
a = cov_Ip / (var_I + eps)
b = m_p - a * m_I
m_a = cv2.boxFilter(a, -1, (r, r))
m_b = cv2.boxFilter(b, -1, (r, r))
return m_a * I + m_b
imd = guidedfilter(np.double(cv2.imread(path, 0)) / 255.0, img, 4 * 7, 0.001)
# 6.最小值滤波
image = cv2.erode(img, np.ones((14, 14)))
opencv的滤波实现方法:均值滤波,双边滤波,高斯滤波,中值滤波,快速引导滤波,最小值滤波。
最新推荐文章于 2024-08-14 09:37:12 发布