其中f(x,y)为原图像,F(u,v)为傅里叶变换以后的结果,根据欧拉公式可得,每个F(u,v)值都为复数,由实部和虚部组成
代码示例
1 void dft(short** in_array, double** re_array, double** im_array, long height, long width) 2 { 3 double re, im, temp; 4 5 for (int i = 0; i < height; i++){ 6 for (int j = 0; j < width; j++){ 7 re = 0; 8 im = 0; 9 10 for (int x = 0; x < height; x++){ 11 for (int y = 0; y < width; y++){ 12 temp = (double)i * x / (double)height + 13 (double)j * y / (double)width; 14 re += in_array[x][y] * cos(-2 * pi * temp); 15 im += in_array[x][y] * sin(-2 * pi * temp); 16 } 17 } 18 19 re_array[i][j] = re; 20 im_array[i][j] = im; 21 } 22 } 23 printf("dft done\n"); 24 }