47 #define NFFT_PRECISION_DOUBLE
53 #define KERNEL(r) (NFFT_K(1.0)-NFFT_M(fabs)((NFFT_R)(r))/((NFFT_R)S/2))
58 static int polar_grid(
int T,
int S, NFFT_R *x, NFFT_R *w)
61 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));
63 for (t = -T / 2; t < T / 2; t++)
65 for (r = -S / 2; r < S / 2; r++)
67 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));
68 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));
70 w[(t + T / 2) * S + (r + S / 2)] = NFFT_K(1.0) / NFFT_K(4.0) / W;
72 w[(t + T / 2) * S + (r + S / 2)] = NFFT_M(fabs)((NFFT_R) r) / W;
85 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));
87 for (t = -T / 2; t < T / 2; t++)
89 for (r = -S / 2; r < S / 2; r++)
93 x[2 * ((t + T / 2) * S + (r + S / 2)) + 0] = (NFFT_R) r / (NFFT_R)(S);
94 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)
99 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)
100 * (NFFT_R)(r) / (NFFT_R)(S);
101 x[2 * ((t + T / 2) * S + (r + S / 2)) + 1] = (NFFT_R) r / (NFFT_R)(S);
104 w[(t + T / 2) * S + (r + S / 2)] = NFFT_K(1.0) / NFFT_K(4.0) / W;
106 w[(t + T / 2) * S + (r + S / 2)] = NFFT_M(fabs)((NFFT_R) r) / W;
116 static int Radon_trafo(
int (*gridfcn)(),
int T,
int S, NFFT_R *f,
int NN, NFFT_R *Rf)
119 NFFT(plan) my_nfft_plan;
122 FFTW(plan) my_fftw_plan;
135 fft = (NFFT_C *) NFFT(malloc)((size_t)(S) *
sizeof(NFFT_C));
136 my_fftw_plan = FFTW(plan_dft_1d)(S,
fft,
fft, FFTW_BACKWARD, FFTW_MEASURE);
138 x = (NFFT_R *) NFFT(malloc)((size_t)(2 * T * S) * (
sizeof(NFFT_R)));
142 w = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
147 NFFT(init_guru)(&my_nfft_plan, 2, N, M, n, 4,
148 PRE_PHI_HUT | PRE_PSI | MALLOC_X | MALLOC_F_HAT | MALLOC_F | FFTW_INIT
150 FFTW_MEASURE | FFTW_DESTROY_INPUT);
154 for (j = 0; j < my_nfft_plan.M_total; j++)
156 my_nfft_plan.x[2 * j + 0] = x[2 * j + 0];
157 my_nfft_plan.x[2 * j + 1] = x[2 * j + 1];
161 if (my_nfft_plan.flags & PRE_LIN_PSI)
162 NFFT(precompute_lin_psi)(&my_nfft_plan);
164 if (my_nfft_plan.flags & PRE_PSI)
165 NFFT(precompute_psi)(&my_nfft_plan);
167 if (my_nfft_plan.flags & PRE_FULL_PSI)
168 NFFT(precompute_full_psi)(&my_nfft_plan);
171 for (k = 0; k < my_nfft_plan.N_total; k++)
172 my_nfft_plan.f_hat[k] = f[k] + _Complex_I * NFFT_K(0.0);
175 NFFT(trafo)(&my_nfft_plan);
178 for (t = 0; t < T; t++)
180 fft[0] = NFFT_K(0.0);
181 for (r = -S / 2 + 1; r < S / 2; r++)
182 fft[r + S / 2] =
KERNEL(r) * my_nfft_plan.f[t * S + (r + S / 2)];
184 NFFT(fftshift_complex_int)(
fft, 1, &S);
185 FFTW(execute)(my_fftw_plan);
186 NFFT(fftshift_complex_int)(
fft, 1, &S);
188 for (r = 0; r < S; r++)
189 Rf[t * S + r] = NFFT_M(creal)(fft[r]) / (NFFT_R)(S);
199 FFTW(destroy_plan)(my_fftw_plan);
201 NFFT(finalize)(&my_nfft_plan);
209 int main(
int argc,
char **argv)
219 printf(
"radon gridfcn N T R\n");
221 printf(
"gridfcn \"polar\" or \"linogram\" \n");
222 printf(
"N image size NxN \n");
223 printf(
"T number of slopes \n");
224 printf(
"R number of offsets \n");
228 if (strcmp(argv[1],
"polar") == 0)
238 f = (NFFT_R *) NFFT(malloc)((size_t)(N * N) * (
sizeof(NFFT_R)));
239 Rf = (NFFT_R *) NFFT(malloc)((size_t)(T * S) * (
sizeof(NFFT_R)));
242 fp = fopen(
"input_data.bin",
"rb");
245 fread(f,
sizeof(NFFT_R), (
size_t)(N * N), fp);
252 fp = fopen(
"sinogram_data.bin",
"wb+");
255 fwrite(Rf,
sizeof(NFFT_R), (
size_t)(T * S), fp);
static int Radon_trafo(int(*gridfcn)(), int T, int S, NFFT_R *f, int NN, NFFT_R *Rf)
computes the NFFT-based discrete Radon transform of f on the grid given by gridfcn() with T angles an...
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 ...
static void fft(int N, int M, int Z, fftw_complex *mem)
fft makes an 1D-ftt for every knot through all layers
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 KERNEL(r)
define weights of kernel function for discrete Radon transform