#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");
  if (img1.empty())
  {
    cout <<"could not found img..." << endl;
    return 0;
  }
  imshow(win1,img1);
  blur(img1,img2,Size(9,9),Point(-1,-1));
  imshow(win2, img2);
  return 0;
}

//高斯滤波
int demo_gaussian_blur()
{
  char win1[] = "window1";
  char win2[] = "window2";
  Mat img1, img2;

  img1 = imread("D://images//timg1.jpg");
  if (img1.empty())
  {
    cout << "could not found img..." << endl;
    return 0;
  }
  imshow(win1, img1);
  //blur(img1, img2, Size(9, 9), Point(-1, -1));
  GaussianBlur(img1, img2, Size(9, 9), 11, 11, 4);
  imshow(win2, img2);
  return 0;
}

//中值滤波
int demo_median_blur()
{
  char win1[] = "window1";
  char win2[] = "window2";
  Mat img1, img2;

  img1 = imread("D://images//2018092701.jpg");
  if (img1.empty())
  {
    cout << "could not found img..." << endl;
    return 0;
  }
  imshow(win1, img1);
  //blur(img1, img2, Size(9, 9), Point(-1, -1));
  //GaussianBlur(img1, img2, Size(9, 9), 11, 11, 4);
  medianBlur(img1, img2, 5);
  imshow(win2, img2);
  return 0;
}

//双边滤波
int demo_bilateral_filter()
{
  char win1[] = "window1";
  char win2[] = "window2";
  Mat img1, img2;

  img1 = imread("D://images//timg1.jpg");
  if (img1.empty())
  {
    cout << "could not found img..." << endl;
    return 0;
  }
  imshow(win1, img1);
  //blur(img1, img2, Size(9, 9), Point(-1, -1));
  //GaussianBlur(img1, img2, Size(9, 9), 11, 11, 4);
  //medianBlur(img1, img2, 5);
  bilateralFilter(img1, img2, 15, 100, 3, 4);
  imshow(win2, img2);
  return 0;
}

int main()
{
  //demo_blur();
  //demo_gaussian_blur();
  //demo_median_blur();
  demo_bilateral_filter();

  waitKey(0);
  return 0;
}

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

05-11 22:28