我的目标DFT是在 OpenCV 中获取图像。
使用dft函数,我可以计算它,然后通过计算它的大小来绘制它(然后,应用对数并最终对其进行归一化以绘制 0 到 1 之间的值)。
我的结果是,对于下面的图像,我向您展示的结果(交换以在图像的中心具有较低的频率):

但是,如果我将它与使用其他工具(如Halcon )获得的结果进行比较,这对我来说似乎不正确,因为它似乎具有非常“高”的值(我的意思是 OpenCV DFT 量级):

我认为可能是以下原因:
第一个有我很难分析的问题,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);
Run Code Online (Sandbox Code Playgroud)
所以总结一下:关于为什么我在这两个量级之间有这种差异的任何想法?
我会将我的评论总结为一个答案。
当人们想到进行傅立叶变换以在逆域中工作时,假设进行逆变换将返回相同的函数/向量/任何东西。换句话说,我们假设

许多程序和库都是这种情况(例如 Mathematica、Matlab/octave、Eigen/unsupported/FFT等)。但是,对于许多库(FFTW、KissFFT等),情况并非如此,而且往往会有一个规模

其中s通常是m数组中元素的数量(这样做是为了避免迭代所有m元素乘以一个比例,这通常并不重要。
话虽这么说,看着逆域的规模时,各种图书馆做缩放变换要使用的变换和反变换不同尺度的自由。变换/逆的常见缩放对包括 { m^-1, m} 和 { m^-0.5, m^0.5}。因此,在比较来自不同库的结果时,我们应该准备好以下因素m(按比例缩放m^-1vs. 未缩放)、m^0.5(按比例缩放m^-0.5vs. 未缩放比例以及缩放比例m^-1vs. 缩放比例m^-0.5),如果使用其他比例因子,甚至其他比例.
注:该缩放因子不相关的归一化的阵列,以使得所有的值都是[0,1]或该阵列的范数等于1。