Note that there are some explanatory texts on larger screens.

plurals
  1. POMasking frequencies in a Fourier Transform
    primarykey
    data
    text
    <p>I'm messing around with OpenCV, and am trying to do some of the same stuff signal processing stuff I've done in MatLab. I'm looking to mask out some frequencies, so I have constructed a matrix which will do this. The problem is that there seem to be a few more steps in OpenCV than in Matlab to accomplish this.<br> In Matlab, it's simple enough:</p> <pre><code>F = fft2(image); smoothF = F .* mask; // multiply FT by mask smooth = ifft2(smoothF); // do inverse FT </code></pre> <p>But I'm having trouble doing the same in OpenCV. The DFT leaves me with a 2 channel image, so I've split the image, multiplied by the mask, merged it back, and then perform the inverse DFT. However, I got a weird result in my final image. I'm pretty sure I'm missing something...</p> <pre><code>CvMat* maskImage(CvMat* im, int maskWidth, int maskHeight) { CvMat* mask = cvCreateMat(im-&gt;rows, im-&gt;cols, CV_64FC1); cvZero(mask); int cx, cy; cx = mask-&gt;cols/2; cy = mask-&gt;rows/2; int left_x = cx - maskWidth; int right_x = cx + maskWidth; int top_y = cy + maskHeight; int bottom_y = cy - maskHeight; //create mask for(int i = bottom_y; i &lt; top_y; i++) { for(int j = left_x; j &lt; right_x; j++) { cvmSet(mask,i,j,1.0f); // Set M(i,j) } } cvShiftDFT(mask, mask); IplImage* maskImage, stub; maskImage = cvGetImage(mask, &amp;stub); cvNamedWindow("mask", 0); cvShowImage("mask", maskImage); CvMat* real = cvCreateMat(im-&gt;rows, im-&gt;cols, CV_64FC1); CvMat* imag = cvCreateMat(im-&gt;rows, im-&gt;cols, CV_64FC1); cvSplit(im, imag, real, NULL, NULL); cvMul(real, mask, real); cvMul(imag, mask, imag); cvMerge(real, imag, NULL, NULL, im); IplImage* maskedImage; maskedImage = cvGetImage(imag, &amp;stub); cvNamedWindow("masked", 0); cvShowImage("masked", maskedImage); return im; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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