| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
img_resolution.cpp
Go to the documentation of this file.
1
9 #include "Bimage.h"
10 #include "img_resolution.h"
11 #include "rwFSC_XML.h"
12 #include "ps_plot.h"
13 #include "trigonometry.h"
14 #include "utilities.h"
15
16
17 // Declaration of the global variables
18 extern int verbose; // Output verbosity
19
94 Bplot* img_resolution(Bimage* p, Bimage* pmod, Bimage* prealmask,
95 Bimage* pftmask, double hi_res, double aligned_res, double sampling_ratio)
96 {
97 if ( sampling_ratio <= 0 ) sampling_ratio = 1;
98
99 // The frequency scaling is linked to the different dimensions of the
100 // data set (important when the x, y and z dimensions are different)
101 // The radius scaling is set to a value consistent with one pixel width
102 // in reciprocal space for the longest dimension.
103 Vector3<double> realsize(p->real_size());
104 Vector3<double> freq_scale(1/realsize);
105 double rad_scale = realsize.x()/sampling_ratio;
106 if ( rad_scale < realsize.y()/sampling_ratio ) rad_scale = realsize.y()/sampling_ratio;
107 if ( rad_scale < realsize.z()/sampling_ratio ) rad_scale = realsize.z()/sampling_ratio;
108 if ( p->sizeX() > 1 && hi_res < 2*p->sampling().x() ) hi_res = 2*p->sampling().x();
109 if ( p->sizeY() > 1 && hi_res < 2*p->sampling().y() ) hi_res = 2*p->sampling().y();
110 if ( p->sizeZ() > 1 && hi_res < 2*p->sampling().z() ) hi_res = 2*p->sampling().z();
111 if ( hi_res > realsize.x()/2.0 ) hi_res = realsize.x()/2.0;
112
113 // maxrad is the main limit for the length of all the arrays,
114 // and is derived from the resolution set in the transform
115 long maxrad = (long) (2 + rad_scale/hi_res);
116 long alnrad = ( aligned_res > hi_res )? (long) (rad_scale/aligned_res): maxrad;
117
118 int ncol(5);
119 Bstring title("Resolution"), txt;
120 Bplot* plot = new Bplot(p->images(), maxrad, ncol*p->images());
121 plot->title(title);
122
123 if ( p->fourier_type() != NoTransform ) {
124 cerr << "Error: File " << p->file_name() << " must be a real space map!" << endl;
125 return plot;
126 }
127
128 if ( pmod->fourier_type() != NoTransform ) {
129 cerr << "Error: File " << pmod->file_name() << " must be a real space map!" << endl;
130 return plot;
131 }
132
133 if ( prealmask ) {
134 p->multiply(prealmask);
135 pmod->multiply(prealmask);
136 }
137
138 if ( pftmask ) pftmask->change_type(UCharacter);
139
140 // Pack the two images into one complex block
141 Bimage* pc = p->pack_two_in_complex(pmod);
142 if ( pc == NULL ) return plot;
143
144 pc->fft();
145
146 Complex<double> image, model;
147
148 pc->set(0, 0);
149 pc->set(1, 0);
150
151 pc->statistics();
152
153 if ( verbose & VERB_DEBUG )
154 cout << "DEBUG img_resolution: FFT done" << endl;
155
156 if ( !pc->FOM() ) pc->FOM_initialize();
157 float* fom = pc->FOM();
158
159 long i, j, c, n, x, y, z, xx, yy, zz, ix, iy, iz, iradius, iradius2, use_this=1;
160 double radius, fraction, fraction2, I1, I2, Idif, Isum;
161 double dphi, dphi2, cos_dphi, F1F2re, Id2;
162 double rx, ry, rz;
163 double invsigma2 = -0.5/(pc->standard_deviation()*pc->standard_deviation());
164
165 if ( verbose > VERB_RESULT ) {
166 cout << "Determining resolution from images " << p->file_name() << " and " << pmod->file_name() << endl;
167 cout << "Resolution limit: " << hi_res << " A (" << maxrad << ")" << endl;
168 if ( aligned_res > hi_res )
169 cout << "Aligned resolution: " << aligned_res << " A (" << alnrad << ")" << endl;
170 cout << "Sampling ratio: " << sampling_ratio << endl << endl;
171 }
172
173 double* num = new double[maxrad];
174 double* F1 = new double[maxrad];
175 double* F2 = new double[maxrad];
176 double* F1F2 = new double[maxrad];
177 double* Fsum = new double[maxrad];
178 double* Fsumphi = new double[maxrad];
179 double* SSNR = new double[maxrad];
180 double* RAB = new double[maxrad];
181
182 for ( n=c=0; n<pc->images(); n++, c+=ncol ) {
183 title = p->file_name() + " vs " + pmod->file_name() + ": image " + Bstring(n, "%d");
184 plot->page(n).title(title);
185 plot->page(n).columns(ncol);
186 for ( i=0; i<ncol; i++ ) plot->page(n).column(i).number(c+i);
187 plot->page(n).column(0).label("s");
188 if ( pc->sizeZ() > 1 ) plot->page(n).column(1).label("FSC");
189 else plot->page(n).column(1).label("FRC");
190 plot->page(n).column(2).label("DPR");
191 plot->page(n).column(3).label("SSNR");
192 plot->page(n).column(4).label("RAB");
193 plot->page(n).axis(1).min(0);
194 plot->page(n).axis(1).max(1/hi_res);
195 plot->page(n).axis(1).inc(0.1/hi_res);
196 plot->page(n).axis(1).flags(1);
197 plot->page(n).axis(1).label("Resolution(A)");
198 plot->page(n).axis(3).min(0);
199 plot->page(n).axis(3).max(1);
200 plot->page(n).axis(3).inc(0.1);
201 if ( pc->sizeZ() > 1 ) plot->page(n).axis(3).label("FSC");
202 else plot->page(n).axis(3).label("FRC");
203 plot->page(n).axis(4).min(0);
204 plot->page(n).axis(4).max(120);
205 plot->page(n).axis(4).inc(10);
206 plot->page(n).axis(4).label("DPR");
207 for ( i=1; i<ncol; i++ ) plot->page(n).column(i).type(2);
208 plot->page(n).column(0).axis(1);
209 plot->page(n).column(1).axis(3);
210 plot->page(n).column(2).axis(4);
211 // plot->page(n).column(3).axis(4);
212 // plot->page(n).column(4).axis(3);
213 plot->page(n).column(1).color(1,0,0);
214 plot->page(n).column(2).color(0,0,1);
215 plot->page(n).column(3).color(0,1,0);
216 plot->page(n).column(4).color(1,1,0);
217
218 for ( i=0; i<maxrad; i++ ) {
219 num[i] = F1[i] = F2[i] = F1F2[i] = Fsum[i] = Fsumphi[i] = 0;
220 SSNR[i] = RAB[i] = 0;
221 }
222 for ( z=0; z<pc->sizeZ(); z++ ) {
223 zz = z;
224 if ( z > (pc->sizeZ() - 1)/2 ) zz -= pc->sizeZ();
225 rz = zz*freq_scale[2];
226 iz = -z;
227 if ( iz < 0 ) iz += pc->sizeZ();
228 for ( y=0; y<pc->sizeY(); y++ ) {
229 yy = y;
230 if ( y > (pc->sizeY() - 1)/2 ) yy -= pc->sizeY();
231 ry = yy*freq_scale[1];
232 iy = -y;
233 if ( iy < 0 ) iy += pc->sizeY();
234 for ( x=0; x<pc->sizeX()/2; x++ ) {
235 i = ((n*pc->sizeZ() + z)*pc->sizeY() + y)*pc->sizeX() + x;
236 use_this = 1;
237 xx = x;
238 if ( x > (pc->sizeX() - 1)/2 ) xx -= pc->sizeX();
239 rx = xx*freq_scale[0];
240 ix = -x;
241 if ( ix < 0 ) ix += pc->sizeX();
242 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
243 iradius = (int) radius;
244 iradius2 = iradius + 1;
245 if ( iradius2 >= maxrad ) use_this = 0;
246 if ( pftmask && (*pftmask)[i] < 1 ) use_this = 0;
247 if ( use_this ) {
248 fraction = radius - iradius;
249 fraction2 = 1.0 - fraction;
250 j = ((n*pc->sizeZ() + iz)*pc->sizeY() + iy)*pc->sizeX() + ix;
251 image = pc->complex(i).unpack_first(pc->complex(j));
252 model = pc->complex(i).unpack_second(pc->complex(j));
253 I1 = image.power();
254 I2 = model.power();
255 Idif = (image - model).power();
256 dphi = image.phi() - model.phi();
257 if ( !isfinite(dphi) ) {
258 cerr << x << " " << y << " " << z << ": dphi not finite: ";
259 cerr << "image = " << image.real() << " + " << image.imag()
260 << "i model = " << model.real() << " + " << model.imag() << "i" << endl;
261 dphi = 0;
262 }
263 dphi = angle_set_negPI_to_PI(dphi);
264 dphi2 = dphi*dphi;
265 num[iradius] += fraction2;
266 num[iradius2] += fraction;
267 F1[iradius] += fraction2*I1;
268 F1[iradius2] += fraction*I1;
269 F2[iradius] += fraction2*I2;
270 F2[iradius2] += fraction*I2;
271 I1 = sqrt(I1);
272 I2 = sqrt(I2);
273 if ( !isfinite(I1) )
274 cerr << x << " " << y << " " << z << ": I1 not finite" << endl;
275 if ( !isfinite(I2) )
276 cerr << x << " " << y << " " << z << ": I2 not finite" << endl;
277 F1F2re = image.real()*model.real() + image.imag()*model.imag();
278 F1F2[iradius] += fraction2*F1F2re;
279 F1F2[iradius2] += fraction*F1F2re;
280 Isum = I1 + I2;
281 Fsum[iradius] += fraction2*Isum;
282 Fsum[iradius2] += fraction*Isum;
283 Id2 = Isum*dphi2;
284 Fsumphi[iradius] += fraction2*Id2;
285 Fsumphi[iradius2] += fraction*Id2;
286 if ( Idif > 0 ) {
287 SSNR[iradius] += fraction2*Idif;
288 SSNR[iradius2] += fraction*Idif;
289 Idif = sqrt(Idif);
290 RAB[iradius] += fraction2*Idif;
291 RAB[iradius2] += fraction*Idif;
292 }
293 if ( fom ) {
294 cos_dphi = F1F2re/(I1*I2);
295 if ( Isum < SMALLFLOAT || cos_dphi < 0 ) {
296 fom[i] = 0;
297 } else if ( Isum > 10*pc->standard_deviation() ) {
298 fom[i] = (1 - Idif/Isum)*cos_dphi;
299 } else {
300 fom[i] = (1 - Idif/Isum)*cos_dphi*
301 (1 - exp(invsigma2*Isum*Isum));
302 }
303 if ( fom[i] < 0 ) fom[i] = 0;
304 fom[j] = fom[i];
305 }
306 }
307 }
308 }
309 }
310 fom[0] = 1;
311
312 F1F2[0] = 1;
313 Fsumphi[0] = 0;
314 SSNR[0] = 0.09*F2[0];
315 double FSC, DPR, FSCsum(0), nsum(0), naln(0), nval(0), FSCaln(0), FSCval(0);
316 for ( i=0, j=c*maxrad; i<maxrad; i++, j++ ) {
317 FSC = 0;
318 if ( i == 0 ) FSC = 1;
319 else if ( F1[i]*F2[i] > SMALLFLOAT ) FSC = F1F2[i]/sqrt(F1[i]*F2[i]);
320 if ( i <= alnrad ) {
321 FSCaln += FSC*num[i];
322 naln += num[i];
323 } else {
324 FSCval += FSC*num[i];
325 nval += num[i];
326 }
327 if ( FSC < SMALLFLOAT ) FSC = 0;
328 if ( FSC > 1 ) FSC = 1;
329 FSCsum += FSC*num[i];
330 nsum += num[i];
331 if ( Fsum[i] > SMALLFLOAT ) DPR = sqrt(Fsumphi[i]/Fsum[i]);
332 else DPR = 0;
333 // if ( SSNR[i] >= SMALLFLOAT ) SSNR[i] = F2[i]/SSNR[i] - 1;
334 if ( F1[i]*F2[i] > SMALLFLOAT ) SSNR[i] = F1F2[i]/(sqrt(F1[i]*F2[i]) - F1F2[i]);
335 else SSNR[i] = 0;
336 if ( Fsum[i] > SMALLFLOAT ) RAB[i] /= Fsum[i];
337 else RAB[i] = 0;
338 (*plot)[j] = i/rad_scale;
339 (*plot)[maxrad+j] = FSC;
340 (*plot)[2*maxrad+j] = DPR*180.0/M_PI;
341 (*plot)[3*maxrad+j] = SSNR[i];
342 (*plot)[4*maxrad+j] = RAB[i];
343 }
344 FSCval /= 2*naln - FSCaln;
345 if ( FSCval < 0 ) FSCval = 0;
346 if ( verbose & VERB_PROCESS )
347 cout << "Validation ratio: " << FSCval << endl;
348 FSCsum /= p->real_size().volume();
349 txt = Bstring(pow(4.0*M_PI/(3.0*FSCsum), 1.0/3.0), "Information volume radius: %g A");
350 plot->page(n).add_text(txt);
351 if ( aligned_res > hi_res ) {
352 txt = Bstring(FSCval, "Validation ratio: %g");
353 plot->page(n).add_text(txt);
354 }
355 }
356
357 if ( verbose & VERB_DEBUG )
358 cout << "DEBUG img_resolution: page number = " << plot->page(0).number() << " columns = " << plot->page(0).columns() << endl;
359
360 delete[] num;
361 delete[] F1;
362 delete[] F2;
363 delete[] F1F2;
364 delete[] Fsum;
365 delete[] Fsumphi;
366 delete[] SSNR;
367 delete[] RAB;
368
369 pc->FOM_find_maximum();
370
371 if ( verbose & VERB_DEBUG )
372 cout << "DEBUG img_resolution: Maximum FOM = " << pc->FOM_maximum() << endl;
373
374 delete pc;
375
376 return plot;
377 }
378
393 double* img_resolution_display(Bplot* plot, float* cutoff)
394 {
395 long i, j, n, c, ncol(5), nrow(plot->rows()), nimg(plot->pages());
396 double res, res_1;
397 double *s, *FSC, *DPR, *SSNR, *RAB;
398 double* data = plot->data_pointer();
399 Bstring txt, label;
400
401 if ( cutoff[1] < 5 ) cutoff[1] *= 180.0/M_PI;
402
403 // Resolution estimates
404 double* res_est = new double[nimg*4];
405 for ( n=0; n<nimg*4; n++ ) res_est[n] = 0;
406
407 for ( n=c=0; n<nimg; n++, c+=ncol ) {
408 s = data + c*nrow;
409 FSC = s + nrow;
410 DPR = s + 2*nrow;
411 SSNR = s + 3*nrow;
412 RAB = s + 4*nrow;
413 label = plot->page(n).axis(3).label();
414 if ( verbose & VERB_PROCESS ) {
415 cout << "Resolution cutoff levels: " << cutoff[0] << " "
416 << cutoff[1] << " " << cutoff[2] << " " << cutoff[3] << endl << endl;
417 if ( nimg > 1 )
418 cout << "Resolution measures for image " << n << endl;
419 else
420 cout << "Resolution curves:" << endl;
421 cout << "s(1/A)\tRes(A)\t" << label << "\tDPR\tSSNR\tRA+B" << endl;
422 }
423 res = res_1 = 999;
424 for ( i=0, j=c*nrow; i<nrow; i++, j++ ) {
425 if ( i > 0 ) {
426 res = 1/s[i];
427 if ( FSC[i-1] >= cutoff[0] && FSC[i] < cutoff[0] )
428 res_est[n*4+0] = res + (res_1 - res)*(cutoff[0] - FSC[i])/(FSC[i-1] - FSC[i]);
429 if ( DPR[i-1] <= cutoff[1] && DPR[i] > cutoff[1] )
430 res_est[n*4+1] = res + (res_1 - res)*(cutoff[1] - DPR[i])/(DPR[i-1] - DPR[i]);
431 if ( SSNR[i-1] >= cutoff[2] && SSNR[i] < cutoff[2] )
432 res_est[n*4+2] = res + (res_1 - res)*(cutoff[2] - SSNR[i])/(SSNR[i-1] - SSNR[i]);
433 if ( RAB[i-1] <= cutoff[3] && RAB[i] > cutoff[3])
434 res_est[n*4+3] = res + (res_1 - res)*(cutoff[3] - RAB[i])/(RAB[i-1] - RAB[i]);
435 }
436 res_1 = res;
437 if ( verbose & VERB_PROCESS )
438 cout << showpoint << fixed << setprecision(5) << setw(7) << s[i] << tab
439 << setprecision(3) << setw(7) << res << tab
440 << setw(7) << FSC[i] << tab
441 << setw(7) << DPR[i] << tab
442 << setw(7) << SSNR[i] << tab
443 << setw(7) << RAB[i] << endl;
444 }
445 txt = label + Bstring(cutoff[0], "(%g): ") + Bstring(res_est[n*4], "%g A");
446 plot->page(n).add_text(txt);
447 txt = Bstring(cutoff[1], "DPR(%g): ") + Bstring(res_est[n*4+1], "%g A");
448 plot->page(n).add_text(txt);
449
450 if ( verbose & VERB_PROCESS ) {
451 cout << "Resolution estimates:\t" << n << tab
452 << setprecision(4) << res_est[n*4] << tab << res_est[n*4+1] << tab
453 << res_est[n*4+2] << tab << res_est[n*4+3] << endl << endl;
454 cout << *(plot->page(n).text()) << endl;
455 }
456 }
457
458 return res_est;
459 }
460
476 double* img_resolution_display(Bplot* plot)
477 {
478 long i, j, k, n, c, ncol(2), nrow(plot->rows()), nimg(plot->pages());
479 double res, res_1;
480 double *s, *FSC;
481 double* data = plot->data_pointer();
482 Bstring txt, label;
483
484 // Resolution estimates
485 double cutoff[4] = {0.143,0.3,0.5,0.9};
486 double* res_est = new double[nimg*4];
487 for ( n=0; n<nimg*4; n++ ) res_est[n] = 0;
488
489 for ( n=c=0; n<nimg; n++, c+=ncol ) {
490 s = data + c*nrow;
491 FSC = s + nrow;
492 label = plot->page(n).axis(3).label();
493 if ( verbose & VERB_PROCESS ) {
494 cout << "Resolution cutoff levels: " << cutoff[0] << " "
495 << cutoff[1] << " " << cutoff[2] << " " << cutoff[3] << endl << endl;
496 if ( nimg > 1 )
497 cout << "Resolution measures for image " << n << endl;
498 else
499 cout << "Resolution curves:" << endl;
500 cout << "s(1/A)\tRes(A)\t" << label << endl;
501 }
502 res = res_1 = 999;
503 for ( i=0, j=c*nrow; i<nrow; i++, j++ ) {
504 if ( i > 0 ) {
505 res = 1/s[i];
506 for ( k=0; k<4; k++ )
507 if ( FSC[i-1] >= cutoff[k] && FSC[i] < cutoff[k] )
508 res_est[n*4+k] = res + (res_1 - res)*(cutoff[k] - FSC[i])/(FSC[i-1] - FSC[i]);
509 }
510 res_1 = res;
511 if ( verbose & VERB_PROCESS )
512 cout << showpoint << fixed << setprecision(5) << setw(7) << s[i] << tab
513 << setprecision(3) << setw(7) << res << tab
514 << setw(7) << FSC[i] << endl;
515 }
516 for ( k=0; k<4; k++ ) {
517 txt = label + Bstring(cutoff[k], "(%g): ") + Bstring(res_est[n*4+k], "%g A");
518 plot->page(n).add_text(txt);
519 }
520
521 if ( verbose & VERB_PROCESS ) {
522 cout << "Resolution estimates:\t" << n << tab
523 << setprecision(2) << res_est[n*4] << tab << res_est[n*4+1] << tab
524 << res_est[n*4+2] << tab << res_est[n*4+3] << endl << endl;
525 cout << *(plot->page(n).text()) << endl;
526 }
527 }
528
529 return res_est;
530 }
531
552 int img_resolution_from_two_images(Bstring& image_file, Bstring& ref_file,
553 Bstring& real_mask_file, Bstring& ft_mask_file, double resolution,
554 double aligned_res, Vector3<float> sampling, double sampling_ratio,
555 float* cutoff, Bstring& ps_file, Bstring& xml_file, Bstring& tsv_file, Bstring& proj_file)
556 {
557 if ( resolution <= 0 ) resolution = 0.1;
558
559 unsigned long i, j;
560 Bimage* proj = NULL;
561 Bimage* pf = NULL;
562 Bimage* prealmask = NULL;
563 Bimage* pftmask = NULL;
564
565 Bimage* pmap = read_img(ref_file, 0, -1);
566 if ( !pmap ) {
567 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
568 return -1;
569 }
570
571 Bimage* p = read_img(image_file, 0, -1);
572 if ( !p ) {
573 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
574 return -1;
575 }
576
577 unsigned long nimg = p->images();
578 Vector3<float> translate;
579 Matrix3 mat(1);
580 View view;
581 Bplot* plot = NULL;
582 double* res_est = NULL;
583
584 if ( verbose & VERB_RESULT )
585 cout << "Img\tFSC\tDPR\tSSNR\tR+AB" << endl;
586
587 if ( p->sizeZ() == pmap->sizeZ() ) {
588 if ( p->images() == pmap->images() ) {
589 delete p;
590 delete pmap;
591 pmap = read_img(ref_file, 1, -1);
592 pmap->statistics();
593 p = read_img(image_file, 1, -1);
594 if ( real_mask_file.length() ) {
595 prealmask = read_img(real_mask_file, 1, -1);
596 if ( !prealmask ) {
597 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
598 return -1;
599 }
600 }
601 if ( ft_mask_file.length() ) {
602 pftmask = read_img(ft_mask_file, 1, -1);
603 if ( !pftmask ) {
604 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
605 return -1;
606 }
607 }
608 if ( sampling.x() > 0 ) {
609 p->sampling(sampling);
610 pmap->sampling(sampling);
611 }
612 p->change_type(Float);
613 p->statistics();
614 p->rescale_to_avg_std(pmap->average(), pmap->standard_deviation());
615 plot = img_resolution(p, pmap, prealmask, pftmask, resolution, aligned_res, sampling_ratio);
616 res_est = img_resolution_display(plot, cutoff);
617 if ( ps_file.length() ) ps_plot(ps_file, plot);
618 if ( xml_file.length() ) xml_write_fsc(xml_file, plot);
619 if ( tsv_file.length() ) plot->write_tsv(tsv_file);
620 if ( verbose & VERB_RESULT ) {
621 for ( i=0; i<nimg; i++ ) {
622 cout << i+1;
623 for ( j=0; j<4; j++ ) cout << tab << res_est[i*4+j];
624 cout << endl;
625 }
626 }
627 delete plot;
628 delete[] res_est;
629 delete p;
630 } else {
631 delete p;
632 delete pmap;
633 pmap = read_img(ref_file, 1, 0);
634 pmap->statistics();
635 if ( real_mask_file.length() ) {
636 prealmask = read_img(real_mask_file, 1, 0);
637 if ( !prealmask ) {
638 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
639 return -1;
640 }
641 }
642 if ( ft_mask_file.length() ) {
643 pftmask = read_img(ft_mask_file, 1, 0);
644 if ( !pftmask ) {
645 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
646 return -1;
647 }
648 }
649 for ( i=0; i<nimg; i++ ) {
650 p = read_img(image_file, 1, i);
651 if ( sampling.x() > 0 ) {
652 p->sampling(sampling);
653 pmap->sampling(sampling);
654 }
655 p->change_type(Float);
656 p->statistics();
657 p->rescale_to_avg_std(pmap->average(), pmap->standard_deviation());
658 plot = img_resolution(p, pmap, prealmask, pftmask, resolution, aligned_res, sampling_ratio);
659 res_est = img_resolution_display(plot, cutoff);
660 // if ( ps_file.length() ) ps_plot(ps_file, plot);
661 delete plot;
662 if ( verbose & VERB_RESULT ) {
663 cout << i+1;
664 for ( j=0; j<4; j++ ) cout << tab << res_est[j];
665 cout << endl;
666 }
667 delete[] res_est;
668 delete p;
669 }
670 }
671 } else if ( p->sizeZ() == 1 ) {
672 if ( proj_file.length() ) {
673 pf = new Bimage(Float, p->compound_type(), p->sizeX(), p->sizeY(), 1, p->images());
674 pf->sampling(p->sampling());
675 for ( i=0; i<p->images(); i++ ) pf->image[i] = p->image[i];
676 }
677 delete p;
678 delete pmap;
679 pmap = read_img(ref_file, 1, 0);
680 pmap->statistics();
681 if ( real_mask_file.length() ) {
682 prealmask = read_img(real_mask_file, 1, -1);
683 if ( !prealmask ) {
684 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
685 return -1;
686 }
687 }
688 if ( ft_mask_file.length() ) {
689 pftmask = read_img(ft_mask_file, 1, -1);
690 if ( !pftmask ) {
691 error_show("img_resolution_from_two_images", __FILE__, __LINE__);
692 return -1;
693 }
694 }
695 for ( i=0; i<nimg; i++ ) {
696 p = read_img(image_file, 1, i);
697 if ( sampling.x() > 0 ) {
698 p->sampling(sampling);
699 pmap->sampling(sampling);
700 }
701 view = p->image->view();
702 mat = view.matrix();
703 translate[0] = p->image->origin().x() - (p->sizeX() - 1.0)/2.0;
704 translate[1] = p->image->origin().y() - (p->sizeY() - 1.0)/2.0;
705 p->change_type(Float);
706 p->statistics();
707 p->rescale_to_avg_std(0, 1);
708 proj = pmap->rotate_project(mat, translate, pmap->sizeX()/2.0);
709 proj->change_type(Float);
710 proj->statistics();
711 proj->rescale_to_avg_std(0, 1);
712 plot = img_resolution(p, pmap, prealmask, pftmask, resolution, aligned_res, sampling_ratio);
713 res_est = img_resolution_display(plot, cutoff);
714 // if ( ps_file.length() ) ps_plot(ps_file, plot);
715 delete plot;
716 if ( verbose & VERB_RESULT ) {
717 cout << i+1;
718 for ( j=0; j<4; j++ ) cout << tab << res_est[j];
719 cout << endl;
720 }
721 delete[] res_est;
722 if ( pf ) pf->replace(i, proj);
723 delete p;
724 delete proj;
725 }
726 }
727
728 delete pmap;
729 if ( prealmask ) delete prealmask;
730 if ( pftmask ) delete pftmask;
731
732 // if ( res_est ) delete[] res_est; // Trash resolution estimates
733
734 if ( pf ) {
735 pf->statistics();
736 write_img(proj_file, pf);
737 delete pf;
738 }
739
740 return 0;
741 }
742
Baxis::inc
double inc()
Definition: Bplot.h:34
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1544
Bimage::sizeZ
void sizeZ(size_t nz)
Definition: Bimage.h:332
Baxis::label
Bstring & label()
Definition: Bplot.h:28
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2532
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:135
Bimage.h
Header file for image class.
img_resolution
Bplot * img_resolution(Bimage *p, Bimage *pmod, Bimage *prealmask, Bimage *pftmask, double hi_res, double aligned_res, double sampling_ratio)
Calculates resolution measures.
Definition: img_resolution.cpp:94
Baxis::min
double min()
Definition: Bplot.h:30
Bplot::title
Bstring & title()
Definition: Bplot.h:188
SMALLFLOAT
#define SMALLFLOAT
Definition: utilities.h:43
Bimage::fft
int fft()
Definition: Bimage.h:682
utilities.h
Header file for general utilities.
ps_plot
int ps_plot(Bstring &filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:128
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:105
Bcolumn::label
Bstring & label()
Definition: Bplot.h:63
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:565
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:307
Matrix3
Definition: Matrix3.h:17
Bplot::pages
void pages(long n)
Definition: Bplot.h:200
Vector3< double >
error_show
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:687
rwFSC_XML.h
Library routines to read and write FSC curves.
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:100
Bplot::write_tsv
void write_tsv(Bstring &filename)
Definition: Bplot.h:253
Bcolumn::color
double * color()
Definition: Bplot.h:76
Bimage::average
double average(size_t cc, double xf, double yf, double zf, size_t nn, double iscale)
Averages in the xy plane when scaling is less than 1.
Definition: Bimage.cpp:1209
Bpage::column
Bcolumn & column(long i)
Definition: Bplot.h:110
Bimage::statistics
size_t statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
img_resolution_display
double * img_resolution_display(Bplot *plot, float *cutoff)
Calculates the resolution estimates from a plot generated by img_resolution.
Definition: img_resolution.cpp:393
Bimage::FOM_find_maximum
double FOM_find_maximum()
Calculates the maximum in the FOM block.
Definition: Bimage.cpp:659
Baxis::max
double max()
Definition: Bplot.h:32
Float
Definition: utilities.h:150
Bimage::rotate_project
Bimage * rotate_project(Matrix3 mat, Vector3< double > translate, double radial_cutoff)
Rotates a 3D map and projects it along the z-axis.
Definition: Bimage_project.cpp:103
Bimage
General image parameter class.
Definition: Bimage.h:152
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:437
M_PI
#define M_PI
Definition: utilities.h:52
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg=0, double nustd=1)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:100
Bimage::FOM_initialize
float * FOM_initialize()
Allocates and initializes the FOM block.
Definition: Bimage.cpp:677
read_img
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Bcolumn::number
long number()
Definition: Bplot.h:61
Bimage::complex
Complex< double > complex(size_t j)
Returns a complex value at the given index.
Definition: Bimage.cpp:885
Bimage::sampling
void sampling(double s)
Definition: Bimage.h:440
verbose
int verbose
Bimage::FOM
float * FOM()
Definition: Bimage.h:239
Bcolumn::type
long type()
Definition: Bplot.h:66
Bimage::multiply
void multiply(size_t j, Complex< double > cv)
Definition: Bimage.h:274
Bpage::text
Bstring * text()
Definition: Bplot.h:121
Bpage::axis
Baxis & axis(long id)
Definition: Bplot.h:117
Bpage::title
Bstring & title()
Definition: Bplot.h:100
Vector3::x
Type x()
Definition: Vector3.h:137
Bimage::file_name
void file_name(Bstring s)
Definition: Bimage.h:213
trigonometry.h
Header file for trigonometry functions.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:132
Bimage::set
void set(size_t j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:977
Bimage::FOM_maximum
double FOM_maximum()
Definition: Bimage.h:241
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:465
write_img
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
Definition: rwimg.cpp:255
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:98
Bpage::add_text
void add_text(Bstring &s)
Definition: Bplot.h:122
Bimage::images
size_t images()
Definition: Bimage.h:438
Complex
Definition: Complex.h:23
Baxis::flags
long flags()
Definition: Bplot.h:38
UCharacter
Definition: utilities.h:142
Bstring
Definition: Bstring.h:28
Bimage::sizeX
void sizeX(size_t nx)
Definition: Bimage.h:330
View::matrix
Matrix3 matrix()
Definition: View.h:138
Bplot::rows
void rows(long n)
Definition: Bplot.h:206
Bplot::page
Bpage & page(long i)
Definition: Bplot.h:210
ps_plot.h
Header file for postscript output functions.
Bpage::number
void number(long n)
Definition: Bplot.h:103
Complex::phi
double phi()
Definition: Complex.h:105
Bimage::sizeY
void sizeY(size_t ny)
Definition: Bimage.h:331
Complex::imag
Type imag()
Definition: Complex.h:102
View
Definition: View.h:26
Bpage::columns
void columns(long ncol)
Definition: Bplot.h:105
img_resolution_from_two_images
int img_resolution_from_two_images(Bstring &image_file, Bstring &ref_file, Bstring &real_mask_file, Bstring &ft_mask_file, double resolution, double aligned_res, Vector3< float > sampling, double sampling_ratio, float *cutoff, Bstring &ps_file, Bstring &xml_file, Bstring &tsv_file, Bstring &proj_file)
Calculates the resolution from two images.
Definition: img_resolution.cpp:552
data
JSAMPIMAGE data
Definition: jpeglib.h:945
model
Bmodel * model
Definition: tcltk_bshow.cpp:32
Complex::power
double power()
Definition: Complex.h:103
Complex::real
Type real()
Definition: Complex.h:101
img_resolution.h
Library routines to estimate resolution.
NoTransform
Definition: Bimage.h:34
Bimage::pack_two_in_complex
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
Definition: Bimage_complex.cpp:600
Bplot::data_pointer
double * data_pointer()
Definition: Bplot.h:217
Bstring::length
long length() const
Definition: Bstring.cpp:278
Vector3::volume
double volume()
Definition: Vector3.h:205
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:321
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bimage::image
Bsub_image * image
Definition: Bimage.h:183
Bcolumn::axis
long axis()
Definition: Bplot.h:68
Bplot
Definition: Bplot.h:146
xml_write_fsc
void xml_write_fsc(Bstring &filename, Bplot *plot)
Definition: rwFSC_XML.cpp:218