44 #define NFFT_PRECISION_DOUBLE
50 #define KERNEL(r) (NFFT_K(1.0)-NFFT_M(fabs)((NFFT_R)(r))/((NFFT_R)S/2))
55 static int polar_grid(
int T,
int S, NFFT_R *x, NFFT_R *w)
58 NFFT_R W = (NFFT_R) T * (((NFFT_R) S / NFFT_K(2.0)) * ((NFFT_R) S / NFFT_K(2.0)) + NFFT_K(1.0) / NFFT_K(4.0));
60 for (t = -T / 2; t < T / 2; t++)
62 for (r = -S / 2; r < S / 2; r++)
64 x[2 * ((t + T / 2) * S + (r + S / 2)) + 0] = (NFFT_R) r / (NFFT_R)(S) * NFFT_M(cos)(NFFT_KPI * (NFFT_R)(t) / (NFFT_R)(T));
65 x[2 * ((t + T / 2) * S + (r + S / 2)) + 1] = (NFFT_R) r / (NFFT_R)(S) * NFFT_M(sin)(NFFT_KPI * (NFFT_R)(t) / (NFFT_R)(T));
67 w[(t + T / 2) * S + (r + S / 2)] = NFFT_K(1.0) / NFFT_K(4.0) / W;
69 w[(t + T / 2) * S + (r + S / 2)] = NFFT_M(fabs)((NFFT_R) r) / W;
82 NFFT_R W = (NFFT_R) T * (((NFFT_R) S / NFFT_K(2.0)) * ((NFFT_R) S / NFFT_K(2.0)) + NFFT_K(1.0) / NFFT_K(4.0));
84 for (t = -T / 2; t < T / 2; t++)
86 for (r = -S / 2; r < S / 2; r++)
90 x[2 * ((t + T / 2) * S + (r + S / 2)) + 0] = (NFFT_R) r / (NFFT_R)(S);
91 x[2 * ((t + T / 2) * S + (r + S / 2)) + 1] = NFFT_K(4.0) * ((NFFT_R)(t) + (NFFT_R)(T) / NFFT_K(4.0)) / (NFFT_R)(T) * (NFFT_R)(r)
96 x[2 * ((t + T / 2) * S + (r + S / 2)) + 0] = -NFFT_K(4.0) * ((NFFT_R)(t) - (NFFT_R)(T) / NFFT_K(4.0)) / (NFFT_R)(T)
97 * (NFFT_R)(r) / (NFFT_R)(S);
98 x[2 * ((t + T / 2) * S + (r + S / 2)) + 1] = (NFFT_R) r / (NFFT_R)(S);
101 w[(t + T / 2) * S + (r + S / 2)] = NFFT_K(1.0) / NFFT_K(4.0) / W;
103 w[(t + T / 2) * S + (r + S / 2)] = NFFT_M(fabs)((NFFT_R) r) / W;
118 NFFT(plan) my_nfft_plan;
119 SOLVER(plan_complex) my_infft_plan;
122 FFTW(plan) my_fftw_plan;
136 fft = (NFFT_C *) NFFT(malloc)((size_t)(S) *
sizeof(NFFT_C));
137 my_fftw_plan = FFTW(plan_dft_1d)(S,
fft,
fft, FFTW_FORWARD, FFTW_MEASURE);
139 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
143 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
148 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, 4,
153 SOLVER(init_advanced_complex)(&my_infft_plan,
158 for (j = 0; j < my_nfft_plan.M_total; j++)
160 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
161 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
163 my_infft_plan.w[j] = w[j];
165 my_infft_plan.w[j] = NFFT_K(0.0);
170 NFFT(precompute_lin_psi)(&my_nfft_plan);
172 if (my_nfft_plan.flags &
PRE_PSI)
173 NFFT(precompute_psi)(&my_nfft_plan);
176 NFFT(precompute_full_psi)(&my_nfft_plan);
179 for (t = 0; t < T; t++)
187 for (r = 0; r < S; r++)
188 fft[r] = Rf[t * S + r] + _Complex_I * NFFT_K(0.0);
190 NFFT(fftshift_complex_int)(
fft, 1, &S);
191 FFTW(execute)(my_fftw_plan);
192 NFFT(fftshift_complex_int)(
fft, 1, &S);
194 my_infft_plan.y[t * S] = NFFT_K(0.0);
195 for (r = -S / 2 + 1; r < S / 2; r++)
196 my_infft_plan.y[t * S + (r + S / 2)] =
fft[r + S / 2] /
KERNEL(r);
200 for (k = 0; k < my_nfft_plan.N_total; k++)
201 my_infft_plan.f_hat_iter[k] = NFFT_K(0.0) + _Complex_I * NFFT_K(0.0);
204 SOLVER(before_loop_complex)(&my_infft_plan);
209 for (k = 0; k < my_nfft_plan.N_total; k++)
210 my_infft_plan.f_hat_iter[k] = my_infft_plan.p_hat_iter[k];
214 for (l = 1; l <=
max_i; l++)
216 SOLVER(loop_one_step_complex)(&my_infft_plan);
223 for (k = 0; k < my_nfft_plan.N_total; k++)
224 f[k] = NFFT_M(creal)(my_infft_plan.f_hat_iter[k]);
227 FFTW(destroy_plan)(my_fftw_plan);
229 SOLVER(finalize_complex)(&my_infft_plan);
230 NFFT(finalize)(&my_nfft_plan);
238 int main(
int argc,
char **argv)
249 printf(
"inverse_radon gridfcn N T R max_i\n");
251 printf(
"gridfcn \"polar\" or \"linogram\" \n");
252 printf(
"N image size NxN \n");
253 printf(
"T number of slopes \n");
254 printf(
"R number of offsets \n");
255 printf(
"max_i number of iterations \n");
259 if (strcmp(argv[1],
"polar") == 0)
268 max_i = atoi(argv[5]);
270 Rf = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
271 iRf = (NFFT_R *) NFFT(malloc)((size_t)(N * N) * (
sizeof(NFFT_R)));
274 fp = fopen(
"sinogram_data.bin",
"rb");
277 fread(Rf,
sizeof(NFFT_R), (
size_t)(T * S), fp);
284 fp = fopen(
"output_data.bin",
"wb+");
287 fwrite(iRf,
sizeof(NFFT_R), (
size_t)(N * N), fp);
static int max_i(int a, int b)
max
static void fft(int N, int M, int Z, fftw_complex *mem)
fft makes an 1D-ftt for every knot through all layers
#define PRECOMPUTE_WEIGHT
#define KERNEL(r)
define weights of kernel function for discrete Radon transform
static int inverse_radon_trafo(int(*gridfcn)(), int T, int S, NFFT_R *Rf, int NN, NFFT_R *f, int max_i)
computes the inverse discrete Radon transform of Rf on the grid given by gridfcn() with T angles and ...
static int polar_grid(int T, int S, NFFT_R *x, NFFT_R *w)
generates the points x with weights w for the polar grid with T angles and R offsets
int main(int argc, char **argv)
simple test program for the inverse discrete Radon transform
static int linogram_grid(int T, int S, NFFT_R *x, NFFT_R *w)
generates the points x with weights w for the linogram grid with T slopes and R offsets