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的逆可以这样做:
// 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
1条答案
按热度按时间2mbi3lxu1#
回答我自己的问题…
在thesetwo参考的帮助下,我最终 * 不 * 使用DFT,而是使用OpenCV的
cv::dct()
和cv::idct()
。为了回答这个问题,
fftwf_plan_r2r_2d(...,FFTW_REDFT10, FFTW_REDFT10,...)
可以用这个OpenCV代码替换,并进行额外的缩放:字符串
FFTW_REDFT01
的逆可以这样做:型
更多有用的链接在这里和这里。
请注意,OpenCV仅支持行数和列数为偶数的图像。