opencv – Image Processing – Smoothing Images with Gaussian Blur in C++

Smoothing, also known as blurring, is one of the most commonly used operation in Image Processing.

The most common use of the smoothing operation is to reduce noise in the image for further processing.

There are many algorithms to perform smoothing operation.

We’ll look at one of the most commonly used filter for blurring an image, the Gaussian Filter using the OpenCV library function GaussianBlur(). This filter is designed specifically for removing high-frequency noise from images.

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char** argv){

    Mat image , blurredImage;

    // Load the image file
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);

    // Report error if image could not be loaded
    if(!image.data){
        cout<<"Error loading image" << "\n";
        return -1;
    }

    // Apply the Gaussian Blur filter. 
    // The Size object determines the size of the filter (the "range" of the blur)
    GaussianBlur( image, blurredImage, Size( 9, 9 ), 1.0);

    // Show the blurred image in a named window
    imshow("Blurred Image" , blurredImage);

    // Wait indefinitely untill the user presses a key
    waitKey(0);

    return 0;
}

For the detailed mathematical definition and other types of filters you can check the original documentation.

if you want to reproduce, please indicate the source:
opencv – Image Processing – Smoothing Images with Gaussian Blur in C++ - CodeDay