Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:41:00+00:00 2026-05-26T02:41:00+00:00

I am writing a function Conv2ByFFT() to do the Gaussian blur which is similar

  • 0

I am writing a function Conv2ByFFT() to do the Gaussian blur which is similar to the GaussianBlur() in openCV api. But as i compare the effects between by function and GaussianBlur() api, i find that the former is not as “blurred” as the latter and i don’t know why.

this is the “correct” one
this is the "correct" one

this is the result using my Conv2ByFFT()
this is the result using my Conv2ByFFT()

here’s some code

void Conv2ByFFT(const Mat& f,const Mat& g,Mat& result)
{
result.create(abs(f.rows-g.rows)+1,abs(f.cols-g.cols)+1,f.type());

//pad the images and get optimal FFT size
Size dftSize;
dftSize.width = getOptimalDFTSize(f.cols + g.cols - 1);
dftSize.height = getOptimalDFTSize(f.rows + g.cols - 1);

Mat tmpF(dftSize,f.type(),Scalar::all(0));
Mat tmpG(dftSize,g.type(),Scalar::all(0));

Mat roiF(tmpF, Rect(0,0,f.cols,f.rows));
f.copyTo(roiF);
Mat roiG(tmpG, Rect(0,0,g.cols,g.rows));
g.copyTo(roiG);

//perform Fourier Transform
dft(tmpF,tmpF,0,f.rows);
dft(tmpG,tmpG,0,g.rows);

//perform per-element multiplication of two Fourier spectrums
mulSpectrums(tmpF,tmpG,tmpF,0);

//perform inverse Fourier Transform
dft(tmpF,tmpF,DFT_INVERSE+DFT_SCALE,result.rows);

tmpF(Rect(0,0,result.cols,result.rows)).copyTo(result);
}

int main()
{
//read image
const char* imagename = "c:\\lena.bmp";
Mat img = imread(imagename);

//check image
if(img.empty())
{  fprintf(stderr, "Can not load image %s\n", imagename);
return -1;
} 
if( !img.data )
    return -1;

Mat src;

//convert the rgbimage into grayimage
cvtColor(img,src,CV_BGR2GRAY);

//save the grayimage
imwrite("lenagray.bmp",src);

//convert the image into float type 
src.convertTo(src,CV_64FC1);


//******************************************************************************
//                    use GaussianBlur() in openCV
//******************************************************************************

//use Gaussian filter to blur the image
Mat dst = src.clone();
GaussianBlur(src,dst,Size(11,11),2);

//show and save the result
dst.convertTo(dst,CV_8U);
imshow("image",dst);
imwrite("lenablur.bmp",dst);

//******************************************************************************
//                    use GaussianBlur() in openCV
//******************************************************************************




//******************************************************************************
//                    use self-defining Conv2ByFFT()
//******************************************************************************

Mat result;

Mat gaussianFilter = getGaussianKernel(11,2,CV_64FC1);

//do the convolution to blur the image
Conv2ByFFT(src,gaussianFilter,result);

//show and save the result
result.convertTo(result,CV_8U);
//imshow("image1",result);
imwrite("lenablur1.bmp",result);

//******************************************************************************
//                    use self-defining Conv2ByFFT()
//******************************************************************************


cvWaitKey();
return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:41:00+00:00Added an answer on May 26, 2026 at 2:41 am

    getGaussianKernel returns a vector of coefficients, not a 2-d kernel.

    As the 2-d Gaussian kernel is separable, in the convolution method, this vector is applied in both directions which has the same effect as applying the full kernel all at once.

    Your FFT function merely convolves the vector with the image. I think if you look carefully, the blur is only in one direction.

    You need to create a full 2-d gaussian kernel, and apply that. Alternatively, I think you can make use of the separability and apply the vector twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a function that should find a file. WIN32_FIND_DATAA* data; HANDLE handle =
As title stated, I'm writing function taking 2 boolean as parameters but don't know
I'm writing a function, which, given an argument, will either redirect the stdout to
I am writing a function in C++ which will take in 2 vectors of
I am writing one function on Javascript which needs to address all the anynymous
I'm currently writing a function which will take a variable number of arguments. I
I am writing a function to compare the contents of two lists. The order
While writing a function which will perform some operation with each number in a
I'm writing a function which will eventually use one of several possible cursors, for
I was writing a function for conversion between Decimal and Binary base number systems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.