54 #define KERNEL(r) (1.0-fabs((double)(r))/((double)R/2))
59 static int polar_grid(
int T,
int R,
double *x,
double *w)
62 double W=(double)T*(((
double)R/2.0)*((double)R/2.0)+1.0/4.0);
64 for(t=-T/2; t<T/2; t++)
66 for(r=-R/2; r<R/2; r++)
68 x[2*((t+T/2)*R+(r+R/2))+0] = (
double)r/R*cos(
PI*t/T);
69 x[2*((t+T/2)*R+(r+R/2))+1] = (
double)r/R*sin(
PI*t/T);
71 w[(t+T/2)*R+(r+R/2)] = 1.0/4.0/W;
73 w[(t+T/2)*R+(r+R/2)] = fabs((
double)r)/W;
86 double W=(double)T*(((
double)R/2.0)*((double)R/2.0)+1.0/4.0);
88 for(t=-T/2; t<T/2; t++)
90 for(r=-R/2; r<R/2; r++)
94 x[2*((t+T/2)*R+(r+R/2))+0] = (
double)r/R;
95 x[2*((t+T/2)*R+(r+R/2))+1] = (
double)4*(t+T/4)/T*r/R;
99 x[2*((t+T/2)*R+(r+R/2))+0] = -(
double)4*(t-T/4)/T*r/R;
100 x[2*((t+T/2)*R+(r+R/2))+1] = (
double)r/R;
103 w[(t+T/2)*R+(r+R/2)] = 1.0/4.0/W;
105 w[(t+T/2)*R+(r+R/2)] = fabs((
double)r)/W;
123 fftw_plan my_fftw_plan;
132 N[0]=NN; n[0]=2*N[0];
133 N[1]=NN; n[1]=2*N[1];
135 fft = (fftw_complex *)
nfft_malloc(R*
sizeof(fftw_complex));
136 my_fftw_plan = fftw_plan_dft_1d(R,fft,fft,FFTW_FORWARD,FFTW_MEASURE);
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 | FFT_OUT_OF_PLACE,
149 FFTW_MEASURE| FFTW_DESTROY_INPUT);
152 solver_init_advanced_complex(&my_infft_plan,(
nfft_mv_plan_complex*)(&my_nfft_plan), CGNR | PRECOMPUTE_WEIGHT);
156 for(j=0;j<my_nfft_plan.
M_total;j++)
158 my_nfft_plan.
x[2*j+0] = x[2*j+0];
159 my_nfft_plan.
x[2*j+1] = x[2*j+1];
161 my_infft_plan.
w[j] = w[j];
163 my_infft_plan.
w[j] = 0.0;
171 nfft_precompute_psi(&my_nfft_plan);
174 nfft_precompute_full_psi(&my_nfft_plan);
186 fft[r] = Rf[t*R+r] + _Complex_I*0.0;
189 fftw_execute(my_fftw_plan);
192 my_infft_plan.
y[t*R] = 0.0;
193 for(r=-R/2+1; r<R/2; r++)
194 my_infft_plan.
y[t*R+(r+R/2)] = fft[r+R/2]/
KERNEL(r);
198 for(k=0;k<my_nfft_plan.
N_total;k++)
199 my_infft_plan.
f_hat_iter[k] = 0.0 + _Complex_I*0.0;
202 solver_before_loop_complex(&my_infft_plan);
207 for(k=0;k<my_nfft_plan.
N_total;k++)
212 for(l=1;l<=
max_i;l++)
221 for(k=0;k<my_nfft_plan.
N_total;k++)
225 fftw_destroy_plan(my_fftw_plan);
228 nfft_finalize(&my_nfft_plan);
236 int main(
int argc,
char **argv)
247 printf(
"inverse_radon gridfcn N T R max_i\n");
249 printf(
"gridfcn \"polar\" or \"linogram\" \n");
250 printf(
"N image size NxN \n");
251 printf(
"T number of slopes \n");
252 printf(
"R number of offsets \n");
253 printf(
"max_i number of iterations \n");
257 if (strcmp(argv[1],
"polar") == 0)
266 max_i = atoi(argv[5]);
272 fp=fopen(
"sinogram_data.bin",
"rb");
275 fread(Rf,
sizeof(
double),T*R,fp);
282 fp=fopen(
"output_data.bin",
"wb+");
285 fwrite(iRf,
sizeof(
double),N*N,fp);
void nfft_fftshift_complex(fftw_complex *x, int d, int *N)
Swaps each half over N[d]/2.
int max_i(int a, int b)
max
fftw_complex * p_hat_iter
search direction
static int linogram_grid(int T, int R, double *x, double *w)
generates the points x with weights w for the linogram grid with T slopes and R offsets ...
double * w
weighting factors
int Inverse_Radon_trafo(int(*gridfcn)(), int T, int R, double *Rf, int NN, double *f, int max_i)
computes the inverse discrete Radon transform of Rf on the grid given by gridfcn() with T angles and ...
void nfft_precompute_lin_psi(nfft_plan *ths)
create a lookup table, but NOT for each node good idea K=2^xx TODO: estimate K, call from init assume...
static int polar_grid(int T, int R, double *x, double *w)
generates the points x with weights w for the polar grid with T angles and R offsets ...
int M_total
Total number of samples.
Header file for utility functions used by the nfft3 library.
static void fft(int N, int M, int Z, fftw_complex *mem)
fft makes an 1D-ftt for every knot through all layers
#define PI
Formerly known to be an irrational number.
unsigned nfft_flags
Flags for precomputation, (de)allocation, and FFTW usage, default setting is PRE_PHI_HUT | PRE_PSI | ...
void * nfft_malloc(size_t n)
#define KERNEL(r)
define weights of kernel function for discrete Radon transform
fftw_complex * y
right hand side, samples
double * x
Nodes in time/spatial domain, size is doubles.
void solver_loop_one_step_complex(solver_plan_complex *ths)
void solver_loop_one_step
void solver_finalize_complex(solver_plan_complex *ths)
void solver_finalize
int N_total
Total number of Fourier coefficients.
fftw_complex * f_hat_iter
iterative solution