Accuracy of OpenCV's DFT (C++ implementation)

asked 2018-01-18 05:08:08 -0600

Colin Peeris gravatar image

updated 2018-01-18 05:39:29 -0600

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

Fig.2

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

edit retag flag offensive close merge delete

Comments

How can you guess value in second image? Is it an image spectrum?

LBerger gravatar imageLBerger ( 2018-01-18 05:17:08 -0600 )edit

Hi,

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.

Colin Peeris gravatar imageColin Peeris ( 2018-01-18 05:40:13 -0600 )edit

Come 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.

Colin Peeris gravatar imageColin Peeris ( 2018-01-18 05:47:05 -0600 )edit

please 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.)

berak gravatar imageberak ( 2018-01-18 06:13:33 -0600 )edit
1

BTW might be interesting to note that DFT and FFT are not identical ...

StevenPuttemans gravatar imageStevenPuttemans ( 2018-01-18 06:44:12 -0600 )edit