I'm trying to implement the MATLAB fft2() and ifft2() function in C++ using OpenCV and the FFTW3.3 library. I've been able to successfully port the code, which perform the forward and inverse transforms correctly. But,the complex numeric values of the dft matrix generated by MATLAB R2009a fft2() function differs greatly from its FFTW counterpart. I need to resolve this issue for optimum performance my application. I'm providing my C++ implementations and sample input/output below:
For example, the above mentioned fft2() function is called using the following code:
cv::Mat im(2,2,CV_64FC2);
im.at<cv::Vec2d>(0,0)[0] = 1;
im.at<cv::Vec2d>(0,0)[0] = 0;
im.at<cv::Vec2d>(0,1)[1] = 1;
im.at<cv::Vec2d>(0,1)[1] = 0;
im.at<cv::Vec2d>(1,0)[0] = 1;
im.at<cv::Vec2d>(1,0)[1] = 0;
im.at<cv::Vec2d>(1,1)[0] = 1;
im.at<cv::Vec2d>(1,1)[1] = 0;
int rows = im.rows;
int cols = im.cols;
cv::Mat imagefft(rows,cols,CV_64FC2);
imagefft = fft2(im);
For x = [ 1+1i 1+1i; 1+1i 1+1i] the fft2(x) provides
[4.0000 + 4.0000i 0; 0 0 ] where fftw implementation provides,
[-6.27744e+066-6.27744e+066i 6.27744e+066-6.27744e+066i ; -6.27744e+066-6.27744e+066i 6.27744e+066-6.27744e+066i ]
I need to understand what is the relation between these two matrix, if any.
Looking forward to your suggestions.
Thanks in advance.