# Accuracy of OpenCV's 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!

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.

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

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.

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.

please show your c++ code.

(and be so kind, to change your matlab screenshot for a

textversion, so folks can try it, qoute you, etc.)BTW might be interesting to note that DFT and FFT are not identical ...