Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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. <a href="http://paulbourke.net/miscellaneous/imagefilter/" rel="noreferrer">Here</a> is a nice article on the difference between high and low-pass filtering in the frequency domain. </p> <p>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. <a href="http://vision.yeditepe.edu.tr/EE562/files/EE469_4.pdf" rel="noreferrer">Here</a> is a good lecture on creating a few different (including Gaussian) filters in the frequency domain.</p> <p><strike>If you are still having difficulty, I will try to update my post with an example a bit later!</strike></p> <p><strong>EDIT :</strong> Here is a short example that I wrote on implementing a Gaussian high-pass filter (based on the lecture I pointed you to):</p> <pre><code>#include &lt;opencv2/core/core.hpp&gt; #include &lt;opencv2/highgui/highgui.hpp&gt; #include &lt;iostream&gt; 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 &lt; ghpf.rows; u++) { for(int v = 0; v &lt; ghpf.cols; v++) { ghpf.at&lt;double&gt;(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; } </code></pre> <p>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:</p> <p><img src="https://i.stack.imgur.com/qEEmu.jpg" alt="enter image description here"></p> <p><strong>NOTE :</strong> 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 <a href="https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/dft.cpp" rel="noreferrer">dft.cpp</a> sample (lines 62 - 74 in particular) on how to perform FFT shifting in OpenCV.</p> <p>Enjoy!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload