一杯清酒邀明月
天下本无事,庸人扰之而烦耳。

一、序言:

该教程承接上文的离散傅里叶变换,用于进行离散傅里叶逆变换。

二、设计目标

对复数数组进行离散傅里叶逆变换,并生成可供使用的图像类。

三、详细步骤

输入:经傅里叶变换后产生的复数数组

输出:MyImage图像

定义:

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

实现:

 1 MyImage* MyCV::Idft2(ComplexNumber *Scr, int width, int height)
 2 {
 3     int bytesPerLine = (width*8+31)/32*4;
 4     double* double_data = new double[width*height];
 5     memset(double_data,0,sizeof(double_data)*sizeof(double)); //全部赋值为0
 6 
 7     double fixed_factor_for_axisX = (2 * PI) / height;                  // evaluate i2π/N of i2πux/N, and store the value for computing efficiency
 8 
 9     double fixed_factor_for_axisY = (2 * PI) / width;                   // evaluate i2π/N of i2πux/N, and store the value for computing efficiency
10 
11     for (int x = 0; x<height; x++) {
12         for (int y = 0; y<width; y++) {
13             for (int u = 0; u<height; u++) {
14                 for (int v = 0; v<width; v++) {
15                     double powerU = u * x * fixed_factor_for_axisX;         // evaluate i2πux/N
16                     double powerV = v * y * fixed_factor_for_axisY;         // evaluate i2πux/N
17                     ComplexNumber cplTemp;
18                     cplTemp.SetValue(cos(powerU + powerV), sin(powerU + powerV));
19                     double_data[y + x*width] = double_data[y + x*width] +
20                             ((Scr[v + u*width] * cplTemp).m_rl
21                             /(height*width));
22                 }
23             }
24         }
25     }
26 
27     unsigned char *idft2_data = new unsigned char[bytesPerLine*height];//存储处理后的数据
28 
29     for(int i=0;i<height;i++)
30         for(int j=0;j<width;j++)
31         {
32             idft2_data[i*bytesPerLine+j] = (unsigned char)double_data[i*width+j];
33         }
34 
35     return new MyImage(idft2_data,width,height,MyImage::format::GRAY8);
36 }

至此,离散傅里叶逆变换的方法实现完成,效果图如下:

 

posted on 2022-02-21 14:02  一杯清酒邀明月  阅读(252)  评论(0编辑  收藏  举报