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 9015897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:51:51+00:00 2026-06-16T03:51:51+00:00

im using the following code to calculate convolution of an image with a specified

  • 0

im using the following code to calculate convolution of an image with a specified kernel(in my case gaussian). Everytime I get a different result and the result image is not even close to the one i obtained by convolution in the Spatial domain. First I thought the problem is with the datatype of the images. I changed them to 32 and 64 but still the same results. Can anyone tell me what could be wrong?

http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#dft
this function above is giving me a black image. I have input in GRAYSCALE.

void convol_fft(const Mat& A,const vector<vector<float>>& kernel2d,Mat& result)
{

    Mat B = Mat(3,3,CV_64F);
    for (int row = 0; row < kernel2d.size(); row++)
        for (int col = 0; col < kernel2d[row].size(); col++){
            B.at<uchar>(row,col) = (uchar)kernel2d[row][col];
        }

    int dft_M = getOptimalDFTSize( A.rows+B.rows-1 );
    int dft_N = getOptimalDFTSize( A.cols+B.cols-1 );
    Mat dft_A = Mat::zeros(dft_M, dft_N, CV_64F);
    Mat dft_B = Mat::zeros(dft_M, dft_N, CV_64F);

    Mat dft_A_part = dft_A(Rect(0, 0, A.cols,A.rows));
    A.convertTo(dft_A_part, dft_A_part.type(), 1, -mean(A)[0]);
    Mat dft_B_part = dft_B(Rect(0, 0, B.cols,B.rows));
    B.convertTo(dft_B_part, dft_B_part.type(), 1, -mean(B)[0]);

    dft(dft_A, dft_A, 0, A.rows);
    dft(dft_B, dft_B, 0, B.rows);

    // set the last parameter to false to compute convolution instead of correlation
    mulSpectrums( dft_A, dft_B, dft_A, 0, false );
    idft(dft_A, dft_A, DFT_SCALE, A.rows + B.rows - 1 );

    result = dft_A(Rect(0, 0, A.cols + B.cols - 1, A.rows + B.rows - 1));
    normalize(result, result, 0, 1, NORM_MINMAX, result.type());
    pow(result, 3., result);

  //  B ^= Scalar::all(255);

}
  • 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-06-16T03:51:52+00:00Added an answer on June 16, 2026 at 3:51 am

    I am not sure about OpenCV…but this looks suspicious.

    for (int row = 0; row < kernel2d.size(); row++)
        for (int col = 0; col < kernel2d[row].size(); col++){
            B.at<uchar>(row,col) = (uchar)kernel2d[row][col];
     }
    

    If you are filling up the B kernel then the row should be kernel2d[col].size(). It looks like you are overrunning the B kernel. What is value of kernel2d.size() ?

    Why not just load the values directly? Saving all the function calls.

    For gaussian kernel it should look something like {1,2,1,2,3,2,1,2,1}.

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

Sidebar

Related Questions

I am using the following code snippet to calculate a total price. This works
i am using the following code(based on this http://goo.gl/5HhSx ) to calculate the difference
Using following code I try to get updated list of checkbuttons' corresponding text values,
I am using following code to get bitmap from url. This function is used
I have the following code which I'm using to calculate the price of a
I'm using the following code to calculate the moments and the position of an
I'm using the following code to calculate the interval for decreasing the whole division
I want to calculate area and perimeter of rects using the following code: rect
I'm using the following code to resize an image so it fits inside a
I am using the following PHP code to calculate a CRN for BPay: <?php

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.