[英]why Matlab fft2 is much faster than OpenCV dft
I just did test to compare the speed bewteen the dft function of OpenCV and fft2 in Matlab. 我只是在Matlab中进行了测试,以比较OpenCV和ftft2的dft函数之间的速度。 I load the same image, use fft2() and dft() to do the transform and measure the time they consumed.
我加载相同的图像,使用fft2()和dft()进行转换并测量它们消耗的时间。 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.
我发现对于图像,dft()在win32发行版中花费了2秒钟以上,而fft2()仅花费了约0.2s。 How come?
怎么会? The OpenCV version I used is 2.4.8 while the Matlab version is 2013 a.
我使用的OpenCV版本是2.4.8,而Matlab版本是2013 a。 Here is my codes for testing
这是我的测试代码
Matlab: Matlab的:
tic
X1 = fft2(im);
toc
OpenCV in C++: C ++中的OpenCV:
start1 = clock();
dft(src,src,DFT_COMPLEX_OUTPUT);
end1 = clock();
cout<<(double)(end1 - start1)/CLOCKS_PER_SEC<<endl;
In general fft is a fast implementation of dft. 通常,ftf是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. DFT是线性变换,其将长度为N的复数信号x作为输入,并且将长度为N的复数信号X作为输出给出,X = Wx。 W is a complex NxN matrix with entiries W_k,n=exp(-2pi k n/N), where 0 < k , n < N.
W是一个复数NxN矩阵,具有W_k,n = exp(-2pi k n / N)的项,其中0 <k,n <N.
FFT is a collection of algorithms for fast computation of the DFT. FFT是用于快速计算DFT的算法的集合。 Typically the number of operations required by the FFT is on the order of N*logN.
通常,FFT所需的运算数量约为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.
最著名的FFT算法是针对N是2的幂的情况,但是对于素数阶和不同的其他因式分解有FFT。
I've asked this and similar questions for very long time fft vs dft and Matlab vs c++ . 我已经问过这个问题和类似的问题很长时间了fft vs dft和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
. 最后说明:不建议使用
tic, toc
,而是使用timeit
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.