0

I wanted to ask where i can find how the GaussianBlur-function in OpenCV is implemented. While looking through the sourcecode i could only find this file but i´m looking for the code where the convolution is done. E.g something like this:

 for x to picture.rows
    for y to picture.cols
       for r to mask.width
         for c to mask.cols 
            do convolution

Does the OpenCV GaussianBlur calculates the Convolution for every Pixel or something like every second Pixel to speed it up?

Drian
  • 171
  • 1
  • 10
  • The implementation contains certain details from the computer vision field, which may not be on-topic for SO. – E_net4 Jun 23 '17 at 23:44

1 Answers1

-1

Below are few links where the Gaussian Filter has been implemented I hope it helps you.

Sample Code -

int main( int argc, char** argv )
{
    //create 2 empty windows
    namedWindow( "Original Image" , CV_WINDOW_AUTOSIZE );
    namedWindow( "Smoothed Image" , CV_WINDOW_AUTOSIZE );

    // Load an image from file
    Mat src = imread( "MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED );

    //show the loaded image
    imshow( "Original Image", src );

    Mat dst;
    char zBuffer[35];

    for ( int i = 1; i  <  31; i = i + 2 )
    {
        //copy the text to the "zBuffer"
        _snprintf_s(zBuffer, 35,"Kernel Size : %d x %d", i, i);

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

        //put the text in the "zBuffer" to the "dst" image
        putText( dst, zBuffer, Point( src.cols/4, src.rows/8), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255), 2 );

        //show the blurred image with the text
        imshow( "Smoothed Image", dst );

        //wait for 2 seconds
        int c = waitKey(2000);

        //if the "esc" key is pressed during the wait, return
        if (c == 27)
        {
            return 0;
        }
    }

    //make the "dst" image, black
    dst = Mat::zeros( src.size(), src.type() );

    //copy the text to the "zBuffer"
    _snprintf_s(zBuffer, 35,"Press Any Key to Exit");

    //put the text in the "zBuffer" to the "dst" image
    putText( dst, zBuffer, Point( src.cols/4,  src.rows / 2), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255) );

    //show the black image with the text
    imshow( "Smoothed Image", dst );

    //wait for a key press infinitely
    waitKey(0);

    return 0;
}

Links-

Link 1

Link2

  • While the links might answer the question, please consider copying the relevant contents from them into the answer. – E_net4 Jun 23 '17 at 10:48
  • This is not the implementation of the Gaussian filter... it's just some code that uses it. – Miki Jun 23 '17 at 11:29
  • Thanks for the answer. But my question was what kind of logic is hiding behind this : GaussianBlur( src, dst, Size( i, i ), 0, 0 ); – Drian Jun 23 '17 at 12:24