OpenCV——边缘保留滤波EPF(Edge Preserve Filter)

原图像:
在这里插入图片描述
pymeanshift结果:
meanshift
bilateralfilter结果:
bilateralfilter
代码部分:

import numpy as np
import cv2 as cv


def bilateral_filter(image):
    # 高斯双边——边缘保留滤波
    # bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is
    #     .   very slow compared to most filters.
    # 双边过滤可以非常好的处理不需要的图片噪点(瑕点)同时清晰地保留边缘轮廓,缺点在于:高斯双边过滤相较与其它的滤波器运行速度较慢
    # 可以实现“磨皮”效果
    """
    参数介绍:
     src:Source 8-bit or floating-point, 1-channel or 3-channel image.8位或者浮点图片,单通道或者3通道RBG图片都可以
     d:Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
    .   it is computed from sigmaSpace.核函数直径,可以根据给出的sigmaSpace来计算,也可以直接给定。推荐d值不大于5(否则计算速度慢)
     sigmaColor:Filter sigma in the color space.色彩空间标准差,即同化多大“范围”内不同像素的颜色
     sigmaSpace:Filter sigma in the coordinate space. A larger value of the parameter means that
    .   farther pixels will influence each other as long as their colors are close enough (see sigmaColor
    .   ). When d\>0, it specifies the neighborhood size regardless of sigmaSpace. Otherwise, d is
    .   proportional to sigmaSpace.空间核标准差,值越大则同化范围越大(同化还受到sigmaColor影响)。可以通过制定 d 来计算,也可以直接给定
    """
    dst = cv.bilateralFilter(image, d=-1, sigmaColor=50, sigmaSpace=50)
    cv.imshow("bilateral_filter", dst)


def mean_shift(image):
    # 均值飘逸分割
    # 实现类似油画效果
    # 本算法是pyramid与meanshift的结合,当maxlevel设置为0时即为普通的meanshift
    """
        @param src The source 8-bit, 3-channel image. 输入图片
    .   @param dst The destination image of the same format and the same size as the source.
    .   @param sp The spatial window radius. 空间窗口半径
    .   @param sr The color window radius. 颜色窗口半径
    .   @param maxLevel Maximum level of the pyramid for the segmentation. 最大迭代次数
    .   @param termcrit Termination criteria: when to stop meanshift iterations. 退出迭代的判断依据
    """
    dst = cv.pyrMeanShiftFiltering(image, 25, 50)
    cv.imshow("mean_shift", dst)


src = cv.imread("data/before_filter.jpg")
cv.imshow("before", src)
# t1 = cv.getTickCount()
# bilateral_filter(src)
# t2 = cv.getTickCount()
# time = (t2-t1)/cv.getTickFrequency()*1000
# print("用时为:{}".format(time)+"ms")
mean_shift(src)

cv.waitKey(0)
cv.destroyAllWindows()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值