Bsoft  2.1.0
Bernard's software package
mg_particles.cpp
Go to the documentation of this file.
1 
9 #include "mg_processing.h"
10 #include "mg_particles.h"
11 #include "mg_select.h"
12 #include "mg_img_proc.h"
13 #include "rwimg.h"
14 #include "matrix_linear.h"
15 #include "file_util.h"
16 #include "utilities.h"
17 #include "timer.h"
18 
19 #include <sys/stat.h>
20 
21 // Declaration of global variables
22 extern int verbose; // Level of output to the screen
23 
24 
37  double nuavg, double nustd)
38 {
39  long psel, n, nc(0);
40  Bfield* field;
41  Bmicrograph* mg;
42  Breconstruction* rec;
43  Bparticle* part ;
44  Bimage* p;
45  Bimage* p1;
46 
47  if ( verbose ) {
48  cout << "Aligning particle images" << endl;
49  cout << "Selection: " << part_select << endl;
50  if ( nustd > 0 )
51  cout << "Rescale avg & stdev: " << nuavg << " " << nustd << endl;
52  }
53 
54  if ( project->select < 1 ) {
55  for ( field = project->field; field; field = field->next ) {
56  for ( mg = field->mg; mg; mg = mg->next ) {
57  if ( ( p = read_img(mg->fpart, 1, -1) ) == NULL ) {
58  error_show("project_align_particles", __FILE__, __LINE__);
59  return -1;
60  }
61  for ( n=0, part = mg->part; part && n<p->images(); part = part->next, n++ ) {
62  psel = 0;
63  if ( part->sel ) {
64  if ( part_select < 0 ) {
65  psel = 1;
66  } else if ( part->sel == part_select ) {
67  psel = 1;
68  }
69  }
70  if ( psel ) { // Use only selected images
71  p1 = p->extract(n);
72  p1->rotate(p1->size()/2 - part->ori, part->view);
73  if ( nustd > 0 ) p1->rescale_to_avg_std(nuavg, nustd);
74 // p1->image->origin(p1->size()/2);
75  p1->origin(p1->size()/2);
76  p1->image->view(0,0,1,0);
77  part->ori = p1->image->origin();
78  part->view = p1->image->view();
79  p->replace(n, p1);
80  delete p1;
81  nc++;
82  }
83  }
84  mg->fpart = mg->fpart.pre_rev('.') + "_aln." + mg->fpart.post_rev('.');
85  write_img(mg->fpart, p, 0);
86  delete p;
87  }
88  }
89  } else {
90  for ( rec = project->rec; rec; rec = rec->next ) {
91  for ( n=0, part = rec->part; part; part = part->next, n++ ) {
92  psel = 0;
93  if ( part->sel ) {
94  if ( part_select < 0 ) {
95  psel = 1;
96  } else if ( part->sel == part_select ) {
97  psel = 1;
98  }
99  }
100  if ( psel ) { // Use only selected images
101  if ( ( p1 = read_img(part->fpart, 1, 0) ) == NULL ) {
102  error_show("project_align_particles", __FILE__, __LINE__);
103  return -1;
104  }
105  p1->rotate(p1->size()/2 - part->ori, part->view);
106  if ( nustd > 0 ) p1->rescale_to_avg_std(nuavg, nustd);
107 // p1->image->origin(p1->size()/2);
108  p1->origin(p1->size()/2);
109  p1->image->view(0,0,1,0);
110  part->ori = p1->image->origin();
111  part->view = p1->image->view();
112  part->fpart = part->fpart.pre_rev('.') + "_aln." + part->fpart.post_rev('.');
113  write_img(part->fpart, p1, 0);
114  delete p1;
115  nc++;
116  }
117  }
118  }
119  }
120 
121  if ( verbose )
122  cout << "Particles oriented: " << nc << endl << endl;
123 
124  return 0;
125 }
126 
139  double nuavg, double nustd)
140 {
141  long psel, n, np, nc(0);
142  Bfield* field;
143  Bmicrograph* mg;
144  Breconstruction* rec;
145  Bparticle* part;
146  Bimage* p = NULL;
147  Bimage* pm = NULL;
148 
149  if ( verbose ) {
150  cout << "Centering particle images" << endl;
151  cout << "Selection: ";
152  if ( part_select < 0 ) cout << "all" << endl;
153  else cout << part_select << endl;
154  if ( nustd > 0 )
155  cout << "Rescale avg & stdev: " << nuavg << " " << nustd << endl;
156  }
157 
158  if ( project->select < 1 ) {
159  for ( field=project->field; field; field=field->next ) {
160  for ( mg=field->mg; mg; mg=mg->next ) {
161  for ( np=0, part=mg->part; part; part=part->next, np++ ) ;
162  for ( n=0, part=mg->part; part; part=part->next, n++ ) {
163  if ( ( p = particle_read_img(part, 1) ) == NULL ) {
164  error_show("project_center_particles", __FILE__, __LINE__);
165  return -1;
166  }
168  psel = 0;
169  if ( part->sel ) {
170  if ( part_select < 0 ) {
171  psel = 1;
172  } else if ( part->sel == part_select ) {
173  psel = 1;
174  }
175  }
176  if ( psel ) { // Use only selected images
177  p->origin(part->ori);
178  part->loc -= p->size()/2 - part->ori;
179  part->ori = p->size()/2;
180  } else {
181  p->origin(p->size()/2);
182  }
184  if ( nustd > 0 ) p->rescale_to_avg_std(nuavg, nustd);
185  if ( verbose & VERB_FULL )
186  cout << part->id << tab << p->image->origin() << tab
187  << p->image->background() << endl;
188  nc++;
189  if ( part->fpart.length() ) {
190  part->fpart = part->fpart.pre_rev('.') + "_cen." + part->fpart.post_rev('.');
191  write_img(part->fpart, p, 0);
192  } else {
193  if ( n == 0 ) {
194  pm = new Bimage(p->data_type(), p->compound_type(), p->size(), np);
195  pm->origin(pm->default_origin());
196  pm->sampling(p->sampling(0));
197  }
198  pm->replace(n, p);
199  }
200  delete p;
201  }
202  if ( pm && mg->fpart.length() ) {
203  mg->fpart = mg->fpart.pre_rev('.') + "_cen." + mg->fpart.post_rev('.');
204  write_img(mg->fpart, pm, 0);
205  delete pm;
206  }
207  }
208  }
209  } else {
210  for ( rec = project->rec; rec; rec = rec->next ) {
211  for ( n=0, part = rec->part; part && n<p->images(); part = part->next, n++ ) {
212  psel = 0;
213  if ( part->sel ) {
214  if ( part_select < 0 ) {
215  psel = 1;
216  } else if ( part->sel == part_select ) {
217  psel = 1;
218  }
219  }
220  if ( psel ) { // Use only selected images
221  if ( ( p = read_img(part->fpart, 1, 0) ) == NULL ) {
222  error_show("project_align_particles", __FILE__, __LINE__);
223  return -1;
224  }
225  p->image[n].origin(part->ori);
226  part->loc -= p->size()/2 - part->ori;
227  part->ori = p->size()/2;
229  if ( verbose & VERB_FULL )
230  cout << part->id << tab << p->image->origin() << tab
231  << p->background(long(0)) << endl;
233  if ( nustd > 0 ) p->rescale_to_avg_std(nuavg, nustd);
234  rec->fpart = rec->fpart.pre_rev('.') + "_cen." + rec->fpart.post_rev('.');
235  write_img(rec->fpart, p, 0);
236  delete p;
237  nc++;
238  }
239  }
240  }
241  }
242 
243  if ( verbose )
244  cout << "Particles oriented: " << nc << endl << endl;
245 
246  return 0;
247 }
248 
264  int part_select, double hires, double lores)
265 {
266  int psel;
267 // Vector3<float>* shift;
268  Bfield* field = project->field;
269  Bmicrograph* mg = field->mg;
270  Bparticle* part = mg->part;
271  Bimage* p;
272 
273  if ( verbose )
274  cout << "Setting the centers of particle images" << endl << endl;
275 
276  for ( field=project->field; field; field=field->next ) {
277  for ( mg=field->mg; mg; mg=mg->next ) {
278  for ( part=mg->part; part; part=part->next ) {
279  psel = 0;
280  if ( part->sel ) {
281  if ( part_select < 0 ) {
282  psel = 1;
283  } else if ( part->sel == part_select ) {
284  psel = 1;
285  }
286  }
287  if ( psel ) { // Use only selected images
288  if ( ( p = read_img(mg->fpart, 1, part->id - 1) ) == NULL ) {
289  error_show("mg_set_particle_centers", __FILE__, __LINE__);
290  return -1;
291  }
292  p->origin(p->size()/2);
293 // img_find_shift(pref, p, NULL, hires, lores, p->sizeX()/4, 0, 1);
294  pref->find_shift(p, NULL, hires, lores, p->sizeX()/4, 0, 1);
295  part->ori = p->image->origin();
296  delete p;
297  }
298  }
299  }
300  }
301 
302  return 0;
303 }
304 
323  double hires, double lores, int filter_flag)
324 {
325  long npart(0);
326 
327  if ( verbose & VERB_LABEL )
328  cout << "Finding particle centers with resolution limits " << hires << " - " << lores << " A" << endl;
329 
330  Bfield* field;
331  Bmicrograph* mg;
332 
333  for ( field=project->field; field; field=field->next )
334  for ( mg=field->mg; mg; mg=mg->next )
335  npart += mg_find_part_centers(mg, hires, lores, filter_flag);
336 
337  return npart;
338 }
339 
358  double hires, double lores, int filter_flag)
359 {
360  Vector3<long> box_size(mg->box_size);
361 
362  if ( verbose & VERB_LABEL )
363  cout << "Finding particle centers with resolution limits " << hires << " - " << lores << " A" << endl;
364 
365  Vector3<double> start;
366  Bparticle* part;
367  Bimage* pex = NULL;
368  Bimage* pexrot = NULL;
369 
370  long npart(particle_count(mg->part));
371  if ( npart < 1 ) return 0;
372 
373  Bimage* p = read_img(mg->fmg, 1, mg->img_num);
374 
375  if ( filter_flag ) p->filter_extremes(1);
376 
377  if ( verbose & VERB_PROCESS )
378  cout << "Finding particle origins from image " << p->file_name() << endl;
379 
380  for ( part=mg->part; part; part=part->next ) {
381  start = part->loc - box_size/2;
382  pex = p->extract(0, start, box_size);
383  pexrot = pex->rotate(pex->size(), M_PI);
384  pex->find_shift(pexrot, NULL, hires, lores, pex->sizeX()/8.0, 0, 1);
385  part->loc += (pexrot->image->origin() - pex->image->origin())/2;
386  part->fom[0] = pexrot->image->FOM();
387  delete pex;
388  delete pexrot;
389  }
390 
391  delete p;
392 
393  return npart;
394 }
395 
412  int part_select, double hires, double lores)
413 {
414  int iter, psel, n;
415  double d, R(1e30), change(1e30);
416  Vector3<float> origin, shift1;
417  Bfield* field = project->field;
418  Bmicrograph* mg = field->mg;
419  Bparticle* part = mg->part;
420  View ref_view;
421  Bimage* p;
422  Bimage* pref = NULL;
423 
424  if ( verbose )
425  cout << "Finding the centers of particle images" << endl << endl;
426 
427  if ( verbose & VERB_RESULT )
428  cout << "Iter\tR" << endl;
429 
430  for ( iter=0; iter<max_iter && R > 0.1 && change > 0.001; iter++ ) {
431  if ( pref ) pref->clear();
432  for ( field=project->field; field; field=field->next ) { // Generating the reference image
433  for ( mg=field->mg; mg; mg=mg->next ) {
434  for ( part=mg->part; part; part=part->next ) {
435  psel = 0;
436  if ( part->sel ) {
437  if ( part_select < 0 ) {
438  psel = 1;
439  } else if ( part->sel == part_select ) {
440  psel = 1;
441  }
442  }
443  if ( psel ) { // Use only selected images
444  p = particle_read_img(part, 1);
445  p->change_type(Float);
446  if ( part->ori.length() < 1 ) part->ori = p->size()/2;
447  if ( !pref ) {
448  pref = p->copy();
449 // pref->image->origin(pref->size()/2);
450  pref->origin(pref->size()/2);
451  pref->clear();
452  }
453  shift1 = pref->image->origin() - part->ori;
454  if ( verbose & VERB_FULL )
455  cout << shift1 << endl;
456  p->shift_wrap(shift1);
457  pref->add(p);
458  delete p;
459  }
460  }
461  }
462  }
463  pref->calculate_background();
464  pref->symmetrize_cylinder();
465  pref->calculate_background();
466  pref->shift_background(0);
467  write_img("part_avg.pif", pref, 0);
468  n = 0;
469  change = R;
470  R = 0;
471  for ( field=project->field; field; field=field->next ) { // Determining the shift for centering
472  for ( mg=field->mg; mg; mg=mg->next ) {
473  for ( part=mg->part; part; part=part->next ) {
474  psel = 0;
475  if ( part->sel ) {
476  if ( part_select < 0 ) {
477  psel = 1;
478  } else if ( part->sel == part_select ) {
479  psel = 1;
480  }
481  }
482  if ( psel ) { // Use only selected images
483  p = particle_read_img(part, 1);
484  p->change_type(Float);
485  p->origin(part->ori);
486  p->find_shift(pref, NULL, hires, lores, p->sizeX()/8, 0, 1);
487 // origin = - p->image->origin() + p->size();
488  origin = p->image->origin();
489  origin[2] = 0;
490  if ( verbose & VERB_FULL )
491  cout << origin << endl;
492  d = (origin - part->ori).length2();
493  R += d;
494  part->ori = origin;
495  delete p;
496  n++;
497  }
498  }
499  }
500  }
501  R = sqrt(R/n);
502  change -= R;
503  if ( verbose & VERB_RESULT )
504  cout << iter+1 << tab << R << endl;
505  }
506 
507  if ( verbose & VERB_RESULT )
508  cout << endl;
509 
510 // kill_symmetry(sym);
511 
512  return pref;
513 }
514 
515 long particles_mask(Bmicrograph* mg, Bimage* pmask, Bstring& partpath)
516 {
517  long n(0);
518  Matrix3 mat;
519  Vector3<double> translate;
520  Bparticle* part = mg->part;
521  Bimage* p;
522  Bimage* ppart = NULL;
523  Bimage* pm;
524 
525  if ( mg->part && mg->fpart.length() && mg->part->fpart.length() < 1 ) {
526  ppart = read_img(mg->fpart, 1, -1);
527  ppart->sampling(part->pixel_size);
528  ppart->change_type(Float);
529  }
530 
531  for ( part = mg->part; part; part = part->next ) {
532  if ( part->fpart.length() ) {
533  p = read_img(part->fpart, 1, 0);
534  } else {
535  p = ppart->extract(part->id-1);
536  }
537  p->change_type(Float);
538  p->rescale_to_avg_std(0,1);
539  p->image->view(part->view);
540 // p->image->origin(part->ori);
541  p->origin(part->ori);
542  translate = part->ori - p->size()/2;
543  mat = p->image->view().matrix();
544  pm = pmask->rotate_project(mat, translate, p->sizeX()/2.0);
545  pm->truncate(0, 0.001*pm->standard_deviation(), 0, 1);
546  pm->filter_average(7);
547  p->multiply(pm);
548  delete pm;
549  if ( part->fpart.length() ) {
550  part->fpart = part->fpart.pre_rev('.') + "_m." + part->fpart.post_rev('.');
551  if ( partpath.length() > 1 )
552  part->fpart = partpath + part->fpart.post_rev('/');
553  write_img(part->fpart, p, 0);
554  } else {
555  ppart->replace(part->id - 1, p);
556  }
557  delete p;
558  n++;
559  }
560 
561  if ( ppart ) {
562  mg->fpart = mg->fpart.pre_rev('.') + "_m." + mg->fpart.post_rev('.');
563  if ( partpath.length() > 1 )
564  mg->fpart = partpath + mg->fpart.post_rev('/');
565  write_img(mg->fpart, ppart, 0);
566  delete ppart;
567  }
568 
569  return n;
570 }
571 
583 {
584  pmask->change_type(Float);
585 
586  if ( !partpath.empty() ) if ( partpath[-1] != '/' ) partpath += "/";
587 
588  long nmg(0);
589  Matrix3 mat;
590  Vector3<double> translate;
591 
592 // Bfield* field = project->field;
593 
594  if ( partpath.length() > 1 )
595  mkdir(partpath.c_str(), (mode_t)0755);
596 
597  if ( verbose )
598  cout << "Masking particle images" << endl << endl;
599 
601 
602 #ifdef HAVE_GCD
603  __block long n(0);
604  dispatch_queue_t myq = dispatch_queue_create(NULL, NULL);
605  dispatch_apply(nmg, dispatch_get_global_queue(0, 0), ^(size_t i){
606  long n1 = particles_mask(mgarr[i], pmask, partpath);
607  dispatch_sync(myq, ^{
608  n += n1;
609  if ( verbose & VERB_RESULT )
610  cout << setw(15) << mgarr[i]->id << tab << n << endl;
611  });
612  });
613 #else
614  long n(0);
615 #pragma omp parallel for
616  for ( long i=0; i<nmg; i++ ) {
617  long n1 = particles_mask(mgarr[i], pmask, partpath);
618  #pragma omp critical
619  {
620  n += n1;
621  if ( verbose & VERB_RESULT )
622  cout << setw(15) << mgarr[i]->id << tab << n << endl;
623  }
624  }
625 #endif
626 
627  delete[] mgarr;
628 
629 /* for ( field = project->field; field; field = field->next ) {
630  for ( mg = field->mg; mg; mg = mg->next ) {
631  if ( verbose ) cout << "Micrograph: " << mg->id << endl;
632  particles_mask(mg, pmask, partpath);
633  }
634  }
635 */
636  if ( verbose & VERB_RESULT )
637  cout << endl;
638 
639  return n;
640 }
641 
654 {
655  long nf, tp(0), tn(0), fp(0);
656  double d, r;
657 
658  Bfield* field, *fieldcomp;
659  Bmicrograph* mg, *mgcomp;
660  Bparticle* part, *partcomp;
661 
662  for ( field = project->field; field; field = field->next ) {
663  for ( fieldcomp = projcomp->field; fieldcomp && fieldcomp->id != field->id; fieldcomp = fieldcomp->next ) ;
664  if ( fieldcomp ) {
665  for ( mg = field->mg; mg ; mg = mg->next ) {
666  for ( mgcomp = fieldcomp->mg; mgcomp && mgcomp->id != mg->id; mgcomp = mgcomp->next ) ;
667  if ( mgcomp ) {
668  r = mg->box_size[0]/2;
669  for ( partcomp = mgcomp->part; partcomp; partcomp = partcomp->next ) {
670  partcomp->sel = 0;
671  partcomp->fom[0] = 2*r;
672  }
673  for ( part = mg->part; part; part = part->next ) {
674  part->sel = 0;
675  nf = 0;
676  for ( partcomp = mgcomp->part; partcomp; partcomp = partcomp->next ) {
677  d = part->loc.distance(partcomp->loc);
678  if ( d < r && partcomp->fom[0] > d ) {
679  partcomp->fom[0] = d;
680  partcomp->sel = part->id;
681  part->sel = partcomp->id;
682  nf++;
683  }
684  }
685  if ( nf ) tp++;
686  else tn++;
687  }
688  for ( partcomp = mgcomp->part; partcomp; partcomp = partcomp->next )
689  if ( partcomp->sel < 1 ) fp++;
690  }
691  }
692  }
693  }
694 
695  if ( verbose ) {
696  cout << "Comparing " << project->filename << " against " << projcomp->filename << endl;
697  cout << "True positive: " << tp << endl;
698  cout << "True negative: " << tn << endl;
699  cout << "False positive: " << fp << endl << endl;
700  }
701 
702  return tp;
703 }
704 
713 {
714  long i, j, nmg(0), nmgsel(0), npart(0), nptot(0), npsel(0);
715  double axis, axis_avg(0), axis_std(0), a1, da;
716  double tilt, tilt_avg(0), tilt_std(0);
717  double ddef, ddef_rmsd(0);
718  Vector3<double> loc, normal;
719  vector<double> b(3);
720  Matrix a(3,3);
721 
722  Bfield* field;
723  Bmicrograph* mg;
724  Bparticle* part;
725 
727 
728  for ( field = project->field; field; field = field->next ) {
729  for ( mg = field->mg; mg ; mg = mg->next, nmg++ ) if ( mg->select ) {
730  for ( i=0; i<3; i++ ) {
731  for ( j=0; j<3; j++ )
732  a[j][i] = 0;
733  b[i] = 0;
734  }
735  npart = 0;
736  ddef_rmsd = 0;
737  for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
738  loc = part->loc - mg->origin;
739  ddef = part->def - mg->ctf->defocus_average();
740  ddef_rmsd += ddef*ddef;
741  loc[2] = ddef/mg->pixel_size[0];
742  for ( i=0; i<3; i++ ) {
743  for ( j=0; j<3; j++ )
744  a[j][i] += loc[i]*loc[j];
745  b[i] += loc[i];
746  }
747  npart++;
748  }
749  npsel += npart;
750  normal = fit_plane(a, b);
751  if ( normal[2] < 0 ) normal = -normal;
752  axis = atan2(-normal[0], normal[1]);
753  tilt = acos(normal[2]);
754  if ( nmg > 0 ) {
755  da = fabs(angle_set_negPI_to_PI(axis - a1));
756  if ( da > M_PI_2 ) {
757  axis = angle_set_negPI_to_PI(axis + M_PI);
758  tilt = -tilt;
759  }
760  } else {
761  a1 = axis;
762  }
763  if ( npart )
764  ddef_rmsd = sqrt(ddef_rmsd/npart);
765  if ( npart > 5 ) {
766  axis_avg += axis;
767  axis_std += axis*axis;
768  tilt_avg += tilt;
769  tilt_std += tilt*tilt;
770  nmgsel++;
771  }
772  if ( verbose )
773  cout << mg->id << tab << npart << tab << ddef_rmsd << tab << axis*180.0/M_PI << tab << tilt*180.0/M_PI << endl;
774  }
775  }
776 
777  if ( nmgsel ) {
778  axis_avg /= nmgsel;
779  axis_std = axis_std/nmgsel - axis_avg*axis_avg;
780  if ( axis_std > 0 ) axis_std = sqrt(axis_std);
781  tilt_avg /= nmgsel;
782  tilt_std = tilt_std/nmgsel - tilt_avg*tilt_avg;
783  if ( tilt_std > 0 ) tilt_std = sqrt(tilt_std);
784  }
785 
786  if ( verbose ) {
787  cout << "Number of micrographs: " << nmgsel << " (" << nmgsel*100.0/nmg << "%)" << endl;
788  cout << "Number of particles: " << npsel << " (" << npsel*100.0/nptot << "%)" << endl;
789  cout << "Axis average & stdev: " << axis_avg*180.0/M_PI << tab << axis_std*180.0/M_PI << endl;
790  cout << "Tilt average & stdev: " << tilt_avg*180.0/M_PI << tab << tilt_std*180.0/M_PI << endl;
791  }
792 
793  return axis_avg;
794 }
795 
806 {
807  long npart(0);
808  double ca(cos(axis)), sa(sin(axis)), tt(tan(tilt));
809  Vector3<double> coor;
810 
811  Bfield* field;
812  Bmicrograph* mg;
813  Bparticle* part;
814 
815  for ( field = project->field; field; field = field->next ) {
816  for ( mg = field->mg; mg ; mg = mg->next ) if ( mg->select ) {
817  for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
818  coor = (part->loc - mg->origin)*mg->pixel_size;
819  part->def = mg->ctf->defocus_average() + (coor[0]*sa - coor[1]*ca)*tt;
820  if ( verbose )
821  cout << part->loc << tab << part->def - mg->ctf->defocus_average() << endl;
822  npart++;
823  }
824  }
825  }
826 
827  return npart;
828 }
829 
length2
double length2(vector< T > v)
Definition: Vector3.h:519
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:415
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:291
matrix_linear.h
Header file for matrix functions.
mg_particles.h
Manipulates single particle images.
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
Bimage::truncate
int truncate(double minim, double maxim, double setmin, double setmax)
Truncates image data to a given minimum and maximum.
Definition: Bimage_rescale.cpp:277
Bimage::symmetrize_cylinder
Bimage * symmetrize_cylinder(int flag)
Calculates a cylindrically symmetrized map.
Definition: Bimage_helix.cpp:524
Bproject::select
int select
Definition: mg_processing.h:342
Bparticle::view
View view
Definition: mg_processing.h:102
file_util.h
Header file for file checking functions.
Bstring
Definition: Bstring.h:29
Bparticle
Definition: mg_processing.h:90
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
project_align_particles
int project_align_particles(Bproject *project, int part_select, double nuavg, double nustd)
Aligns single particle images based on orientation parameters.
Definition: mg_particles.cpp:36
project_set_particle_centers
int project_set_particle_centers(Bproject *project, Bimage *pref, int part_select, double hires, double lores)
Calculates centers of single particle images by cross-correlation with a reference.
Definition: mg_particles.cpp:263
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2702
Bimage::center
int center(int fill_type=0, double fill=0)
Centers an image.
Definition: Bimage_transform.cpp:694
Vector3< long >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:592
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
mg_select.h
Header file for micrograph processing.
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Bproject::filename
Bstring filename
Definition: mg_processing.h:338
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Bstring::empty
bool empty()
Definition: Bstring.h:71
Bimage::background
double background(long nn)
Definition: Bimage.h:549
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bfield::id
Bstring id
Definition: mg_processing.h:262
Bimage::rotate_project
Bimage * rotate_project(Matrix3 mat, Vector3< double > translate, double radial_cutoff, int norm_flag=1)
Rotates a 3D map and projects it along the z-axis.
Definition: Bimage_project.cpp:118
View
Definition: View.h:26
project_micrograph_array
Bmicrograph ** project_micrograph_array(Bproject *project, long &nmg)
Sets up an array of selected micrograph pointers.
Definition: mg_processing.cpp:1254
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bimage::shift_wrap
int shift_wrap(Vector3< double > vec)
Shifts an image.
Definition: Bimage_transform.cpp:641
Bimage::find_shift
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Definition: Bimage_correlate.cpp:929
Bfield
Definition: mg_processing.h:260
Bsub_image::FOM
double FOM()
Definition: Bimage.h:165
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
M_PI_2
#define M_PI_2
Definition: utilities.h:66
project_center_particles
int project_center_particles(Bproject *project, int part_select, double nuavg, double nustd)
Centers single particle images based on the parametric center.
Definition: mg_particles.cpp:138
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:544
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:558
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Bsub_image::background
double background()
Definition: Bimage.h:125
project
Bproject * project
Definition: bshow.cpp:33
Matrix3
Definition: Matrix3.h:18
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:325
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bimage::shift_background
int shift_background(double bkg)
Sets the background for each sub-image to a given value.
Definition: Bimage_background.cpp:351
Bimage::add
void add(long j, double v)
Definition: Bimage.h:321
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
mg_find_part_centers
long mg_find_part_centers(Bmicrograph *mg, double hires, double lores, int filter_flag)
Finds the centers of picked particles within a micrograph.
Definition: mg_particles.cpp:357
particles_mask
long particles_mask(Bmicrograph *mg, Bimage *pmask, Bstring &partpath)
Definition: mg_particles.cpp:515
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:255
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
project_set_particle_defocus_from_tilt
long project_set_particle_defocus_from_tilt(Bproject *project, double axis, double tilt)
Finds the tilt axis from refined particle defocus values.
Definition: mg_particles.cpp:805
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:109
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:364
timer.h
Utilities for timing functions.
project_find_particle_centers
Bimage * project_find_particle_centers(Bproject *project, int max_iter, int part_select, double hires, double lores)
Calculates centers of single particle images.
Definition: mg_particles.cpp:411
Bproject
Definition: mg_processing.h:336
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:563
verbose
int verbose
Bparticle::sel
long sel
Definition: mg_processing.h:104
project_tilt_from_particle_defocus
double project_tilt_from_particle_defocus(Bproject *project)
Finds the tilt axis from refined particle defocus values.
Definition: mg_particles.cpp:712
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2830
mg_img_proc.h
Header file for image processing from micrograph structures.
Bimage::clear
void clear()
Definition: Bimage.h:705
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
Bimage::data_type
DataType data_type()
Definition: Bimage.h:362
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
project_compare_particles
long project_compare_particles(Bproject *project, Bproject *projcomp)
Compares the coordinates of particles between two files.
Definition: mg_particles.cpp:653
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
fit_plane
Vector3< double > fit_plane(Matrix a, vector< double > b)
Solves for fitting a plane through a model.
Definition: matrix_linear.cpp:227
Bparticle::def
double def
Definition: mg_processing.h:96
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
project_find_part_centers_in_mgs
long project_find_part_centers_in_mgs(Bproject *project, double hires, double lores, int filter_flag)
Finds the centers of picked particles within a micrograph.
Definition: mg_particles.cpp:322
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
rwimg.h
Header file for 2D and 3D image I/O.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
Bimage::filter_average
int filter_average(long kernel_size)
Applies an averaging filter to an image.
Definition: Bimage_filter.cpp:207
mg_processing.h
Header file for micrograph processing.
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
Bmicrograph::select
long select
Definition: mg_processing.h:204
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
project_mask_particles
long project_mask_particles(Bproject *project, Bimage *pmask, Bstring &partpath)
Calculates centers of single particle images.
Definition: mg_particles.cpp:582
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
particle_read_img
Bimage * particle_read_img(Bparticle *part, int readflag)
Reads a particle image file.
Definition: mg_img_proc.cpp:519
Vector3::length
double length()
Definition: Vector3.h:222
Matrix
Definition: Matrix.h:22
particle_count
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_select.cpp:755
Float
@ Float
Definition: utilities.h:161
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bparticle::id
int id
Definition: mg_processing.h:93
Bimage::filter_extremes
int filter_extremes()
Filters the extremes out of a micrograph image.
Definition: Bimage_segment.cpp:620
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163