Skip to content

Instantly share code, notes, and snippets.

@sumit4iit
Created October 26, 2013 15:37
Show Gist options
  • Save sumit4iit/7170825 to your computer and use it in GitHub Desktop.
Save sumit4iit/7170825 to your computer and use it in GitHub Desktop.
#include<iostream>
#include "cv.h"
#include "highgui.h"
#include <cstring>
using namespace cv;
using namespace std;
int main()
{
string path = "res/download.jpg";
Mat src = imread(path,CV_LOAD_IMAGE_ANYCOLOR);
if(!src.data)
{
cout<<"fail\n";
return -1;
}
Mat blurBlock, gaussian, median, bilateral;
int kernel_size = 5;
// Blur operator.
// Size defines size of kernel
// Point is an anchor point , and here point -1,-1 defines a center point of the mask.
// BORDER_DEFAULT specifies the border type for padding image.
// For more explanation please read my post on filter2d.
// Blur operator.
blur(src,blurBlock,Size(kernel_size,kernel_size), Point(-1,-1), BORDER_DEFAULT);
// Gaussian Filter
// The two 0s after Size(kernel_size,kernel_size) specify the valuse of sigma1 and sigma2.
// Here 0 and 0 represent that value of sigmax and sigmay should be calculated from the dimension of kernel
GaussianBlur(src,gaussian,Size(kernel_size,kernel_size), 0, 0, BORDER_DEFAULT);
// Median Blur
// Default size of kernel.
medianBlur(src, median, kernel_size);
// Display the results
namedWindow("Input",CV_WINDOW_AUTOSIZE);
namedWindow("Block",CV_WINDOW_AUTOSIZE);
namedWindow("Gaussian",CV_WINDOW_AUTOSIZE);
namedWindow("Median",CV_WINDOW_AUTOSIZE);
imshow("Input",src);
imshow("Block",blurBlock);
imshow("Gaussian",gaussian);
imshow("Median",median);
// wait for keypress event.
waitKey(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment