Reputation: 33
I just did test to compare the speed bewteen the dft function of OpenCV and fft2 in Matlab. I load the same image, use fft2() and dft() to do the transform and measure the time they consumed. I found that for the image the dft() costed over 2 second in the win32 release version while the fft2() only took round 0.2s. How come? The OpenCV version I used is 2.4.8 while the Matlab version is 2013 a. Here is my codes for testing
Matlab:
tic
X1 = fft2(im);
toc
OpenCV in C++:
start1 = clock();
dft(src,src,DFT_COMPLEX_OUTPUT);
end1 = clock();
cout<<(double)(end1 - start1)/CLOCKS_PER_SEC<<endl;
Upvotes: 1
Views: 1182
Reputation: 4191
I've asked this and similar questions for very long time fft vs dft and Matlab vs c++. The answer I found is,
On the other hand,
Final note: it is not recommended to use tic, toc
, instead use timeit
.
Upvotes: 0
Reputation: 1073
In general fft is a fast implementation of dft.
DFT is a linear transform which takes as input a complex signal x of length N and gives as output a complex signal X of length N, X=Wx. W is a complex NxN matrix with entiries W_k,n=exp(-2pikn/N), where 0 < k , n < N.
FFT is a collection of algorithms for fast computation of the DFT. Typically the number of operations required by the FFT is on the order of N*logN. The most famous FFT algorithms are for the case that N is a power of 2, but there are FFT for prime orders and for different other factorizations.
Upvotes: 1