函数说明:
/** @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 );
@param src 输入图像
@param dst 输出图像
@param d 过滤过程中每个像素领域的直径范围,若非正数,则从sigmaspace计算
@param sigmaColor 值越大,表示像素领域内就有多宽的颜色会被混在一起
@param sigmaSpace 值越大,就代表有更大范围的相同颜色像素会相互影响,从而使更大区域的相似颜色,获取到相同的颜色
程序源码:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <stdio.h>
using namespace cv;
using namespace std;
RNG rng(12345);
Scalar color[7] = {
(Scalar(0,0,255)),//红色
(Scalar(0,255,0)),//绿色
(Scalar(255,0,0)),//蓝色
(Scalar(255,255,0)),//浅蓝色
(Scalar(255,0,255)),//紫色
(Scalar(0,255,255)),//黄色
(Scalar(128,128,192)),//浅粉色
};
int main()
{
Mat image,img_bilFilter;
image = imread("../face.jpg", 1);
if (image.empty()) {
cout << "无此图片" << endl;
return 0;
}
img_bilFilter = image.clone();
while (1)
{
imshow("原图", image);
waitKey(1);
bilateralFilter(image, img_bilFilter, 0, 100, 5);
imshow("高斯双边模糊", img_bilFilter);
waitKey(1);
}
return 1;
}