DFT 和 FFT(幅度)结果之间的差异

Diferences between DFT and FFT (magnitude) results

我的目标是在 OpenCV 中获取图像的 DFT

使用 dft 函数,我能够计算它,然后通过计算其大小来绘制它(然后,应用对数并最终对其进行归一化,以便绘制 0 到 1 之间的值)。

我的结果是,对于下图,我给你看的结果(为了在图像中心有较低的频率而交换):

但是,如果我将它与使用 Halcon 等其他工具获得的结果进行比较,这对我来说似乎是不正确的,因为它似乎确实具有 "high" 值(我的意思是 OpenCV DFT 幅度):

我认为可能是这些原因:

  1. DFT(在OpenCV)和FFT(Halcon)
  2. 之间的区别
  3. 我正在执行的操作为了在 OpenCV 中显示大小

第一个有一个问题,我很难分析,而且OpenCV没有FFT函数,Halcon也没有DFT功能(当然如果我没记错的话),所以我不能直接比较它。

第二个是我工作时间最长的一个,但我还是没有找到原因。

这是我用来绘制 img 大小的代码(这是我的 DFT 图像):

// 1.- To split the image in Re | Im values
Mat planes[] = {Mat_<float>(img), Mat::zeros(img.size(), CV_32F)};

// 2.- To magnitude + phase
split(img, planes);

// Calculate magnitude. I overwrite it, I know, but this is inside a function so it will be never used again, doesn't matter
magnitude(planes[0], planes[1], planes[0]);

// Magnitude Mat
Mat magI = planes[0];

// 3.- We add 1 to all them in order to perform the log
magI += Scalar::all(1);                    // switch to logarithmic scale
log(magI, magI);

// 4.- Swap the quadrants to center frequency
magI = magI(Rect(0, 0, magI.cols & -2, magI.rows & -2));
int cx = magI.cols/2;
int cy = magI.rows/2;

Mat q0(magI, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant
Mat q1(magI, Rect(cx, 0, cx, cy));  // Top-Right
Mat q2(magI, Rect(0, cy, cx, cy));  // Bottom-Left
Mat q3(magI, Rect(cx, cy, cx, cy)); // Bottom-Right

// swap quadrants (Top-Left with Bottom-Right)
Mat tmp;
q0.copyTo(tmp);
q3.copyTo(q0);
tmp.copyTo(q3);

// swap quadrant (Top-Right with Bottom-Left)
q1.copyTo(tmp);
q2.copyTo(q1);
tmp.copyTo(q2);

// 5.- Normalize
// Transform the matrix with float values into a
// viewable image form (float between values 0 and 1).
normalize(magI, magI, 0, 1, CV_MINMAX); 

// Paint it
imshow( "Magnitud DFT", magI);

所以总结一下:关于为什么我在这两个量级之间有这种差异

我会将我的评论总结成一个答案。

当人们考虑进行傅里叶变换以在逆域中工作时,假设是进行逆变换将 return 与 function/vector/whatever 相同。换句话说,我们假设

许多程序和库(例如 Mathematica、Matlab/octave、Eigen/unsupported/FFT, etc.). However, with many libraries (FFTW, KissFFT 等)都是这种情况,但情况并非如此,而且往往存在一个比例尺

其中 s 通常是数组中元素 (m) 的某次幂(如果在变换和逆过程中未以不匹配的方式缩放,则应为 1 ).这样做是为了避免迭代所有 m 元素乘以一个比例,通常是 not important.

也就是说,在查看逆域中的比例时,执行 缩放变换的各种库可以自由使用不同的比例进行变换和逆变换。 transform/inverse 的常见缩放对包括 {m^-1m} 和 {m^-0.5m^0.5}。因此,当比较来自不同库的结果时,我们应该准备好 m(按 m^-1 缩放与未缩放)、m^0.5(按 m^-0.5 缩放与未缩放)的因素。未按 m^-1 缩放与按 m^-0.5 缩放)或什至其他缩放比例(如果使用其他缩放因子)。

注意:这个比例因子与归一化数组有关,这样所有的值都是[0,1]或者数组的范数等于 1.