本文介绍了等效于FFTW_REDFT01的FFTW fftwf_plan_r2r_2d()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试移植使用FFTW的代码以使用KissFFT.
该代码使用FFTW_REDFT01 .

I am trying to port code that uses FFTW to use KissFFT.
The code uses fftwf_plan_r2r_2d() with FFTW_REDFT01.

KissFFT中的等效调用是什么?

What would be the equivalent call in KissFFT?

如果此调用(使用FFTW_REDFT01)等效于DCT,我是否可以直接使用直接DCT转换,例如例如 OpenCV cv::dct ?
我需要做一些输入数据修改,例如反射和对称化吗?

If this call (with FFTW_REDFT01) is equivalent to a DCT, could I just use a direct DCT transform instead, e.g. such as OpenCV cv::dct?
Is there some input data modification I'd need to do, like reflections and symmetrizations?

推荐答案

回答我自己的问题...
借助这些 两个引用,我最终完全不使用DFT而是完全使用DFT,而是使用了OpenCV的cv::dct()cv::idct()反而.

Answering my own question...
With the help of these two references, I ended up not using DFT at all, but using OpenCV's cv::dct() and cv::idct() instead.

要回答这个问题,可以用以下OpenCV代码将fftwf_plan_r2r_2d(...,FFTW_REDFT10, FFTW_REDFT10,...)替换为其他缩放比例:

To answer the question, fftwf_plan_r2r_2d(...,FFTW_REDFT10, FFTW_REDFT10,...) can be replaced by this OpenCV code with the additional scaling:

cv::dct(img, resFFT); // fwd dct. This is like Matlab's dct2()
resFFT *= (4 * sqrt(float(img.rows/2)) * sqrt(float(img.cols/2)));
resFFT.row(0) *= sqrt(2.f);
resFFT.col(0) *= sqrt(2.f);

FFTW_REDFT01的反函数可以这样完成:

The inverse with FFTW_REDFT01 can be done like so:

// First re-scale the data for idct():
resFFT /= (4 * sqrt(float(img.rows/2)) * sqrt(float(img.cols/2)));
resFFT.row(0) /= sqrt(2.f);
resFFT.col(0) /= sqrt(2.f);
cv::idct(resFFT, outImg); // this will return the input exactly

// However, the transforms computed by FFTW are unnormalized, exactly like the corresponding,
// so computing a transform followed by its inverse yields the original array scaled by N, where N is the logical DFT size.
// The logical DFT size: Logical N=2*n for each axis, this is th implicit symmetrization
// of the image: reflect right and then reflect both halves down.
int logicalSizeN = (2*img.rows) * (2*img.cols);
outImg *= logicalSizeN; // scale to be like FFTW result

更多有用的链接此处此处.

请注意,OpenCV仅支持行和列数偶数的图像.

Note that OpenCV supports only images with an even number of rows and columns.

这篇关于等效于FFTW_REDFT01的FFTW fftwf_plan_r2r_2d()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 02:22