OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 18 Jun 2015 20:28:44 -0500please help regarding cropping a complex matrixhttp://answers.opencv.org/question/64362/please-help-regarding-cropping-a-complex-matrix/ Hi, I don't know why I can't access the other account I opened in Feb this year. So thanks to thudor who replied to my question in February.
Now the problem I am facing is, (I am still novice in opencv, so please bear):
1. I am taking DFT of an image.
2. From the complex output I am cropping a circular portion surrounding a set of coordinates.
3. I am doing inverse Fourier Transform of this cropped Image (the size of the cropped image is equal to the complex output of DFT).
4. Now when I take the magnitude of the IDFT its fine. But the phase is not what I get in MATLAB. I mean the pattern.
So, I tried to look at the possible troubles. When I am cropping the image, I am creating a mask.
temp = new_mask(complexI, real_center);
Mat new_mask(Mat q, max_intensity m)
{
Mat masks = Mat::zeros(q.size(), CV_8U);
circle(masks, Point(m.col_ref, m.row_ref), int(filter_rad), Scalar(255, 255, 255), -1, 8, 0); //-1 means filled
return masks;
}
And then using this mask I am cropping the complex matrix.
Mat cropped(complexI.size(), complexI.type(), Scalar::all(0));
complexI.copyTo(cropped, temp);
Do you think, because I used CV_8U as the type of the mask matrix it is causing trouble when I am doing inverse Fourier transform? Please suggest.
I tried using other data types like CV_64FC2 but then the sentence complexI.copyTo(cropped, temp) doesn't work. Even if I use the type complexI.type() for the masks matrix this sentence doesn't work.
I am giving an example of the comparison of phase output of IDFT in MATLAB and opencv. PLEASE HELP!!!![image description](/upfiles/14345961906952511.jpg)
The blue line is MATLAB output and the red one is opencv.
THANKS A LOT IN ADVANCE whoever helps :)Wed, 17 Jun 2015 21:59:11 -0500http://answers.opencv.org/question/64362/please-help-regarding-cropping-a-complex-matrix/Comment by berak for <p>Hi, I don't know why I can't access the other account I opened in Feb this year. So thanks to thudor who replied to my question in February. </p>
<p>Now the problem I am facing is, (I am still novice in opencv, so please bear):</p>
<ol>
<li>I am taking DFT of an image. </li>
<li>From the complex output I am cropping a circular portion surrounding a set of coordinates. </li>
<li>I am doing inverse Fourier Transform of this cropped Image (the size of the cropped image is equal to the complex output of DFT).</li>
<li>Now when I take the magnitude of the IDFT its fine. But the phase is not what I get in MATLAB. I mean the pattern. </li>
</ol>
<p>So, I tried to look at the possible troubles. When I am cropping the image, I am creating a mask. </p>
<pre><code>temp = new_mask(complexI, real_center);
</code></pre>
<p>Mat new_mask(Mat q, max_intensity m)
{</p>
<pre><code>Mat masks = Mat::zeros(q.size(), CV_8U);
circle(masks, Point(m.col_ref, m.row_ref), int(filter_rad), Scalar(255, 255, 255), -1, 8, 0); //-1 means filled
return masks;
</code></pre>
<p>}</p>
<p>And then using this mask I am cropping the complex matrix. </p>
<pre><code>Mat cropped(complexI.size(), complexI.type(), Scalar::all(0));
complexI.copyTo(cropped, temp);
</code></pre>
<p>Do you think, because I used CV_8U as the type of the mask matrix it is causing trouble when I am doing inverse Fourier transform? Please suggest. </p>
<p>I tried using other data types like CV_64FC2 but then the sentence complexI.copyTo(cropped, temp) doesn't work. Even if I use the type complexI.type() for the masks matrix this sentence doesn't work. </p>
<p>I am giving an example of the comparison of phase output of IDFT in MATLAB and opencv. PLEASE HELP!!!<img alt="image description" src="/upfiles/14345961906952511.jpg"/></p>
<p>The blue line is MATLAB output and the red one is opencv. </p>
<p>THANKS A LOT IN ADVANCE whoever helps :)</p>
http://answers.opencv.org/question/64362/please-help-regarding-cropping-a-complex-matrix/?comment=64376#post-id-64376"Do you think, because I used CV_8U as the type of the mask matrix it is causing trouble" - no, that's perfectly ok. if you're getting different results than matlab, it must be another reason. e.g. opencv's dft has 0.0 not at the center of the image, but at top-left cornerThu, 18 Jun 2015 00:51:30 -0500http://answers.opencv.org/question/64362/please-help-regarding-cropping-a-complex-matrix/?comment=64376#post-id-64376Comment by tkamal for <p>Hi, I don't know why I can't access the other account I opened in Feb this year. So thanks to thudor who replied to my question in February. </p>
<p>Now the problem I am facing is, (I am still novice in opencv, so please bear):</p>
<ol>
<li>I am taking DFT of an image. </li>
<li>From the complex output I am cropping a circular portion surrounding a set of coordinates. </li>
<li>I am doing inverse Fourier Transform of this cropped Image (the size of the cropped image is equal to the complex output of DFT).</li>
<li>Now when I take the magnitude of the IDFT its fine. But the phase is not what I get in MATLAB. I mean the pattern. </li>
</ol>
<p>So, I tried to look at the possible troubles. When I am cropping the image, I am creating a mask. </p>
<pre><code>temp = new_mask(complexI, real_center);
</code></pre>
<p>Mat new_mask(Mat q, max_intensity m)
{</p>
<pre><code>Mat masks = Mat::zeros(q.size(), CV_8U);
circle(masks, Point(m.col_ref, m.row_ref), int(filter_rad), Scalar(255, 255, 255), -1, 8, 0); //-1 means filled
return masks;
</code></pre>
<p>}</p>
<p>And then using this mask I am cropping the complex matrix. </p>
<pre><code>Mat cropped(complexI.size(), complexI.type(), Scalar::all(0));
complexI.copyTo(cropped, temp);
</code></pre>
<p>Do you think, because I used CV_8U as the type of the mask matrix it is causing trouble when I am doing inverse Fourier transform? Please suggest. </p>
<p>I tried using other data types like CV_64FC2 but then the sentence complexI.copyTo(cropped, temp) doesn't work. Even if I use the type complexI.type() for the masks matrix this sentence doesn't work. </p>
<p>I am giving an example of the comparison of phase output of IDFT in MATLAB and opencv. PLEASE HELP!!!<img alt="image description" src="/upfiles/14345961906952511.jpg"/></p>
<p>The blue line is MATLAB output and the red one is opencv. </p>
<p>THANKS A LOT IN ADVANCE whoever helps :)</p>
http://answers.opencv.org/question/64362/please-help-regarding-cropping-a-complex-matrix/?comment=64446#post-id-64446Hi Berak, Thanks a lot. I was thinking that cv_8U might cause a problem because the cropped portion is of complex type and the surrounding 0's are of cv_8u type.
Can you suggest if I use q.type() for the masks matrix type why complexI.copyTo(cropped, temp) doesn't work? :(Thu, 18 Jun 2015 20:28:44 -0500http://answers.opencv.org/question/64362/please-help-regarding-cropping-a-complex-matrix/?comment=64446#post-id-64446