OpenCv 026---高斯双边滤波

1 前备知识

此前的图像卷积处理无论是均值还是高斯都是属于模糊卷积,它们都有一个共同的特点就是模糊之后图像的边缘信息不复存在或者受到了破坏。而高斯双边滤波可以通过卷积处理实现图像模糊的同时减少图像边缘破坏,滤波之后的输出完整的保存了图像整体边缘(轮廓)信息,我们称这类滤波算法为边缘保留滤波算法(EPF)。最常见的边缘保留滤波算法有以下几种:

- 高斯双边模糊:高斯模糊是考虑图像空间位置对权重的影响,但是它没有考虑图像像素分布对图像卷积输出的影响,双边模糊考虑了像素值分布的影响,对像素值空间分布差异较大的进行保留从而完整的保留了图像的边缘信息。

- Meanshift均值迁移模糊:TODO

- 局部均方差模糊:TODO

- OpenCV中对边缘保留滤波还有一个专门的API:下文

2 所用到的主要OpenCv API

/** @brief Applies the bilateral filter to an image.
The function applies bilateral filtering to the input image, as described in
http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
bilateralFilter can reduce unwanted noise very well while keeping edges fairly sharp. However, it is
very slow compared to most filters.
_Sigma values_: For simplicity, you can set the 2 sigma values to be the same. If they are small (\<
10), the filter will not have much effect, whereas if they are large (\> 150), they will have a very
strong effect, making the image look "cartoonish".
_Filter size_: Large filters (d \> 5) are very slow, so it is recommended to use d=5 for real-time
applications, and perhaps d=9 for offline applications that need heavy noise filtering.
This filter does not work inplace.
@param src Source 8-bit or floating-point, 1-channel or 3-channel image.
@param dst Destination image of the same size and type as src .
@param d Diameter of each pixel neighborhood that is used during filtering. If it is non-positive,
it is computed from sigmaSpace.
@param sigmaColor Filter sigma in the color space. A larger value of the parameter means that
farther colors within the pixel neighborhood (see sigmaSpace) will be mixed together, resulting
in larger areas of semi-equal color.
@param 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.
@param borderType border mode used to extrapolate pixels outside of the image, see #BorderTypes
 */
CV_EXPORTS_W void bilateralFilter( InputArray src, OutputArray dst, int d,
                                   double sigmaColor, double sigmaSpace,
                                   int borderType = BORDER_DEFAULT );

3 程序代码

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int artc, char** argv) {
    Mat src = imread("images/Demo.jpg");
    if (src.empty()) {
        printf("could not load image...\n");
        return -1;
    }
    namedWindow("input", CV_WINDOW_AUTOSIZE);
    imshow("input", src);

    Mat dst;
    bilateralFilter(src, dst, 0, 100, 10, 4);
    imshow("result", dst);

    waitKey(0);
    return 0;
}

4 运行结果

5 扩展及注意事项

none

6*目前只做大概了解,知道有这一算法,后续具体使用再做具体分析

原文地址:https://www.cnblogs.com/Vince-Wu/p/11846886.html

时间: 2024-08-09 09:50:39

OpenCv 026---高斯双边滤波的相关文章

python+opencv实现高斯平滑滤波

功能: 创建两个滑动条来分别控制高斯核的size和σ的大小,这个程序是在阈值分割的那个程序上改动的.阈值分割程序在这 注意:由于σ=0时,opencv会根据窗口大小计算出σ,所以,从0滑动σ的滑动条时,会出现先边清晰又变模糊的现象 python+opencv实现阈值分割 python+opencv实现霍夫变换检测直线 (2016-5-10)到OpenCV-Python Tutorials's documentation!可以下载 代码: # -*- coding: utf-8 -*- impor

双边滤波

Qt 平台,双边滤波原理代码例如以下: #include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include <cmath> using namespace cv; usi

【OpenCV】邻域滤波:方框、高斯、中值、双边滤波

原文:http://blog.csdn.net/xiaowei_cqu/article/details/7785365 邻域滤波(卷积) 邻域算子值利用给定像素周围像素的值决定此像素的最终输出.如图左边图像与中间图像卷积禅城右边图像.目标图像中绿色的像素由原图像中蓝色标记的像素计算得到. 通用线性邻域滤波是一种常用的邻域算子,输入像素加权得到输出像素: 其中权重核   为“滤波系数”.上面的式子可以简记为: [方框滤波] 最简单的线性滤波是移动平均或方框滤波,用 窗口中的像素值平均后输出,核函数

图像平滑技术之盒滤波、均值滤波、中值滤波、高斯滤波、双边滤波的原理概要及OpenCV代码实现

图像平滑是指直接对源图像的每个像素数据做邻域运算以达到平滑图像的目的.实质上主要就是通达卷积核算子实现的,卷积核算子的相关知识大家可以参考我写的博文http://blog.csdn.net/wenhao_ir/article/details/51691410 图像平滑也称为模糊或滤波,是图像处理中常用的技术之一,进行平滑处理时需要用到滤波器核(其实就是卷积核算子),根据滤波器核函数来实现不同的滤波技术.下面介绍几种 常用的图像平滑方法的大概原理及OpenCV下的实现代码. 一.盒滤波(均值滤波)

OpenCv高斯,中值,均值,双边滤波

#include "cv.h" #include "highgui.h" #include <iostream> using namespace std; using namespace cv; int main(int argc, char* argv[]) { Mat src = imread("misaka.jpg"); Mat dst; //参数是按顺序写的 //高斯滤波 //src:输入图像 //dst:输出图像 //Siz

Atitit &#160;&#160;图像处理&#160;平滑&#160;也称&#160;模糊,&#160;归一化块滤波、高斯滤波、中值滤波、双边滤波)

Atitit   图像处理 平滑 也称 模糊, 归一化块滤波.高斯滤波.中值滤波.双边滤波) 是一项简单且使用频率很高的图像处理方法 用途 去噪 去雾 各种线性滤波器对图像进行平滑处理,相关OpenCV函数如下: 归一化块滤波器 (Normalized Box Filter) § 最简单的滤波器, 输出像素值是核窗口内像素值的 均值 ( 所有像素加权系数相等) § 高斯滤波器 (Gaussian Filter) § 最有用的滤波器 (尽管不是最快的). 高斯滤波是将输入数组的每一个像素点与 高斯

【OPENCV入门之六】非线性滤波(中值滤波、双边滤波)

参考网站: http://blog.csdn.net/poem_qianmo/article/details/23184547 在很多情况下,比如在噪声是散粒噪声而不是高斯噪声时(图像偶尔会出现很大的值的时候),在这种情况下,用高斯滤波器对图像进行模糊的话,噪声是不会被去除的,它们只是转换为更为柔和但仍然可见的散粒.而用非线性滤波会更好些. 1.中值滤波(Median filter)--medianBlur函数 该方法在去除脉冲噪声.斑点噪声(speckle noise).椒盐噪声(salt-a

opencv3 图片模糊操作-均值滤波 高斯滤波 中值滤波 双边滤波

#include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; //均值滤波模糊处理int demo_blur(){ char win1[] = "window1"; char win2[] = "window2"; Mat img1, img2; img1 = imread("D://images//4.jpg&quo

数学之路-python计算实战(18)-机器视觉-滤波去噪(双边滤波与高斯滤波 )

高斯滤波就是对整幅图像进行加权平均的过程,每一个像素点的值,都由其本身和邻域内的其他像素值经过加权平均后得到.高斯滤波的具体操作是:用一个模板(或称卷积.掩模)扫描图像中的每一个像素,用模板确定的邻域内像素的加权平均灰度值去替代模板中心像素点的值. #滤波去噪 lbimg=cv2.GaussianBlur(newimg,(3,3),1.8) cv2.imshow('src',newimg) cv2.imshow('dst',lbimg) cv2.waitKey() cv2.destroyAllW