Inverse Discrete Fourier

130 views Asked by At

apparently i have some troubles with my code, but after one day of searching i dont know how to continue.

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++;
    }
}
}

The Output greyscale image

The output looks like the right pixel values are calculated, but stored in the wrong position. Both pointers passed to the method point to a Vector object, which have the same size and are in row mayor layout. So the index formula (k*M+l) should be right?

M is the width, N is the hight of the image.

Thanks!

0

There are 0 answers