Ricardo
Ricardo

Reputation: 1356

Why the Fourier transform does not look correct in C++?

I'm trying to calculate the Fourier transform of an image with a lib called FftComplex

I am processing this image: enter image description here

I should get and output like this: enter image description here

But instead I'm getting this: enter image description here

This is part of the code:

    // Convert the raw images to vectors
        PF_PixelFloat* pixelPointerAtIndex;
        for (unsigned long index= 0; index < imgArraySize; index++){
            pixelPointerAtIndex = (PF_PixelFloat*)((char*)inWorld.data + (index * sizeof(PF_PixelFloat)));
            imgRedDataVector.push_back( (std::complex<double>) pixelPointerAtIndex->red);
            imgGreenDataVector.push_back((std::complex<double>) pixelPointerAtIndex->green);
            imgBlueDataVector.push_back((std::complex<double>) pixelPointerAtIndex->blue);
        }

    // Fourier Transform
        fft::transform(imgRedDataVector);
        fft::transform(imgGreenDataVector);
        fft::transform(imgBlueDataVector);

    // Copy the Fourier data back to the image
        for (unsigned long index = 0; index < imgArraySize; index++) {
            pixelPointerAtIndex = (PF_PixelFloat*)((char*)inWorld.data + (index * sizeof(PF_PixelFloat)));
            pixelPointerAtIndex->red    = imgRedDataVector[index].real();
            pixelPointerAtIndex->green  = imgGreenDataVector[index].real();
            pixelPointerAtIndex->blue   = imgBlueDataVector[index].real();
        }

I also have try this:

    finalImgRedDataVector[index].imag()
    ...

It seams like I am getting the "Argument" but maybe I'm getting the "Modulus" ?

Does any body knows what is wrong with this or what I'm missing?

Thanks.

Upvotes: 0

Views: 80

Answers (1)

MSalters
MSalters

Reputation: 179779

You're not getting the "Argument" either. Complex numbers have two parts, "real" and "imaginary". Picturing them as X and Y coordinate, the argument is the angle they make, and magnitude is the distance to the origin. It's the magnitude which is depicted in the second image.

In C++, that's abs(std::complex)

Upvotes: 1

Related Questions