| Bsoft 2.0.5 Bernard's software package

pocs_tool.cpp
Go to the documentation of this file.
1
11 #include "pocs_tool.h"
12 #include "fft_tool.h"
13
14 int filter_sin_mask (Bimage * p, int n_cicli, float r_max, Bimage * pmask, int piano, int tipo, int first);
15 int restore_with_mask (Bimage * p, Bimage * pcopia, Bimage * pmask, int linea, int tipo);
16 int copy_sin (Bimage * p);
17 int copy_phi (Bimage * pelab, Bimage * p, int i);
18 int filter_bessel (Bimage * p, int r, int first);
19
20
32 int
33 filter_sin_mask (Bimage * p, int n_cicli, float r_max, Bimage * pmask, int piano, int tipo, int first)
34 {
35 int j;
36
37 Bimage *pcopia = p->copy();
38
39 for (j = 0; j < n_cicli; j++)
40 {
41 fft_2D_forward (p);
42
43 filter_bessel (p, (int) r_max, first);
44 zeroes (p);
45
46 fft_2D_backward (p);
47
48 if (pmask)
49 restore_with_mask (p, pcopia, pmask, piano, tipo);
50 }
51
52 delete pcopia;
53
54 return 0;
55 }
56
66 int
67 filter_X_mask (Bimage * p, Bimage * pmask, int n_cicli, float r_maxx, int passata)
68 {
69 int i, first = 2;
70 int planesize = p->sizeX() * p->sizeY();
71 float *pp;
72 float fat, r_max, theta;
73
74 float *pv = (float *) p->data_pointer();
75
76 Bimage *pelab = new Bimage (Float, TSimple, p->sizeX(), 2 * p->sizeY(), 1, 1);
77
78 if (passata == 0)
79 for (i = 0; i < p->sizeZ(); i++)
80 {
81 r_max = r_maxx;
82 pp = pv + i * planesize;
83 memcpy (pelab->data_pointer(), pp, planesize * sizeof (float));
84 copy_sin (pelab);
85 filter_sin_mask (pelab, n_cicli, r_max, pmask, i, 0, first);
86 memcpy (pp, pelab->data_pointer(), planesize * sizeof (float));
87 }
88 else
89 for (i = 0; i < p->sizeZ(); i++)
90 {
91 theta = M_PI * (i - (int)p->sizeZ() / 2) / p->sizeZ();
92 fat = fabs (sin (theta));
93 r_max = r_maxx * fat;
94 pp = pv + i * planesize;
95 memcpy (pelab->data_pointer(), pp, planesize * sizeof (float));
96 copy_phi (pelab, p, i);
97 filter_sin_mask (pelab, n_cicli, r_max, pmask, i, 1, first);
98 memcpy (pp, pelab->data_pointer(), planesize * sizeof (float));
99 }
100
101 delete pelab;
102
103 return 0;
104 }
105
115 int
116 restore_with_mask (Bimage * p, Bimage * pcopia, Bimage * pmask, int linea, int tipo)
117 {
118 float *pm1;
119
120 float *pr1, *pr2;
121 int i, j, k, icol, val;
122
123 float *copia = (float *) pcopia->data_pointer();
124 float *elab = (float *) p->data_pointer();
125 float *mask = NULL;
126 if (pmask)
127 mask = (float *) pmask->data_pointer();
128
129 if (tipo == 0)
130 {
131 pm1 = mask + linea * p->sizeX();
132 pr1 = copia;
133 pr2 = elab;
134 for (i = 0; i < p->sizeY(); i++)
135 {
136 k = i % (p->sizeY() / 2);
137 val = (int) (pm1[k]);
138 for (j = 0; j < p->sizeX(); j++)
139 {
140 if (val != 0)
141 *pr2 = *pr1;
142 pr1++;
143 pr2++;
144 }
145 }
146 pr1 = copia;
147 pr2 = elab;
148 }
149 else
150 {
151 pm1 = mask + linea;
152 pr1 = copia;
153 pr2 = elab;
154 for (i = 0; i < p->sizeY(); i++)
155 {
156 k = i % (p->sizeY() / 2);
157 icol = k * p->sizeX();
158 val = (int) (pm1[icol]);
159 for (j = 0; j < p->sizeX(); j++)
160 {
161 if (val != 0)
162 *pr2 = *pr1;
163 pr1++;
164 pr2++;
165 }
166 }
167 pr1 = copia;
168 pr2 = elab;
169 }
170 return 0;
171 }
172
178 int
179 copy_sin (Bimage * p)
180 {
181 float *pr1, *pr2, *pr3, *pr4;
182 int j, k;
183
184 float *pr = (float *) p->data_pointer();
185
186 pr1 = pr;
187 pr2 = pr + p->sizeX() * p->sizeY() / 2;
188
189 for (k = 0; k < p->sizeY() / 2; k++)
190 {
191 for (j = 0; j < p->sizeX(); j++)
192 {
193 pr3 = pr1 + (p->sizeX() - j) % p->sizeX();
194 pr4 = pr2 + j;
195 *pr4 = *pr3;
196 }
197 pr1 += p->sizeX();
198 pr2 += p->sizeX();
199 }
200 return 0;
201 }
202
210 int
211 copy_phi (Bimage * pelab, Bimage * p, int i)
212 {
213 int j, nt2;
214 float *pr1, *pp, *pp1;
215
216 float *pr = (float *) pelab->data_pointer();
217 float *pv = (float *) p->data_pointer();
218
219 nt2 = pelab->sizeX() * pelab->sizeY() / 2;
220 j = (p->sizeZ() - i) % p->sizeZ();
221 pp = pv + j * nt2;
222 pr1 = pr + nt2;
223 for (pp1 = pp; pp1 < pp + nt2; pp1++)
224 *pr1++ = *pp1;
225 return 0;
226 }
227
235 int
236 filter_bessel (Bimage * p, int r, int first)
237 {
238 float *pr1, *pr2;
239 int i, j;
240 float m, rmax, rmaxx;
241 int x, ymax, imax;
242
243 float *pr = (float *) p->data_pointer();
244
245 rmax = (float) r / (float) p->sizeY();
246 imax = first * 2;
247
248 rmaxx = (float) (p->sizeX() / 2 - 1) / (2. * M_PI * rmax);
249 m = rmaxx / (float) (p->sizeX() / 2 - first);
250 pr[1] = 0.;
251 pr[p->sizeX()] = 0.;
252 pr[p->sizeX() + 1] = 0.;
253 for (i = 2; i < imax; i += 2)
254 {
255 pr1 = pr + i;
256 pr2 = pr1 + p->sizeX();
257 *pr1++ = 0.;
258 *pr1 = 0.;
259 *pr2++ = 0.;
260 *pr2 = 0.;
261 }
262 for (i = imax; i < p->sizeX(); i += 2)
263 {
264 x = (i / 2 - first);
265 ymax = (int) ceil (m * (float) x);
266 if (ymax == 0)
267 ymax = 1;
268 if (ymax > (p->sizeY() / 2))
269 ymax = p->sizeY() / 2;
270 for (j = 0; j < ymax; j++)
271 {
272 pr1 = pr + j * 2 * p->sizeX() + i;
273 pr2 = pr1 + p->sizeX();
274 *pr1++ = 0.;
275 *pr1 = 0.;
276 *pr2++ = 0.;
277 *pr2 = 0.;
278 }
279 }
280 return 0;
281 }
282
289 int
290 support_f (Bimage * p, float rmax)
291 {
292 int i, j, j1, j2;
293 float weight;
294 float *pr1;
295
296 float *pr = (float *) p->data_pointer();
297
298 // cout << "in support_f" << endl;
299
300 j1 = p->sizeZ() / 2 - (int) rmax;
301 j2 = p->sizeZ() / 2 + (int) rmax;
302
303 double ang_fac = M_PI / (2.0 * j1);
304
305 for (j = 0; j < j1; j++)
306 {
307 pr1 = pr + j * p->sizeX() * p->sizeY();
308 weight = sin (ang_fac * j);
309 for (i = 0; i < p->sizeX() * p->sizeY(); i++)
310 pr1[i] *= weight;
311 }
312 for (j = j2 + 1; j < p->sizeZ(); j++)
313 {
314 pr1 = pr + j * p->sizeX() * p->sizeY();
315 weight = sin (ang_fac * (p->sizeZ() - j));
316 for (i = 0; i < p->sizeX() * p->sizeY(); i++)
317 pr1[i] *= weight;
318 }
319 return 0;
320 }
fft_tool.h
copy_sin
int copy_sin(Bimage *p)
Copy the second half of a sinogram from the first one.
Definition: pocs_tool.cpp:179
zeroes
int zeroes(Bimage *p)
Definition: fft_tool.cpp:373
fft_2D_backward
int fft_2D_backward(Bimage *p)
Definition: fft_tool.cpp:55
TSimple
Definition: Bimage.h:58
filter_bessel
int filter_bessel(Bimage *p, int r, int first)
Definition: pocs_tool.cpp:236
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
M_PI
#define M_PI
Definition: utilities.h:59
fft_2D_forward
int fft_2D_forward(Bimage *p)
Definition: fft_tool.cpp:41
filter_sin_mask
int filter_sin_mask(Bimage *p, int n_cicli, float r_max, Bimage *pmask, int piano, int tipo, int first)
Definition: pocs_tool.cpp:33
copy_phi
int copy_phi(Bimage *pelab, Bimage *p, int i)
Definition: pocs_tool.cpp:211
pocs_tool.h
restore_with_mask
int restore_with_mask(Bimage *p, Bimage *pcopia, Bimage *pmask, int linea, int tipo)
Definition: pocs_tool.cpp:116
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:261
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2695
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
filter_X_mask
int filter_X_mask(Bimage *p, Bimage *pmask, int n_cicli, float r_maxx, int passata)
Definition: pocs_tool.cpp:67
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
support_f
int support_f(Bimage *p, float rmax)
Definition: pocs_tool.cpp:290