显然我的代码有些问题,但是经过一天的搜索,我不知道如何继续。
void DiscreteFourier2D::reconstruct(
int M, int N,
std::complex<float> const *spectrum,
std::complex<float> *reconstruction) {
float A = (1.f / sqrt(M * N));
for (int k = 0; k <= M - 1; k++) {
for (int l = 0; l <= N - 1; l++) {
std::complex<float> total(0.f, 0.f);
for (int m = 0; m <= M - 1; m++) {
for (int n = 0; n <= N - 1; n++) {
//std::complex<float> fourier = spectrum[m * (M) + n];
std::complex<float> fourier = *spectrum;
spectrum++;
std::complex<float> i(0.f, 1.f);
float mM = (float) m / (float) M;
float nN = (float) n / (float) N;
float e_1 = 2.f * M_PI * k * (mM - 0.5);
float e_2 = 2.f * M_PI * l * (nN - 0.5);
total += fourier * exp(e_1 * i) * exp(e_2 * i);
}
}
reconstruction[(k*M)+l]=total*A;
//(*reconstruction) = A * total;
//reconstruction++;
}
}
}
输出看起来像是计算了正确的像素值,但存储在错误的位置。传递给该方法的两个指针都指向一个 Vector 对象,该对象具有相同的大小并且采用 row mayor 布局。那么指数公式(k*M+l)应该是对的吧?
M是宽度,N是图像的高度。
谢谢!