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 Jan 2018 06:44:12 -0600Accuracy of OpenCV's DFT (C++ implementation)http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong.
Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!
![Fig.1](/upfiles/15162731822390162.jpg)
![Fig.2](/upfiles/15162732072692394.jpg)
I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.
![MATLAB code](/upfiles/15162755494912427.jpg)Thu, 18 Jan 2018 05:08:08 -0600http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/Comment by berak for <p>I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong. </p>
<p>Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!</p>
<p><img alt="Fig.1" src="/upfiles/15162731822390162.jpg"></p>
<p><img alt="Fig.2" src="/upfiles/15162732072692394.jpg"></p>
<p>I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.</p>
<p><img alt="MATLAB code" src="/upfiles/15162755494912427.jpg"></p>
http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182738#post-id-182738please show your c++ code.
(and be so kind, to change your matlab screenshot for a **text** version, so folks can try it, qoute you, etc.)Thu, 18 Jan 2018 06:13:33 -0600http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182738#post-id-182738Comment by StevenPuttemans for <p>I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong. </p>
<p>Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!</p>
<p><img alt="Fig.1" src="/upfiles/15162731822390162.jpg"></p>
<p><img alt="Fig.2" src="/upfiles/15162732072692394.jpg"></p>
<p>I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.</p>
<p><img alt="MATLAB code" src="/upfiles/15162755494912427.jpg"></p>
http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182741#post-id-182741BTW might be interesting to note that DFT and FFT are not identical ...Thu, 18 Jan 2018 06:44:12 -0600http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182741#post-id-182741Comment by Colin Peeris for <p>I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong. </p>
<p>Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!</p>
<p><img alt="Fig.1" src="/upfiles/15162731822390162.jpg"></p>
<p><img alt="Fig.2" src="/upfiles/15162732072692394.jpg"></p>
<p>I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.</p>
<p><img alt="MATLAB code" src="/upfiles/15162755494912427.jpg"></p>
http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182736#post-id-182736Come to think of it, I'm actually FFTing an array with negative values. MATLAB deals with it just fine I guess. However, for the OpenCV code, I have to convert the double values to an image using...
m.at<uchar>(i, j) = input[i][j]*255;
where imput[i][j] is of double type and m is Mat.Thu, 18 Jan 2018 05:47:05 -0600http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182736#post-id-182736Comment by Colin Peeris for <p>I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong. </p>
<p>Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!</p>
<p><img alt="Fig.1" src="/upfiles/15162731822390162.jpg"></p>
<p><img alt="Fig.2" src="/upfiles/15162732072692394.jpg"></p>
<p>I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.</p>
<p><img alt="MATLAB code" src="/upfiles/15162755494912427.jpg"></p>
http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182734#post-id-182734Hi,
Thanks for the reply. I've also included my MATLAB code as it is neater than my C++ code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.Thu, 18 Jan 2018 05:40:13 -0600http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182734#post-id-182734Comment by LBerger for <p>I'm coding a with C++ and OpenCV. I'm comparing the outputs (complex numbers) of MATLAB's FFT function and OpenCV's DFT function. I am able to get identical results for normal images such as the one below (Fig. 1). However, after some processing to get the image (Fig. 2), the values are very different by orders of magnitude and I think the OpenCV's output is wrong. </p>
<p>Is this expected of the OpenCV's DFT function? I've tried all sorts of things like putting "DFT_SCALE" as well. Any suggestions please? Thanks!</p>
<p><img alt="Fig.1" src="/upfiles/15162731822390162.jpg"></p>
<p><img alt="Fig.2" src="/upfiles/15162732072692394.jpg"></p>
<p>I've also included my MATLAB code. Fig.1 is the variable assigned "S" and Fig.2 is the variable "Normin2". (product of imshow(Normin2)). Normin2 has a maximum value of 1.359 and a minimum value of -1.2667.</p>
<p><img alt="MATLAB code" src="/upfiles/15162755494912427.jpg"></p>
http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182731#post-id-182731How can you guess value in second image? Is it an image spectrum?Thu, 18 Jan 2018 05:17:08 -0600http://answers.opencv.org/question/182729/accuracy-of-opencvs-dft-c-implementation/?comment=182731#post-id-182731