6, C + + inverse discrete Fourier transform

C + + inverse discrete Fourier transform

1, Preface:

This course takes on the above discrete Fourier transform and is used for inverse discrete Fourier transform.

 

2, Design objectives

The complex array is transformed by inverse discrete Fourier transform, and the available image classes are generated.

 

3, Detailed steps

Input: complex array generated by Fourier transform

Exporting: MyImage images

Definition:

static MyImage* Idft2(ComplexNumber *Scr,int const width,int const height);

 

Implementation: MyImage * MyCV::Idft2(ComplexNumber * Scr, int width, int height)

{

    int bytesPerLine = (width*8+31)/32*4;

 

    double* double_data = new double[width*height];

    memset(double_data,0,sizeof(double_data)*sizeof(double)); //All assigned to 0

 

    double fixed_factor_for_axisX = (2 * PI) / height;                  // evaluate i2π/N of i2πux/N, and store the value for computing efficiency

    double fixed_factor_for_axisY = (2 * PI) / width;                   // evaluate i2π/N of i2πux/N, and store the value for computing efficiency

    for (int x = 0; x<height; x++) {

        for (int y = 0; y<width; y++) {

            for (int u = 0; u<height; u++) {

                for (int v = 0; v<width; v++) {

                    double powerU = u * x * fixed_factor_for_axisX;         // evaluate i2πux/N

                    double powerV = v * y * fixed_factor_for_axisY;         // evaluate i2πux/N

                    ComplexNumber cplTemp;

                    cplTemp.SetValue(cos(powerU + powerV), sin(powerU + powerV));

                    double_data[y + x*width] = double_data[y + x*width] +

                            ((Scr[v + u*width] * cplTemp).m_rl

                            /(height*width));

                }

            }

        }

    }

 

    unsigned char *idft2_data = new unsigned char[bytesPerLine*height];//Store processed data

 

    for(int i=0;i<height;i++)

        for(int j=0;j<width;j++)

        {

            idft2_data[i*bytesPerLine+j] = (unsigned char)double_data[i*width+j];

        }

 

    return new MyImage(idft2_data,width,height,MyImage::format::GRAY8);

}

 

So far, the implementation of the inverse discrete Fourier transform is completed, and the effect diagram is as follows:

 

 

If there are any errors in the above tutorials or codes, you are welcome to criticize and testify.

Tags: C++

Posted on Tue, 31 Mar 2020 18:35:05 -0700 by christa