How to Smooth An Image Using Gaussian Blur

Introduction

In this document, it will be explanied how to smooth/blur an image with using Gaussian Blur function. OpenCV library and Visual Studio software are used and the function is implemented in C++ programming language.

Brief Information About Gaussian Blur

Gaussian Blur is a method used for blurring with Gaussian Function in image processing. It benefits with reducing image noise and handling with high frequency images.

Gaussian Function is a function used for defining normal distribution widely. Two-dimensional Gaussian function is used in image processing for blurring. One-dimensional function is defined as:

Figure 1: Gaussian Function

Configuring and Implementing OpenCV Library with Visual Studio Software

OpenCV library can be downloaded from its organization page. After downloading, OpenCV library should be configured with Visual Studio by following these steps¹.

By installing OpenCV in Visual Studio, the library can be used with lines of code:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

C++ Code Snippet for Gaussian Blur

OpenCV library has already got a function for Gaussian Blur defined as follows:

void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT) Note: Mat is a data type for n-dimensional arrays in OpenCV.

A C++ code snippet to filter an image using Gaussian Blur:

	Mat src = imread( "C:\\opencv\\samples\\sample.jpg", CV_LOAD_IMAGE_UNCHANGED );

	Mat dst;

	//smooth the image using Gaussian kernel in the "src" and save it to "dst"
	GaussianBlur( src, dst, Size( 4, 4 ), 0, 0 );
	

Input & Output Images

Two figures, one of them is original image(src) and one of them is output image(dst), are shown below.

Original Image Blurred Image
Figure 2: Original Peppers Image
Figure 3: Original Peppers Image

References

¹ Shermal Fernando, "Installing & Configuring with Visual Studio", n.d., taken from http://opencv-srf.blogspot.com.tr/2013/05/installing-configuring-opencv-with-vs.html, accessed: 09-04-2016