1 /* dft.c - discrete fourier transformation program */
4 * author: frank.zirkelbach@physik.uni-augsburg.de
10 int main(int argc,char **argv) {
25 strcpy(src.file,argv[1]);
26 strcpy(dst.file,argv[2]);
28 fourier_init(&fourier,1);
34 dst.width=src.info.width;
35 dst.height=src.info.height;
38 fourier.data_len[0]=src.info.width;
39 fourier.data_len[1]=src.info.height;
40 fourier_alloc_data(&fourier);
42 mag=(double *)malloc(fourier.data_len[0]*fourier.data_len[1]*sizeof(double));
44 printf("unable to alloc mag memory\n");
50 for(y=0;y<fourier.data_len[1];y++) {
51 for(x=0;x<fourier.data_len[0];x++) {
53 fourier.data[offt].r=(src.map[offt].r+src.map[offt].g+src.map[offt].b)/3;
55 offy+=fourier.data_len[0];
58 // do the fourier trafo
59 fourier_dft_2d(&fourier);
61 printf("fourier done!\n");
63 // copy back the data, intensity = sqrt(r^2+i^2)
66 for(y=0;y<fourier.data_len[1];y++) {
67 for(x=0;x<fourier.data_len[0];x++) {
69 mag[offt]=sqrt(fourier.ftdata[offt].r*fourier.ftdata[offt].r+fourier.ftdata[offt].i*fourier.ftdata[offt].i);
70 if(mag[offt]>max) max=mag[offt];
72 offy+=fourier.data_len[0];
75 if(max!=0) scale=(int)255/max;
79 printf("scaling image intensity: %d\n",scale);
80 for(x=0;x<dst.width*dst.height;x++) {
81 dst.map[x].r=scale*mag[x];
82 dst.map[x].g=dst.map[x].r;
83 dst.map[x].b=dst.map[x].r;
91 fourier_shutdown(&fourier);