55 #define KERNEL(r) (1.0-fabs((double)(r))/((double)R/2))
60 static int polar_grid(
int T,
int R,
double *x,
double *w)
63 double W=(double)T*(((
double)R/2.0)*((double)R/2.0)+1.0/4.0);
65 for(t=-T/2; t<T/2; t++)
67 for(r=-R/2; r<R/2; r++)
69 x[2*((t+T/2)*R+(r+R/2))+0] = (
double)r/R*cos(
PI*t/T);
70 x[2*((t+T/2)*R+(r+R/2))+1] = (
double)r/R*sin(
PI*t/T);
72 w[(t+T/2)*R+(r+R/2)] = 1.0/4.0/W;
74 w[(t+T/2)*R+(r+R/2)] = fabs((
double)r)/W;
87 double W=(double)T*(((
double)R/2.0)*((double)R/2.0)+1.0/4.0);
89 for(t=-T/2; t<T/2; t++)
91 for(r=-R/2; r<R/2; r++)
95 x[2*((t+T/2)*R+(r+R/2))+0] = (
double)r/R;
96 x[2*((t+T/2)*R+(r+R/2))+1] = (
double)4*(t+T/4)/T*r/R;
100 x[2*((t+T/2)*R+(r+R/2))+0] = -(
double)4*(t-T/4)/T*r/R;
101 x[2*((t+T/2)*R+(r+R/2))+1] = (
double)r/R;
104 w[(t+T/2)*R+(r+R/2)] = 1.0/4.0/W;
106 w[(t+T/2)*R+(r+R/2)] = fabs((
double)r)/W;
116 int Radon_trafo(
int (*gridfcn)(),
int T,
int R,
double *f,
int NN,
double *Rf)
122 fftw_plan my_fftw_plan;
130 N[0]=NN; n[0]=2*N[0];
131 N[1]=NN; n[1]=2*N[1];
133 fft = (fftw_complex *)
nfft_malloc(R*
sizeof(fftw_complex));
134 my_fftw_plan = fftw_plan_dft_1d(R,fft,fft,FFTW_BACKWARD,FFTW_MEASURE);
145 nfft_init_guru(&my_nfft_plan, 2, N, M, n, 4,
146 PRE_PHI_HUT| PRE_PSI| MALLOC_X | MALLOC_F_HAT| MALLOC_F| FFTW_INIT | FFT_OUT_OF_PLACE,
147 FFTW_MEASURE| FFTW_DESTROY_INPUT);
152 for(j=0;j<my_nfft_plan.
M_total;j++)
154 my_nfft_plan.
x[2*j+0] = x[2*j+0];
155 my_nfft_plan.
x[2*j+1] = x[2*j+1];
163 nfft_precompute_psi(&my_nfft_plan);
166 nfft_precompute_full_psi(&my_nfft_plan);
169 for(k=0;k<my_nfft_plan.
N_total;k++)
170 my_nfft_plan.
f_hat[k] = f[k] + _Complex_I*0.0;
179 for(r=-R/2+1; r<R/2; r++)
180 fft[r+R/2] =
KERNEL(r)*my_nfft_plan.
f[t*R+(r+R/2)];
183 fftw_execute(my_fftw_plan);
187 Rf[t*R+r] = creal(fft[r])/R;
197 fftw_destroy_plan(my_fftw_plan);
199 nfft_finalize(&my_nfft_plan);
207 int main(
int argc,
char **argv)
217 printf(
"radon gridfcn N T R\n");
219 printf(
"gridfcn \"polar\" or \"linogram\" \n");
220 printf(
"N image size NxN \n");
221 printf(
"T number of slopes \n");
222 printf(
"R number of offsets \n");
226 if (strcmp(argv[1],
"polar") == 0)
240 fp=fopen(
"input_data.bin",
"rb");
243 fread(f,
sizeof(
double),N*N,fp);
250 fp=fopen(
"sinogram_data.bin",
"wb+");
253 fwrite(Rf,
sizeof(
double),T*R,fp);