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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:14:00+00:00 2026-05-31T05:14:00+00:00

I want to create a Gaussian high-pass filter after determining the correct padding size

  • 0

I want to create a Gaussian high-pass filter after determining the correct padding size (e.g., if image width and height is 10X10, then should be 20X20).

I have Matlab code that I am trying to port in OpenCV, but I am having difficulty properly porting it. My Matlab code is show below:

f1_seg = imread('thumb1-small-test.jpg');

Iori = f1_seg;


% Iori = imresize(Iori, 0.2);

%Convert to grayscale
I = Iori;
if length(size(I)) == 3
    I = rgb2gray(Iori);
end
% 

%Determine good padding for Fourier transform

PQ = paddedsize(size(I));

I = double(I);

%Create a Gaussian Highpass filter 5% the width of the Fourier transform

D0 = 0.05*PQ(1);

H = hpfilter('gaussian', PQ(1), PQ(2), D0);

% Calculate the discrete Fourier transform of the image.

F=fft2(double(I),size(H,1),size(H,2));

% Apply the highpass filter to the Fourier spectrum of the image

HPFS_I = H.*F;

I know how to use the DFT in OpenCV, and I am able to generate its image, but I am not sure how to create the Gaussian filter. Please guide me to how I can create a high-pass Gaussian filter as is shown above?

  • 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-31T05:14:01+00:00Added an answer on May 31, 2026 at 5:14 am

    I believe where you are stuck is that the Gaussian filter supplied by OpenCV is created in the spatial (time) domain, but you want the filter in the frequency domain. Here is a nice article on the difference between high and low-pass filtering in the frequency domain.

    Once you have a good understanding of how frequency domain filtering works, then you are ready to try to create a Gaussian Filter in the frequency domain. Here is a good lecture on creating a few different (including Gaussian) filters in the frequency domain.

    If you are still having difficulty, I will try to update my post with an example a bit later!

    EDIT :
    Here is a short example that I wrote on implementing a Gaussian high-pass filter (based on the lecture I pointed you to):

    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    
    #include <iostream>
    
    using namespace cv;
    using namespace std;
    
    double pixelDistance(double u, double v)
    {
        return cv::sqrt(u*u + v*v);
    }
    
    double gaussianCoeff(double u, double v, double d0)
    {
        double d = pixelDistance(u, v);
        return 1.0 - cv::exp((-d*d) / (2*d0*d0));
    }
    
    cv::Mat createGaussianHighPassFilter(cv::Size size, double cutoffInPixels)
    {
        Mat ghpf(size, CV_64F);
    
        cv::Point center(size.width / 2, size.height / 2);
    
        for(int u = 0; u < ghpf.rows; u++)
        {
            for(int v = 0; v < ghpf.cols; v++)
            {
                ghpf.at<double>(u, v) = gaussianCoeff(u - center.y, v - center.x, cutoffInPixels);
            }
        }
    
        return ghpf;
    }
    
    
    int main(int /*argc*/, char** /*argv*/)
    {
        Mat ghpf = createGaussianHighPassFilter(Size(128, 128), 16.0);
    
        imshow("ghpf", ghpf);
        waitKey();
    
        return 0;
    }
    

    This is definitely not an optimized filter generator by any means, but I tried to keep it simple and straight forward to ease understanding 🙂 Anyway, this code displays the following filter:

    enter image description here

    NOTE : This filter is not FFT shifted (i.e., this filter works when the DC is placed in the center instead of the upper-left corner). See the OpenCV dft.cpp sample (lines 62 – 74 in particular) on how to perform FFT shifting in OpenCV.

    Enjoy!

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

Sidebar

Related Questions

i want create image animation , i have 50 images with png format now
How to create simple Gaussian Blur filter with HLSL (for Silverlight)? Why - I
I want create a drop shadow around the canvas component in flex. Technically speaking
I want create a excel with Apache POI in java and I must insert
I want create module which update list of usb devices automatically (not only mass
I want to create a Java application bundle for Mac without using Mac. According
I want to create a client side mail creator web page. I know the
I want to create a function that performs a function passed by parameter on
I want to create a simple http proxy server that does some very basic
I want to create a draggable and resizable window in JavaScript for cross browser

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.