一、序言:
该教程承接上文的离散傅里叶变换,用于进行离散傅里叶逆变换。
二、设计目标
对复数数组进行离散傅里叶逆变换,并生成可供使用的图像类。
三、详细步骤
输入:经傅里叶变换后产生的复数数组
输出: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 }
至此,离散傅里叶逆变换的方法实现完成,效果图如下:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2020-02-21 C++ 回调函数简单示例
2020-02-21 Qt HWND的句柄与QWidget的转换