C++ Inverse Discrete Fourier Transform
1. Preface:
This tutorial builds on the discrete Fourier transform above and is used to perform the inverse discrete Fourier transform.
2. Design goals
Takes the inverse discrete Fourier transform of an array of complex numbers and produces a ready-to-use image class.
3. Detailed steps
Input: complex number array after Fourier transform
Output: MyImage image
definition:
static MyImage* Idft2(ComplexNumber *Scr,int const width,int const height);
实现: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 assignments are 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 the 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 method of inverse discrete Fourier transform has been completed, and the effect diagram is as follows:
If there are any mistakes in the above tutorial or code, criticism and testimony are welcome.