// Wrapper around FFTW3 that computes the real-valued inverse Fourier transform // of a complex-valued frequantial image. // The input data must be hermitic. static void ifft_2dfloat(float *ifx, fftwf_complex *fx, int w, int h) { fftwf_complex *a = fftwf_xmalloc(w*h*sizeof*a); fftwf_complex *b = fftwf_xmalloc(w*h*sizeof*b); //fprintf(stderr, "planning...\n"); evoke_wisdom(); fftwf_plan p = fftwf_plan_dft_2d(h, w, a, b, FFTW_BACKWARD, FFTW_ESTIMATE); bequeath_wisdom(); //fprintf(stderr, "...planned!\n"); FORI(w*h) a[i] = fx[i]; fftwf_execute(p); float scale = 1.0/(w*h); FORI(w*h) { fftwf_complex z = b[i] * scale; ifx[i] = crealf(z); if (FIWARN() > 0) { if (cimagf(z) > 0.001) fail("z is not real {cimagf(z)=%g} (set FIWARN=0 to run anyway)", cimagf(z)); //assert(cimagf(z) < 0.001); } }
static void transform_roi_buffers(float *y, float *x, int n, int roi) { float x_p0[3*n*n], *x_p = x_p0; ppsmooth_vec(x_p0, x, n, n, 3); if (roi == 2) x_p = x; if (roi == 3) { for (int i = 0; i < 3*n*n; i++) y[i]=x_p0[i]; return; } float *c = xmalloc(n*n*sizeof*c); float *ys = xmalloc(n*n*sizeof*c); fftwf_complex *fc = fftwf_xmalloc(n*n*sizeof*fc); for (int l = 0; l < 3; l++) { for (int i = 0; i < n*n; i++) c[i] = x_p[3*i+l]; fft_2dfloat(fc, c, n, n); for (int i = 0; i < n*n; i++) //ys[i] = cabs(fc[i]); ys[i] = 255*(log(cabs(fc[i])/255)+0.5)/5; //float fac = n*13; float fac = n*3; for (int j = 0; j < n; j++) for (int i = 0; i < n; i++) { int ii = (i + n/2) % n; int jj = (j + n/2) % n; float norm = hypot(i-n/2-1, j-n/2-1) / fac; y[3*(j*n+i)+l] = ys[jj*n+ii] * 1;//norm; } } free(ys); free(c); fftwf_free(fc); //float param[1] = {0.5}; //blur_2d(y, y, n, n, 3, "cauchy", param, 1); }
// wrapper around FFTW3 that computes the complex-valued Fourier transform // of a real-valued image static void fft_2dfloat(fftwf_complex *fx, float *x, int w, int h) { fftwf_complex *a = fftwf_xmalloc(w*h*sizeof*a); //fprintf(stderr, "planning...\n"); evoke_wisdom(); fftwf_plan p = fftwf_plan_dft_2d(h, w, a, fx, FFTW_FORWARD, FFTW_ESTIMATE); bequeath_wisdom(); //fprintf(stderr, "...planned!\n"); FORI(w*h) a[i] = x[i]; // complex assignment! fftwf_execute(p); fftwf_destroy_plan(p); fftwf_free(a); fftwf_cleanup(); }