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,
151 FFTW_MEASURE | FFTW_DESTROY_INPUT);
154 SOLVER(init_advanced_complex)(&my_infft_plan,
159 for (j = 0; j < my_nfft_plan.M_total; j++)
161 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
162 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
164 my_infft_plan.w[j] = w[j];
166 my_infft_plan.w[j] = NFFT_K(0.0);
171 NFFT(precompute_lin_psi)(&my_nfft_plan);
173 if (my_nfft_plan.flags &
PRE_PSI)
174 NFFT(precompute_psi)(&my_nfft_plan);
177 NFFT(precompute_full_psi)(&my_nfft_plan);
180 for (t = 0; t < T; t++)
188 for (r = 0; r < S; r++)
189 fft[r] = Rf[t * S + r] + _Complex_I * NFFT_K(0.0);
191 NFFT(fftshift_complex_int)(
fft, 1, &S);
192 FFTW(execute)(my_fftw_plan);
193 NFFT(fftshift_complex_int)(
fft, 1, &S);
195 my_infft_plan.y[t * S] = NFFT_K(0.0);
196 for (r = -S / 2 + 1; r < S / 2; r++)
197 my_infft_plan.y[t * S + (r + S / 2)] = fft[r + S / 2] /
KERNEL(r);
201 for (k = 0; k < my_nfft_plan.N_total; k++)
202 my_infft_plan.f_hat_iter[k] = NFFT_K(0.0) + _Complex_I * NFFT_K(0.0);
205 SOLVER(before_loop_complex)(&my_infft_plan);
210 for (k = 0; k < my_nfft_plan.N_total; k++)
211 my_infft_plan.f_hat_iter[k] = my_infft_plan.p_hat_iter[k];
215 for (l = 1; l <=
max_i; l++)
217 SOLVER(loop_one_step_complex)(&my_infft_plan);
224 for (k = 0; k < my_nfft_plan.N_total; k++)
225 f[k] = NFFT_M(creal)(my_infft_plan.f_hat_iter[k]);
228 FFTW(destroy_plan)(my_fftw_plan);
230 SOLVER(finalize_complex)(&my_infft_plan);
231 NFFT(finalize)(&my_nfft_plan);
239 int main(
int argc,
char **argv)
250 printf(
"inverse_radon gridfcn N T R max_i\n");
252 printf(
"gridfcn \"polar\" or \"linogram\" \n");
253 printf(
"N image size NxN \n");
254 printf(
"T number of slopes \n");
255 printf(
"R number of offsets \n");
256 printf(
"max_i number of iterations \n");
260 if (strcmp(argv[1],
"polar") == 0)
269 max_i = atoi(argv[5]);
271 Rf = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
272 iRf = (NFFT_R *) NFFT(malloc)((size_t)(N * N) * (
sizeof(NFFT_R)));
275 fp = fopen(
"sinogram_data.bin",
"rb");
278 fread(Rf,
sizeof(NFFT_R), (
size_t)(T * S), fp);
285 fp = fopen(
"output_data.bin",
"wb+");
288 fwrite(iRf,
sizeof(NFFT_R), (
size_t)(N * N), fp);
static int max_i(int a, int b)
max
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 ...
#define PRECOMPUTE_WEIGHT
static void fft(int N, int M, int Z, fftw_complex *mem)
fft makes an 1D-ftt for every knot through all layers
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 ...
#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 ...