使用C ++的2D图像的DFT-不良结果

时间:2018-11-10 17:13:26

标签: c++ image-processing fft dft

我尝试用C ++ Qt编写DFT。我使用带有exp功能的版本。我尝试了许多版本,并且始终得到相同的结果。第一个DFT用于行,第二个用于列。图像400 x 400 RGB。这是对的吗?如果没有,那是什么问题?

using namespace std;
complex<double> *tab;
tab = new complex<double>[640000];
complex<double> i(0.0, 1.0);

for (int j = 0; j < 400; ++j) {
    for (int k = 0; k < 400; ++k) {
        complex<double> sum(0.0, 0.0);

        for (int n = 0; n < 400; ++n) {
            int t = (j * 400 + n) << 2;
            complex<double> arg = -i * ((2.0 * M_PI * k * n) / 400);
            complex<double> val(tmp[t] / 255.0, 0.0); //tmp - unsigned char, values R G B

            sum += val * exp(arg);
        }
        int t = (j * 400 + k) << 2;

        tab[t] = sum;
        tab[t + 1] = sum;
        tab[t + 2] = sum;
    }
}

for (int j = 0; j < 400; ++j) {
    for (int k = 0; k < 400; ++k) {
        complex<double> sum(0.0, 0.0);

        for (int n = 0; n < 400; ++n) {
            int t = (n * 400 + j) << 2;
            complex<double> arg = -i * ((2.0 * M_PI * k * n) / 400);
            sum += tab[t] * exp(arg);
        }

        int t = (k * 400 + j) << 2;
        unsigned char p;

        p = static_cast<unsigned char>(static_cast<int>(round(abs(sum))) % 256);

        buf[t] = p;
        buf[t + 1] = p;
        buf[t + 2] = p;
    }
}

delete tab;

我使用图片:

enter image description here

结果:

enter image description here

0 个答案:

没有答案