概念介绍
2,双边滤波函数bilateralFilter()
实例
#include
using namespace std;
using namespace cv;
Mat g_srcimage, g_dstimage1, g_dstimage2, g_dstimage3, g_dstimage4, g_dstimage5;
int g_nBoxFliterValue = 3;
int g_nMeanBlurValue = 3;
int g_nGaussianBlurValue = 3;
int g_nMedianBlurValue = 3;
int g_nBeliteralValue = 3;
static void on_BoxFliter(int, void*);
static void on_MeanBlur(int, void*);
static void on_GaussianBlur(int, void*);
static void on_Medianblur(int, void*);
static void on_Bilateral(int, void*);
int main()
{
system("color 5E");
g_srcimage = imread("D://1.jpg", 1);
if (!g_srcimage.data) { printf("错错错\n"); return false; }
g_dstimage1 = g_srcimage.clone();
g_dstimage2 = g_srcimage.clone();
g_dstimage3 = g_srcimage.clone();
g_dstimage4 = g_srcimage.clone();
g_dstimage5 = g_srcimage.clone();
namedWindow("原图窗口", 1);
imshow("原图窗口", g_srcimage);
namedWindow("方框滤波", 1);
createTrackbar("内核值:","方框滤波",&g_nBoxFliterValue,40,on_BoxFliter);
on_BoxFliter(g_nBoxFliterValue, 0);
namedWindow("均值滤波", 1);
createTrackbar("内核值:", "均值滤波", &g_nMeanBlurValue, 40, on_MeanBlur);
on_MeanBlur(g_nMeanBlurValue, 0);
namedWindow("高斯滤波", 1);
createTrackbar("内核值:", "高斯滤波", &g_nGaussianBlurValue, 40, on_GaussianBlur);
on_GaussianBlur(g_nGaussianBlurValue, 0);
namedWindow("中值滤波", 1);
createTrackbar("参数值:", "中值滤波", &g_nMedianBlurValue ,40, on_Medianblur);
on_Medianblur(g_nMedianBlurValue, 0);
namedWindow("双边滤波", 1);
createTrackbar("参数值:", "双边滤波", &g_nBeliteralValue, 40, on_Bilateral);
on_Bilateral(g_nBeliteralValue, 0);
cout << endl << "滑动滚动条观察图像效果\n\n"
<< "按下q键退出";
while (char(waitKey(1)) != 'q') {}
return 0;
}
static void on_BoxFliter(int, void*)
{
boxFilter(g_srcimage, g_dstimage1, -1, Size(g_nBoxFliterValue + 1, g_nBoxFliterValue + 1));
imshow("方框滤波", g_dstimage1);
}
static void on_MeanBlur(int, void*)
{
blur(g_srcimage, g_dstimage2, Size(g_nMeanBlurValue + 1, g_nMeanBlurValue + 1),Point(-1,-1));
imshow("均值滤波", g_dstimage2);
}
static void on_GaussianBlur(int, void*)
{
GaussianBlur(g_srcimage, g_dstimage3, Size(g_nGaussianBlurValue*2 + 1, g_nGaussianBlurValue*2+ 1),0,0);
imshow("高斯滤波", g_dstimage3);
}
static void on_Medianblur(int, void*)
{
medianBlur(g_srcimage, g_dstimage4, g_nMedianBlurValue * 2 + 1);
imshow("中值滤波", g_dstimage4);
}
static void on_Bilateral(int, void*)
{
bilateralFilter(g_srcimage, g_dstimage5, g_nBeliteralValue, g_nBeliteralValue*2, g_nBeliteralValue/2);
imshow("双边滤波", g_dstimage5);
}