Blurring is built on the same concept of 2D Convolution, difference being the change in kernel matrix.
Blurring averages the pixel values around one particular pixel.
Looks simple, but blurring is much more than just Convolution, it requires some more concepts of variance, averaging, etc.
A very simple kernel is a box kernel:
1 1 1 1 1
1 1 1 1 1
Blurring averages the pixel values around one particular pixel.
Looks simple, but blurring is much more than just Convolution, it requires some more concepts of variance, averaging, etc.
A very simple kernel is a box kernel:
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
This kernel deems every pixel equally important. A better kernel would be one that decreases the effect of a pixel as its distance from the central pixel increases. The Gaussian kernel does this, and is the most commonly used blurring kernel:
1 4 6 4 1
4 16 24 16 4
6 24 36 24 6
4 16 24 16 4
1 4 6 4 1
------------------------------------------------------------------------
#include<iostream>
#include<cv.h>
#include<highgui.h>
using namespace std;
using namespace cv;
int main()
{
Mat img_b,img=imread("images/image.jpg");
float blur[5][5]={{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1},{1,1,1,1,1}};
// simple box kernel
//float blur[5][5]={{1,4,6,4,1},{4,16,24,16,4},{6,24,36,24,6},{4,16,24,16,4},{1,4,6,4,1}};
// Guassian kernel
Mat filter_b=Mat(5,5,CV_32FC1,blur);
filter2D(img,img_b,-1,filter_b);
namedWindow("Image");
namedWindow("Image_B");
imshow("Image",img);
imshow("Image_B",img_b);
while(char(waitKey(0))!='q'){}
return 0;
}
-------------------------------------------------------------------------
Note: Blurring is more than just Convolution. If you want to go further, please visit THIS documentation. Following is the basic application of 'GaussianBlur()' function.
--------------------------------------------------------------------------
Input Image:
#include<iostream>
#include<cv.h>
#include<highgui.h>
using namespace std;
using namespace cv;
int main()
{
Mat img_b,img=imread("images/image.jpg");
int k=5;
//you can vary the value of 'k' from 1 to 5, in this case.
int sigma = 0.3 * ((k - 1) * 0.5 - 1) + 0.8;
GaussianBlur(img, img_b, Size(k, k), sigma);
namedWindow("Image");
namedWindow("Image_B");
imshow("Image",img);
imshow("Image_B",img_b);
while(char(waitKey(0))!='q'){}
return 0;
}
-------------------------------------------------------------
Result:


No comments:
Post a Comment