Bsoft  2.1.0
Bernard's software package
mg_pick.cpp
Go to the documentation of this file.
1 
9 #include "mg_pick.h"
10 #include "mg_processing.h"
11 #include "mg_select.h"
12 #include "linked_list.h"
13 #include "utilities.h"
14 
15 // Declaration of global variables
16 extern int verbose; // Level of output to the screen
17 
18 /* flags 1: quadric correct; 2: gaussian filter; 4: mask background */
19 Bimage* img_prepare_for_picking(Bimage* p, int flags, long sigma, long bin)
20 {
21  Bimage* pb = p->bin_copy(bin);
22 
23  if ( flags & 1 ) pb->quadric_correct(pb->quadric_fit());
24 
25  long ksize(9);
26  if ( flags & 2 ) {
27  sigma /= bin;
28  if ( sigma < 1 ) sigma = 1;
29  ksize = 2*( (long) (4*sigma + 0.9) ) + 1;
30  pb->filter_gaussian(ksize, sigma);
31  }
32 
33  pb->rescale_to_avg_std(0, 1);
34  pb->statistics();
35 
36  double threshold(pb->average() - 3*pb->standard_deviation());
37  Bimage* pmask = NULL;
38 
39  if ( verbose & VERB_FULL )
40  cout << "threshold = " << threshold << endl;
41 
42  if ( flags & 4 ) {
43  pmask = pb->mask_by_threshold(threshold);
44  pmask->mask_erode(5);
45  pmask->change_type(Float);
46  pmask->filter_average(11);
47  pb->multiply(pmask, 1, 0);
48  delete pmask;
49  }
50 
51  return pb;
52 }
53 
54 
75 Bparticle* particles_from_peaks(Bimage* pcc, long bin, double excl_dist,
76  double part_ori, double& fommin, double fommax,
77  long maxnum, double pix_min, double pix_max)
78 {
79  if ( part_ori < excl_dist ) part_ori = excl_dist;
80 
81  long i, j, ncoor;
82  double fom;
83  Vector3<double> origin(part_ori, part_ori, part_ori);
84  origin = origin.min(pcc->size()-1);
85  Vector3<long> min(origin/bin), max(pcc->size()-min);
86 
87  if ( verbose & VERB_PROCESS )
88  cout << "Limits: " << min << tab << max << endl;
89 
90  Vector3<long> obin(bin, bin, bin);
91  obin = obin.min(pcc->size());
92 
93  if ( excl_dist < 10 ) excl_dist = 1.8*part_ori;
94 
95  excl_dist /= bin;
96 
97  Vector3<double>* coor = pcc->find_peaks(excl_dist, ncoor, fommin, fommax, pix_min, pix_max);
98 
99  Bparticle* partlist = NULL;
100  Bparticle* part = NULL;
101 
102  for ( i=j=0; i<ncoor && j<maxnum; i++ ) {
103  fom = pcc->get(0, coor[i]);
104  if ( fom >= fommin && fom <= fommax ) {
105  if ( coor[i] >= min && coor[i] <= max ) {
106  part = particle_add(&part, ++j);
107  if ( !partlist ) partlist = part;
108  part->loc = coor[i] * obin;
109  part->ori = origin;
110  part->fom[0] = fom;
111  }
112  }
113  }
114 
115  delete[] coor;
116 
117  if ( verbose & VERB_PROCESS )
118  cout << "Number of particles found: " << j << endl << endl;
119 
120  return partlist;
121 }
122 
123 
142  double hires, double lores, double fommin, double fommax, double excl_dist, long bin)
143 {
144  if ( !p ) return NULL;
145  if ( bin < 1 ) bin = 1;
146  if ( bin > 4 ) bin = 4;
147  if ( excl_dist < 1 ) excl_dist = 0.8*ptemp->sizeX();
148 
149  if ( verbose & VERB_FULL )
150  cout << "Picking from " << p->file_name() << endl;
151 
152  long sigma(10);
153  Bimage* pb = img_prepare_for_picking(p, 3, sigma, bin);
154 
155  fft_plan planf = pb->fft_setup(FFTW_FORWARD, 0);
156  fft_plan planb = pb->fft_setup(FFTW_BACKWARD, 0);
157 
158  Bimage* pcc = pb->find_template(ptemp, pmask, hires, lores, 1, planf, planb);
159 
162  delete pb;
163 
164  ptemp->image->FOM(pcc->image->FOM());
165 
166  if ( verbose & VERB_DEBUG )
167  write_img("pcc.pif", pcc, 0);
168 
169  if ( verbose & VERB_DEBUG )
170  cout << "DEBUG particles_pick: bin=" << bin << endl;
171 
172  Bparticle* partlist = particles_from_peaks(pcc, bin, excl_dist,
173  ptemp->image->origin()[0], fommin, fommax);
174 
175  delete pcc;
176 
177  return partlist;
178 }
179 
180 double gauss_find_intersection(long ngauss, vector<double>& gauss)
181 {
182  double a1, a2, v, d(1), l((gauss[1]+gauss[2])/(gauss[0]+gauss[3]));
183  double cut((gauss[1] + gauss[4])/2);
184 
185  while ( d > 1e-6 ) {
186  v = (cut - gauss[1])/gauss[2];
187  a1 = gauss[0]*exp(-0.5*v*v);
188  v = (cut - gauss[4])/gauss[5];
189  a2 = gauss[3]*exp(-0.5*v*v);
190  d = a2 - a1;
191  cut -= l*d;
192  l *= 0.99;
193  if ( verbose & VERB_DEBUG )
194  cout << a1 << tab << a2 << tab << cut << endl;
195  d = fabs(d);
196  }
197 
198  if ( verbose & VERB_DEBUG )
199  cout << "u1=" << gauss[1] << tab << "u2=" << gauss[4] << tab << "cut=" << cut << endl;
200 
201  return cut;
202 }
203 
220 Bparticle* particles_pick_var(Bimage* p, long avg_kernel, long var_kernel,
221  double nsig, double part_ori, double excl_dist, long bin)
222 {
223  if ( !p ) return NULL;
224  if ( bin < 1 ) bin = 1;
225  if ( bin > 4 ) bin = 4;
226  if ( excl_dist < 1 ) excl_dist = 1.6*part_ori;
227 
228  if ( verbose & VERB_FULL )
229  cout << "Picking from " << p->file_name() << endl;
230 
231  avg_kernel /= bin;
232  var_kernel /= bin;
233 
234  if ( verbose & VERB_DEBUG )
235  cout << "DEBUG particles_pick_var: nsig=" << nsig << endl;
236 
237  Bimage* pc = p->bin_copy(bin);
238  pc->filter_average(avg_kernel);
239  pc->variance(var_kernel);
240 
241  // Two gaussians are fitted to the variance image histogram
242  vector<double> gauss = pc->histogram_gauss_fit(256, 2);
243  double fomcut, t;
244 
245  t = fabs(gauss[1]-gauss[4])/sqrt(gauss[2]*gauss[2]+gauss[5]*gauss[5]);
246 
247 // fomcut = gauss_find_intersection(2, gauss);
248 /*
249  if ( gauss[1] < gauss[4] ) {
250  fomcut = gauss[1] + nsig*gauss[2];
251  if ( t > 1 && fomcut > gauss[4] ) fomcut = gauss_find_intersection(2, gauss);
252  } else {
253  fomcut = gauss[4] + nsig*gauss[5];
254  if ( t > 1 && fomcut > gauss[1] ) fomcut = gauss_find_intersection(2, gauss);
255  }
256 */
257 
258  if ( gauss[1] < gauss[4] ) {
259  fomcut = gauss[1] + nsig*gauss[2];
260  if ( fomcut > gauss[4] ) fomcut = gauss[4];
261  } else {
262  fomcut = gauss[4] + nsig*gauss[5];
263  if ( fomcut > gauss[1] ) fomcut = gauss[1];
264  }
265 
266  if ( verbose ) {
267  cout << "Variance image min, max: " << pc->minimum() << tab << pc->maximum() << endl;
268  cout << "First peak: " << gauss[0] << tab << gauss[1] << tab << gauss[2] << endl;
269  cout << "Second peak: " << gauss[3] << tab << gauss[4] << tab << gauss[5] << endl;
270  cout << "T and FOM: " << t << tab << fomcut << endl;
271  }
272 
273  if ( verbose & VERB_DEBUG ) {
274  cout << "DEBUG particles_pick_var: fomcut=" << fomcut << endl;
275  write_img("var.pif", pc, 0);
276  }
277 
278  Bparticle* partlist = particles_from_peaks(pc, bin, excl_dist,
279  part_ori, fomcut, 1e30, 1000000, 2, excl_dist);
280 
281  delete pc;
282 
283  return partlist;
284 }
285 
286 Bparticle* particles_pick_var(Bimage* p, long avg_kernel, long var_kernel,
287  double cutmin, double cutmax, double part_ori, double excl_dist, long bin)
288 {
289  if ( !p ) return NULL;
290  if ( bin < 1 ) bin = 1;
291  if ( bin > 4 ) bin = 4;
292  if ( excl_dist < 1 ) excl_dist = 1.6*part_ori;
293 
294  if ( verbose & VERB_FULL )
295  cout << "Picking from " << p->file_name() << endl;
296 
297  avg_kernel /= bin;
298  var_kernel /= bin;
299 
300  if ( verbose & VERB_DEBUG )
301  cout << "DEBUG particles_pick_var: cutmin=" << cutmin << " cutmax=" << cutmax << endl;
302 
303  Bimage* pc = p->bin_copy(bin);
304  pc->filter_average(avg_kernel);
305  pc->variance(var_kernel);
306  pc->truncate(cutmin, cutmax, 0, 0);
307 
308  Bparticle* partlist = particles_from_peaks(pc, bin, excl_dist,
309  part_ori, cutmin, cutmax, 1000000, 2, excl_dist);
310 
311  delete pc;
312 
313  return partlist;
314 }
315 
316 
336 Bparticle* particles_pick_cc(Bstring& filename, long img_num, Bimage* ptemp,
337  Bimage* pmask, double hires, double lores, double fommin, double fommax,
338  double excl_dist, long bin)
339 {
340  Bimage* p = read_img(filename, 1, img_num);
341  if ( !p ) return NULL;
342 
343  p->sampling(ptemp->sampling(0));
344 
345  Bparticle* partlist = particles_pick_cc(p, ptemp, pmask,
346  hires, lores, fommin, fommax, excl_dist, bin);
347 
348  delete p;
349 
350  return partlist;
351 }
352 
370 Bparticle* particles_pick_var(Bstring& filename, long img_num,
371  long avg_kernel, long var_kernel, double nsig,
372  double part_ori, double excl_dist, long bin)
373 {
374  Bimage* p = read_img(filename, 1, img_num);
375  if ( !p ) return NULL;
376 
377  Bparticle* partlist = particles_pick_var(p, avg_kernel, var_kernel,
378  nsig, part_ori, excl_dist, bin);
379 
380  delete p;
381 
382  return partlist;
383 }
384 
385 double img_marker_set_difference_at_voxel(Bimage* p, long i, Bmarker* markin, Bmarker* markout)
386 {
387  long x, y, z, n;
388  double v, sumin(0), sumout(0);
389  Bmarker* mark = NULL;
390 
391  p->coordinates(i, x, y, z);
392  Vector3<float> c(x, y, z);
393 
394  for ( n=0, mark = markin; mark; mark = mark->next ) {
395  v = p->get(0, mark->loc + c, 0);
396  if ( v ) {
397  sumin += v;
398  n++;
399  }
400  }
401 
402  if ( n ) sumin /= n;
403 
404  for ( n=0, mark = markout; mark; mark = mark->next ) {
405  v = p->get(0, mark->loc + c, 0);
406  if ( v ) {
407  sumout += v;
408  n++;
409  }
410  }
411 
412  if ( n ) sumout /= n;
413 
414  return sumin - sumout;
415 }
416 
429 Bimage* img_marker_set_difference(Bimage* p, Bmarker* markin, Bmarker* markout, int contrast)
430 {
431  Bimage* pt = p->copy_header(p->images());
432  pt->data_type(Float);
433  pt->data_alloc();
434 
435 #ifdef HAVE_GCD
436  dispatch_apply(p->data_size(), dispatch_get_global_queue(0, 0), ^(size_t i){
437  pt->set(i, img_marker_set_difference_at_voxel(p, i, markin, markout));
438  });
439 #else
440 #pragma omp parallel for
441  for ( long i=0; i<p->data_size(); i++ )
442  pt->set(i, img_marker_set_difference_at_voxel(p, i, markin, markout));
443 #endif
444 
445  pt->statistics();
446 
447  double scale(1);
448  if ( contrast > 0 ) scale = 1/pt->maximum();
449  else scale = 1/pt->minimum();
450 
451  pt->rescale(scale, 0);
452 
453  return pt;
454 }
455 
473 double mg_pick_particles(Bmicrograph* mg, Bimage* p, Bmarker* markin,
474  Bmarker* markout, int avg_kernel, int contrast)
475 {
476  if ( !mg->select ) return 0;
477 
478  if ( mg->pixel_size[0] > 0 ) p->sampling(mg->pixel_size);
479  else mg->pixel_size = p->sampling(0);
480 
481  mg->origin = p->size()/2;
482 
483  p->filter_average(avg_kernel);
484 
485  Bimage* pt = img_marker_set_difference(p, markin, markout, contrast);
486 
487  if ( verbose & VERB_DEBUG )
488  write_img("map.pif", pt, 0);
489 
490 // double threshold = pt->average() + pt->standard_deviation();
491  double threshold(0);
492 
493 // if ( verbose )
494 // cout << "Threshold: " << threshold << endl;
495 
496  if ( mg->part ) {
497  particle_kill(mg->part);
498  mg->part = NULL;
499  }
500 
501  mg->part = particles_from_peaks(pt, 1, 0, mg->box_size[0]/2, threshold);
502 
503  delete pt;
504 
505  mg->fom = threshold;
506 
507  Bparticle* part = NULL;
508  for ( part = mg->part; part; part = part->next )
509  part->ori = mg->box_size/2;
510 
512 
513  return threshold;
514 }
515 
534  double hires, double lores, double fommin, double fommax, double excl_dist, long bin)
535 {
536  long npart(0);
537  double min_thresh(1);
538  Bfield* field;
539  Bmicrograph* mg;
540  Breconstruction* rec;
541 
542  if ( verbose ) {
543  cout << "Finding particles by cross-correlation:" << endl;
544  cout << "Template: " << ptemp->file_name() << endl;
545  if ( pmask )
546  cout << "Mask: " << pmask->file_name() << endl;
547  cout << "Resolution limits: " << hires << " - ";
548  if ( lores > 0 ) cout << lores << " A" << endl;
549  else cout << "inf A" << endl;
550  cout << "Thresholds: " << fommin << " - " << fommax << endl;
551  cout << "Exclusion distance: " << excl_dist << endl;
552  cout << "Binning: " << bin << endl;
553  }
554 
555  if ( project->select < 1 ) {
556  for ( field = project->field; field; field = field->next ) {
557  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
558  if ( verbose )
559  cout << "Picking from micrograph " << mg->id << flush;
560  mg->box_size = ptemp->size();
561  mg->part = particles_pick_cc(mg->fmg, mg->img_num, ptemp, pmask, hires, lores, fommin, fommax, excl_dist, bin);
562  mg->fom = ptemp->image->FOM();
563  npart = micrograph_set_part_links(mg);
564  if ( min_thresh > mg->fom ) min_thresh = mg->fom;
565  if ( verbose )
566  cout << tab << npart << endl;
567  }
568  }
570  } else {
571  for ( rec = project->rec; rec; rec = rec->next ) {
572  if ( verbose )
573  cout << "Picking from reconstruction " << rec->id << endl;
574  rec->box_size = ptemp->size();
575  rec->part = particles_pick_cc(rec->frec, 0, ptemp, pmask, hires, lores, fommin, fommax, excl_dist, bin);
576  rec->fom = ptemp->image->FOM();
577  if ( min_thresh > rec->fom ) min_thresh = rec->fom;
578  npart = reconstruction_set_part_links(rec);
579  }
581  }
582 
583  if ( verbose )
584  cout << "Number of particles: " << npart << endl << endl;
585 
586  return min_thresh;
587 }
588 
605 double project_pick_particles(Bproject* project, long avg_kernel, long var_kernel,
606  double nsig, double part_ori, double excl_dist, long bin)
607 {
608  if ( part_ori < 1 ) part_ori = excl_dist;
609 
610  long npart(0);
611  double min_thresh(1);
612  Bfield* field;
613  Bmicrograph* mg;
614  Breconstruction* rec;
615 
616  if ( verbose ) {
617  cout << "Finding particles from local variance map:" << endl;
618  cout << "Averaging kernel size: " << avg_kernel << endl;
619  cout << "Variance kernel size: " << var_kernel << endl;
620  cout << "Multiple of sigma for cutoff: " << nsig << endl;
621  cout << "Exclusion distance: " << excl_dist << endl;
622  cout << "Binning: " << bin << endl;
623  }
624 
625  if ( project->select < 1 ) {
626  for ( field = project->field; field; field = field->next ) {
627  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
628  if ( verbose )
629  cout << "Picking from micrograph " << mg->id << endl;
630  if ( mg->box_size.length() < 1 )
631  mg->box_size = Vector3<long>(2*part_ori, 2*part_ori, 1);
632  mg->part = particles_pick_var(mg->fmg, mg->img_num,
633  avg_kernel, var_kernel, nsig, part_ori, excl_dist, bin);
634  if ( min_thresh > mg->fom ) min_thresh = mg->fom;
636  }
637  }
639  } else {
640  for ( rec = project->rec; rec; rec = rec->next ) {
641  if ( verbose )
642  cout << "Picking from reconstruction " << rec->id << endl;
643  if ( rec->box_size.length() < 1 )
644  rec->box_size = Vector3<long>(2*part_ori, 2*part_ori, 2*part_ori);
645  rec->part = particles_pick_var(rec->frec, 0,
646  avg_kernel, var_kernel, nsig, part_ori, excl_dist, bin);
647  if ( min_thresh > rec->fom ) min_thresh = rec->fom;
649  }
651  }
652 
653  if ( verbose )
654  cout << "Number of particles: " << npart << endl << endl;
655 
656  return min_thresh;
657 }
658 
676 long project_pick_particles(Bproject* project, double din, double dout,
677  int avg_kernel, double ainc, int flags, int contrast)
678 {
679  if ( din < 2 ) {
680  cerr << "Error: The particle diameter must be specified!" << endl << endl;
681  return -1;
682  }
683 
684  int w = (int) (dout + 10);
685  Vector3<long> size(w, w, 1);
686 
687  Bmarker* markin = marker_set_at_radius(din/2, ainc);
688  Bmarker* markout = marker_set_at_radius(dout/2, ainc);
689 
690  Bfield* field;
691  Bmicrograph* mg;
692  Bimage* p;
693 
694  if ( verbose ) {
695  cout << "Finding particles using a circular fore/background template:" << endl;
696  cout << "Particle diameter: " << din << endl;
697  cout << "Background diameter: " << dout << endl;
698  cout << "Angular increment: " << ainc*180.0/M_PI << " degrees" << endl;
699  cout << "Averaging kernel size: " << avg_kernel << endl << endl;
700  }
701 
702  for ( field = project->field; field; field = field->next ) {
703  for ( mg = field->mg; mg; mg = mg->next ) if ( mg->select ) {
704  mg->box_size = size;
705  p = read_img(mg->fmg, 1, mg->img_num);
706  if ( p ) {
707  if ( verbose )
708  cout << "Picking from micrograph " << mg->id << endl;
709  if ( flags & 1 ) p->filter_extremes(1);
710  mg->fom = mg_pick_particles(mg, p, markin, markout, avg_kernel, contrast);
712  delete p;
713  }
714  }
715  }
716 
717  kill_list((char *) markin, sizeof(Bmarker));
718  kill_list((char *) markout, sizeof(Bmarker));
719 
720  long npart = project_count_mg_particles(project);
721 
722  if ( verbose )
723  cout << "Number of particles: " << npart << endl << endl;
724 
725  return npart;
726 }
727 
728 
729 int part_mask_particles(Bparticle* part, Bimage* pmask, long box_size)
730 {
731  if ( verbose ) {
732  cout << "Masking the existing particles:" << endl;
733  cout << "Box size: " << box_size << endl;
734  }
735 
736  for ( ; part; part = part->next )
737  pmask->sphere(part->loc, box_size, 0, FILL_USER, 0);
738 
739  return 0;
740 }
741 
742 int img_mask_above_threshold(Bimage* pvar, Bimage* p, double threshold)
743 {
744  if ( verbose ) {
745  cout << "Masking the variance map:" << endl;
746  cout << "Threshold: " << threshold << endl;
747  }
748 
749  for ( long i=0; i<p->data_size(); i++ ) if ( (*p)[i] > threshold ) pvar->set(i, 0);
750 
751  return 0;
752 }
753 
754 double mg_pick_background(Bmicrograph* mg, Bimage* p, long number,
755  long avg_kernel, long var_kernel, double excl_dist)
756 {
757  if ( !mg->select ) return 0;
758 
759  p->filter_average(avg_kernel);
760 
761  if ( verbose )
762  cout << "Filtered min, max, avg & std: " << p->minimum() << " " <<
763  p->maximum() << " " << p->average() << " " << p->standard_deviation() << endl;
764 
765  Bimage* pvar = p->copy();
766 
767  pvar->variance(var_kernel);
768 
769  pvar->rescale(-1/pvar->standard_deviation(), pvar->average()/pvar->standard_deviation());
770 
771  if ( verbose )
772  cout << "Variance min, max, avg & std: " << pvar->minimum() << " " <<
773  pvar->maximum() << " " << pvar->average() << " " << pvar->standard_deviation() << endl;
774 
775  part_mask_particles(mg->part, pvar, mg->box_size[0]);
776 
778 
779 // write_img("vt.pif", pvar);
780 
781  double threshold(0);
782 
783  if ( mg->part ) {
784  particle_kill(mg->part);
785  mg->part = NULL;
786  }
787 
788  mg->part = particles_from_peaks(pvar, 1, excl_dist, mg->box_size[0]/2, threshold, 1e30, number);
789 
790  delete pvar;
791 
793 
794  return threshold;
795 }
796 
797 double rec_pick_background(Breconstruction* rec, Bimage* p, long number,
798  long avg_kernel, long var_kernel, double excl_dist)
799 {
800  p->filter_average(avg_kernel);
801 
802  if ( verbose )
803  cout << "Filtered min, max, avg & std: " << p->minimum() << " " <<
804  p->maximum() << " " << p->average() << " " << p->standard_deviation() << endl;
805 
806  Bimage* pvar = p->copy();
807 
808  pvar->variance(var_kernel);
809 
810  pvar->rescale(-1/pvar->standard_deviation(), pvar->average()/pvar->standard_deviation());
811 
812  if ( verbose )
813  cout << "Variance min, max, avg & std: " << pvar->minimum() << " " <<
814  pvar->maximum() << " " << pvar->average() << " " << pvar->standard_deviation() << endl;
815 
816  part_mask_particles(rec->part, pvar, rec->box_size[0]);
817 
819 
820 // write_img("vt.pif", pvar);
821 
822  double threshold(0);
823 
824  if ( rec->part ) {
825  particle_kill(rec->part);
826  rec->part = NULL;
827  }
828 
829  rec->part = particles_from_peaks(pvar, 1, excl_dist, rec->box_size[0]/2, threshold, 1e30, number);
830 
831  delete pvar;
832 
834 
835  return threshold;
836 }
837 
849  long avg_kernel, long var_kernel, double excl_dist)
850 {
851  Bfield* field;
852  Bmicrograph* mg;
853  Breconstruction* rec;
854  Bimage* p;
855  long npart(0);
856 
857  if ( verbose ) {
858  cout << "Finding background areas:" << endl;
859  cout << "Maximum number: " << number << endl;
860  cout << "Averaging kernel size: " << avg_kernel << endl;
861  cout << "Variance kernel size: " << var_kernel << endl;
862  cout << "Exclusion distance: " << excl_dist << endl << endl;
863  }
864 
865  if ( project->select < 1 ) {
866  for ( field = project->field; field; field = field->next ) {
867  for ( mg = field->mg; mg; mg = mg->next ) if ( !mg->select ) {
868  p = read_img(mg->fmg, 1, mg->img_num);
869  if ( p ) {
870  if ( verbose )
871  cout << "Picking from micrograph " << mg->id << endl;
872  mg->origin = p->size()/2;
873  mg->fom = mg_pick_background(mg, p, number, avg_kernel, var_kernel, excl_dist);
874  delete p;
875  }
876  }
877  }
879  } else {
880  for ( rec = project->rec; rec; rec = rec->next ) {
881  p = read_img(rec->frec, 1, 0);
882  if ( p) {
883  if ( verbose )
884  cout << "Picking from reconstruction " << rec->id << endl;
885  rec->origin = p->size()/2;
886  rec->fom = rec_pick_background(rec, p, number, avg_kernel, var_kernel, excl_dist);
887  delete p;
888  }
889  }
891  }
892 
893  if ( verbose )
894  cout << "Background areas picked: " << npart << endl << endl;
895 
896  return npart;
897 }
898 
899 Bparticle* part_pick_sym_axis(Bparticle* part, Bsymmetry* sym, View& refview, Vector3<double> refori, double axis_dist)
900 {
901  long j, g, s;
902  Bparticle* nupart_list = NULL;
903  Bparticle* nupart = NULL;
904  View vr;
905  View* views, *v;
906  Quaternion qr, qp;
907  Vector3<double> tr;
908 
909  qr = refview.quaternion();
910 
911  for ( j=0, g=1; part; part = part->next, ++g ) {
912  tr = part->ori - refori + part->loc;
913  views = symmetry_get_all_views(sym, part->view);
914  for ( s=1, v = views; v; v = v->next, ++s ) {
915  qp = v->quaternion();
916  vr = View(qr*qp);
917  nupart = particle_add(&nupart, ++j);
918  if ( !nupart_list ) nupart_list = nupart;
919  nupart->group = g;
920  nupart->sel = s;
921  nupart->view = vr;
922  nupart->loc = tr + vr.backward().vector3() * axis_dist;
923  if ( part->loc[2] < 1 ) nupart->loc[2] = 0; // for micrographs
924  if ( verbose & VERB_FULL )
925  cout << j << tab << nupart->view << endl;
926  }
927  kill_list((char *) views, sizeof(View));
928  }
929 
930  return nupart_list;
931 }
932 
944 long project_pick_sym_axis(Bproject* project, Bsymmetry* sym, int sym_axis, double axis_dist)
945 {
946  long n(0);
947  Bfield* field;
948  Bmicrograph* mg;
949  Breconstruction* rec;
950  Bparticle* part;
951  View refview;
952  Vector3<double> refori;
953 
954  if ( sym_axis == 2 ) {
955  if ( sym->point > 200 && sym->point < 300 ) { // Dihedral
956  refview = View(1, 0, 0, 0);
957  } else if ( sym->point == 432 ) { // Octahedral
958  refview = View(1, -1, 0, 0);
959  }
960  } else if ( sym_axis == 3 && sym->point > 300 ) { // Tetra-, Octa-, Icosahedral
961  refview = View(1, 1, 1, 0);
962  } else if ( sym_axis == 5 && sym->point == 532 ) { // Icosahedral
963  refview = View(0, 1.0L/GOLDEN, 1, 0);
964  }
965 
966  if ( verbose ) {
967  cout << "Picking subregions based on symmetry " << sym->label << ":" << endl;
968  cout << "Symmetry axis: " << refview << " (" << sym_axis << ")" << endl;
969  cout << "Distance along axis: " << axis_dist << endl;
970  if ( project->select )
971  cout << "Box size: " << project->rec->box_size << endl;
972  else
973  cout << "Box size: " << project->field->mg->box_size << endl;
974  }
975 
976  if ( project->select ) {
977  for ( rec = project->rec; rec; rec = rec->next ) {
978  refori = rec->box_size/2;
979  part = part_pick_sym_axis(rec->part, sym, refview, refori, axis_dist);
980  particle_kill(rec->part);
981  rec->part = part;
982  }
984  } else {
985  for ( field = project->field; field; field = field->next ) {
986  for ( mg = field->mg; mg; mg = mg->next ) {
987  refori = mg->box_size/2;
988  part = part_pick_sym_axis(mg->part, sym, refview, refori, axis_dist);
989  particle_kill(mg->part);
990  mg->part = part;
991  }
992  }
994  }
995 
996  if ( verbose )
997  cout << "Number of new particles: " << n << endl << endl;
998 
999  return n;
1000 }
1001 
1002 Bimage* img_prepare_projections(Bstring& tempfile, Bsymmetry* sym, double hires, long bin)
1003 {
1004  if ( tempfile.length() < 1 ) return NULL;
1005 
1006  Bimage* ptemp = read_img(tempfile, 1, 0);
1007  if ( !ptemp ) {
1008  cerr << "Error: The template/reference file was not read!" << endl;
1009  bexit(-1);
1010  }
1011 
1012  ptemp->check_resolution(hires);
1013 
1014  double angle(hires/ptemp->real_size()[0]);
1015  View* views = NULL;
1016  Bimage* proj = NULL;
1017  FSI_Kernel* kernel = NULL;
1018 
1019  if ( ptemp->sizeZ() > 1 ) {
1020  if ( verbose ) {
1021  cout << "Calculating projections:" << endl;
1022  cout << "Symmetry: " << sym->label << endl;
1023  cout << "Angle step size: " << angle*180.0/M_PI << endl;
1024  }
1025  kernel = new FSI_Kernel(8, 2);
1026  views = asymmetric_unit_views(sym, angle, angle, angle, 1);
1027  proj = ptemp->project(views, hires, kernel);
1028  delete ptemp;
1029  ptemp = proj;
1030  if ( views ) kill_list((char *) views, sizeof(View));
1031  if ( kernel ) delete kernel;
1032  if ( verbose )
1033  cout << "Number of projections: " << ptemp->images() << endl;
1034  }
1035 
1036  if ( verbose & VERB_DEBUG )
1037  cout << "DEBUG img_prepare_projections: Calculating the background" << endl;
1038  ptemp->calculate_background();
1039 
1040  if ( verbose & VERB_DEBUG )
1041  cout << "DEBUG img_prepare_projections: Smoothing the edge" << endl;
1042  ptemp->edge(1, ptemp->size(), Vector3<double>(0,0,0), 2, FILL_BACKGROUND);
1043 
1044  if ( verbose & VERB_DEBUG )
1045  cout << "DEBUG img_prepare_projections: Doubling the size" << endl;
1046  double scale(1.5);
1047  Vector3<long> nusize((long)(scale*ptemp->sizeX()), (long)(scale*ptemp->sizeY()), 1);
1048  Vector3<long> translate((nusize-ptemp->size())/2);
1049  ptemp->resize(nusize, translate, FILL_BACKGROUND);
1050 
1051  if ( bin > 1 ) ptemp->bin(bin);
1052 
1053  if ( verbose & VERB_DEBUG )
1054  write_img("temp.pif", ptemp, 0);
1055 
1056  return ptemp;
1057 }
1058 
1059 Bimage* img_prepare_orientations(Bstring& tempfile, Bsymmetry* sym, double hires, long bin)
1060 {
1061  if ( tempfile.length() < 1 ) return NULL;
1062 
1063  Bimage* ptemp = read_img(tempfile, 1, 0);
1064  if ( !ptemp ) {
1065  cerr << "Error: The template/reference file was not read!" << endl;
1066  bexit(-1);
1067  }
1068 
1069  if ( ptemp->sizeZ() < 2 ) {
1070  cerr << "Error: The template must be a 3D volume!" << endl;
1071  return NULL;
1072  }
1073 
1074  ptemp->check_resolution(hires);
1075 
1076  double angle(hires/ptemp->real_size()[0]);
1077 
1078  if ( verbose ) {
1079  cout << "Calculating orientations:" << endl;
1080  cout << "Symmetry: " << sym->label << endl;
1081  cout << "Angle step size: " << angle*180.0/M_PI << endl;
1082  }
1083 
1084  View* views = asymmetric_unit_views(sym, angle, angle, angle, 1);
1085 
1086  Bimage* pmt = ptemp->orient(views);
1087  delete ptemp;
1088 
1089  ptemp = pmt;
1090 
1091  if ( views ) kill_list((char *) views, sizeof(View));
1092 
1093  if ( verbose )
1094  cout << "Number of orientations: " << ptemp->images() << endl;
1095 
1096  if ( verbose & VERB_DEBUG )
1097  cout << "DEBUG img_prepare_orientations: Calculating the background" << endl;
1098  ptemp->calculate_background();
1099 
1100  if ( verbose & VERB_DEBUG )
1101  cout << "DEBUG img_prepare_orientations: Smoothing the edge" << endl;
1102  ptemp->edge(1, ptemp->size(), Vector3<double>(0,0,0), 2, FILL_BACKGROUND);
1103 
1104  if ( verbose & VERB_DEBUG )
1105  cout << "DEBUG img_prepare_orientations: Doubling the size" << endl;
1106  double scale(1.5);
1107  Vector3<long> nusize((long)(scale*ptemp->sizeX()), (long)(scale*ptemp->sizeY()), (long)(scale*ptemp->sizeZ()));
1108  Vector3<long> translate((nusize-ptemp->size())/2);
1109  ptemp->resize(nusize, translate, FILL_BACKGROUND);
1110 
1111  if ( bin > 1 ) ptemp->bin(bin);
1112 
1113  if ( verbose & VERB_DEBUG )
1114  write_img("temp.pif", ptemp, 0);
1115 
1116  return ptemp;
1117 }
1118 
1119 
1120 double part_align(Bparticle* part, Bimage* p, Bimage* ptemp,
1121  double hires, double lores, double shift_limit, long bin,
1123 {
1124  long nn;
1125  Vector3<double> shift;
1126 
1127  part->fom[0] = 0;
1128 
1129  if ( bin > 1 ) p->bin(bin);
1130 
1131  if ( verbose & VERB_DEBUG )
1132  cout << "DEBUG part_align: Transforming" << endl;
1133  p->fft(planf, 0);
1134 
1135  if ( verbose & VERB_DEBUG )
1136  cout << "DEBUG part_align: Band-pass filtering" << endl;
1137  p->complex_bandpass(hires, lores);
1138 
1139  if ( verbose & VERB_DEBUG )
1140  cout << "DEBUG part_align: Normalizing" << endl;
1141  p->complex_normalize();
1142 
1143  if ( verbose & VERB_DEBUG )
1144  cout << "DEBUG part_align: Calculating the complex conjugate product" << endl;
1145  Bimage* pcc = p->complex_conjugate_product_one2many(ptemp);
1146  if ( !pcc ) cerr << "Complex conjugate product failed!" << endl;
1147 
1148  if ( verbose & VERB_DEBUG )
1149  cout << "DEBUG part_align: Back-transforming" << endl;
1150  pcc->origin(shift);
1151  pcc->fft_back(planb, 0);
1152 
1153  if ( verbose & VERB_DEBUG )
1154  cout << "DEBUG part_align: Finding peaks" << endl;
1155  pcc->find_peak(shift_limit);
1156  pcc->refine_peak();
1157 
1158  for ( nn=0; nn<pcc->images(); nn++ ) {
1159 // cout << nn << tab << pcc->image[nn].origin() * bin << tab << ptemp->image[nn].view() << tab << pcc->image[nn].FOM() << endl;
1160  if ( part->fom[0] < pcc->image[nn].FOM() ) {
1161  part->fom[0] = pcc->image[nn].FOM();
1162  part->view = ptemp->image[nn].view();
1163  shift = pcc->image[nn].origin();
1164  }
1165  }
1166 
1167  delete pcc;
1168 
1169  shift *= bin;
1170 
1171  if ( verbose )
1172  cout << right << setprecision(2) << part->id << tab << shift
1173  << setprecision(4) << tab << part->view << tab
1174  << setprecision(6) << part->fom[0] << endl;
1175 
1176 // cout << "box size = " << part->mg->box_size << endl;
1177 
1178  part->loc += shift;
1179  if ( part->mg ) part->ori = part->mg->box_size/2;
1180  else if ( part->rec ) part->ori = part->rec->box_size/2;
1181 
1182  return part->fom[0];
1183 }
1184 
1185 
1207  double hires, double lores, long bin, fft_plan planf, fft_plan planb)
1208 {
1209 
1210  if ( verbose )
1211  cout << "Micrograph " << mg->id << " (" << mg->img_num << ")" << endl;
1212 
1213  Vector3<long> extsize(ptemp->size()*bin);
1214  Vector3<double> start, origin(extsize/2);
1215  Bparticle* part;
1216  Bimage* pex = NULL;
1217 
1218  long npart(particle_count(mg->part));
1219  if ( npart < 1 ) return 0;
1220 
1221  Bimage* p = read_img(mg->fmg, 1, mg->img_num);
1222 
1223  if ( verbose & VERB_PROCESS )
1224  cout << "Finding particles from image " << p->file_name() << endl;
1225 
1226  double shift_limit(ptemp->sizeX()/4);
1227 
1228  if ( verbose )
1229  cout << "ID\tdx\tdy\tdz\tvx\tvy\tvz\tva\tFOM" << endl;
1230  for ( part = mg->part; part; part = part->next ) {
1231  if ( verbose & VERB_DEBUG )
1232  cout << "DEBUG mg_extract_orient_particles: Extracting particle" << endl;
1233  start = part->loc - origin;
1234  start = start.max(0);
1235  start = start.min(p->size() - extsize);
1236  pex = p->extract(0, start, extsize);
1237  part_align(part, pex, ptemp, hires, lores, shift_limit, bin, planf, planb);
1238  delete pex;
1239  }
1240 
1241  delete p;
1242 
1243  return npart;
1244 }
1245 
1247  double hires, double lores, long bin, fft_plan planf, fft_plan planb)
1248 {
1249 
1250  if ( verbose )
1251  cout << "Reconstruction " << rec->id << endl;
1252 
1253  Vector3<long> extsize(ptemp->size()*bin);
1254  Vector3<double> start, origin(extsize/2);
1255  Bparticle* part;
1256  Bimage* pex = NULL;
1257 
1258  long npart(particle_count(rec->part));
1259  if ( npart < 1 ) return 0;
1260 
1261  Bimage* p = read_img(rec->frec, 1, 0);
1262 
1263  if ( verbose & VERB_PROCESS )
1264  cout << "Finding particles from image " << p->file_name() << endl;
1265 
1266  double shift_limit(ptemp->sizeX()/4);
1267 
1268  if ( verbose )
1269  cout << "ID\tdx\tdy\tdz\tvx\tvy\tvz\tva\tFOM" << endl;
1270  for ( part = rec->part; part; part = part->next ) {
1271  if ( verbose & VERB_DEBUG )
1272  cout << "DEBUG mg_extract_orient_particles: Extracting particle" << endl;
1273  start = part->loc - origin;
1274  start = start.max(0);
1275  start = start.min(p->size() - extsize);
1276  pex = p->extract(0, start, extsize);
1277  part_align(part, pex, ptemp, hires, lores, shift_limit, bin, planf, planb);
1278  delete pex;
1279  }
1280 
1281  delete p;
1282 
1283  return npart;
1284 }
1285 
1286 
1302  Bsymmetry* sym, double hires, double lores, long bin)
1303 {
1304  Bfield* field;
1305  Bmicrograph* mg;
1306  Breconstruction* rec;
1307  Bimage* ptemp = NULL;
1308 
1309  if ( project->select < 1 )
1310  ptemp = img_prepare_projections(tempfile, sym, hires, bin);
1311  else
1312  ptemp = img_prepare_orientations(tempfile, sym, hires, bin);
1313 
1314  if ( verbose ) {
1315  cout << "Extracting and orienting particles in micrographs:" << endl;
1316  cout << "Template: " << ptemp->file_name() << endl;
1317  cout << "Template images: " << ptemp->images() << endl;
1318  cout << "Template size: " << ptemp->size() << endl;
1319 // if ( pmask )
1320 // cout << "Mask: " << pmask->file_name() << endl;
1321  cout << "Resolution limits: " << hires << " - ";
1322  if ( lores > 0 ) cout << lores << " A" << endl;
1323  else cout << "inf A" << endl;
1324 // cout << "Threshold: " << fomcut << endl;
1325 // cout << "Exclusion distance: " << excl_dist << endl;
1326  cout << "Binning: " << bin << endl;
1327  }
1328 
1329  if ( verbose & VERB_PROCESS )
1330  cout << "Setting up FFT plans" << endl;
1331 
1332  fft_plan planf = ptemp->fft_setup(FFTW_FORWARD, 1);
1333  fft_plan planb = ptemp->fft_setup(FFTW_BACKWARD, 1);
1334 
1335  if ( verbose & VERB_PROCESS )
1336  cout << "Transforming template" << endl;
1337 
1338  ptemp->fft(planf, 0);
1339 
1340  if ( verbose & VERB_PROCESS )
1341  cout << "Band-pass filtering template" << endl;
1342 
1343  ptemp->complex_bandpass(hires, lores);
1344 
1345  if ( verbose & VERB_PROCESS )
1346  cout << "Normalizing template" << endl;
1347 
1348  ptemp->complex_normalize();
1349 
1350  if ( project->select < 1 ) {
1351  for ( field = project->field; field; field = field->next ) {
1352  for ( mg = field->mg; mg; mg = mg->next ) {
1353  mg_extract_orient_particles(mg, ptemp, hires, lores, bin, planf, planb);
1354  }
1355  }
1356  } else {
1357  for ( rec = project->rec; rec; rec = rec->next ) {
1358  rec_extract_orient_particles(rec, ptemp, hires, lores, bin, planf, planb);
1359  }
1360  }
1361 
1364 
1365  return 0;
1366 }
1367 
Bimage::coordinates
void coordinates(long i, long &nx, long &ny, long &nz)
Definition: Bimage.h:429
micrograph_set_part_links
long micrograph_set_part_links(Bmicrograph *mg)
Sets the links from particles back to the micrograph.
Definition: mg_processing.cpp:1170
Bimage::fft_setup
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
Definition: Bimage_fft.cpp:29
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
Bimage::rescale
int rescale(double scale, double shift)
Rescales the image data with a given multiplier and offset.
Definition: Bimage_rescale.cpp:27
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Breconstruction::id
Bstring id
Definition: mg_processing.h:285
Bimage::mask_erode
long mask_erode(long times=1)
Erodes a binary mask.
Definition: Bimage_mask.cpp:443
View::next
View * next
Definition: View.h:28
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:500
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Bimage::filter_gaussian
int filter_gaussian(long kernel_size, double sigma)
Applies a gaussian filter to an image.
Definition: Bimage_filter.cpp:324
Bimage::histogram_gauss_fit
vector< double > histogram_gauss_fit(long bins, long ngauss=1)
Fits a gaussian function to a histogram of an image.
Definition: Bimage_histogram.cpp:590
img_prepare_for_picking
Bimage * img_prepare_for_picking(Bimage *p, int flags, long sigma, long bin)
Definition: mg_pick.cpp:19
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
symmetry_get_all_views
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
Definition: symmetry.cpp:442
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bimage::find_peaks
Bimage * find_peaks(long kernelsize)
Finds peaks in a map with periodic boundaries.
Definition: Bimage_correlate.cpp:1739
Bimage::get
double get(long nn, long xx, long yy, long zz, long cc=0)
Returns the data value at the given coordinates.
Definition: Bimage.cpp:960
Bsymmetry::point
int point
Definition: symmetry.h:39
Bproject::select
int select
Definition: mg_processing.h:342
Quaternion
Definition: Quaternion.h:25
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Bparticle::view
View view
Definition: mg_processing.h:102
rec_pick_background
double rec_pick_background(Breconstruction *rec, Bimage *p, long number, long avg_kernel, long var_kernel, double excl_dist)
Definition: mg_pick.cpp:797
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1118
Bstring
Definition: Bstring.h:29
Bparticle
Definition: mg_processing.h:90
Bproject::field
Bfield * field
Definition: mg_processing.h:346
Bimage::find_template
Bimage * find_template(Bimage *ptemp, Bimage *pmask, double hires, double lores, int bin, fft_plan planf, fft_plan planb)
Finds one or more matches to a template.
Definition: Bimage_correlate.cpp:1177
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2702
img_marker_set_difference_at_voxel
double img_marker_set_difference_at_voxel(Bimage *p, long i, Bmarker *markin, Bmarker *markout)
Definition: mg_pick.cpp:385
Breconstruction::fom
double fom
Definition: mg_processing.h:305
Bimage::variance
int variance(long kernel_size, int flag=0)
Calculates the local variance within the given kernel.
Definition: Bimage_stats.cpp:625
Vector3< double >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::find_peak
int find_peak(double radius=1e30, double sigma=0)
Finds the peak in an image to the nearest voxel.
Definition: Bimage_correlate.cpp:1340
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
reconstruction_set_part_links
long reconstruction_set_part_links(Breconstruction *rec)
Sets the links from particles back to the reconstruction.
Definition: mg_processing.cpp:1185
GOLDEN
#define GOLDEN
Definition: utilities.h:85
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
mg_select.h
Header file for micrograph processing.
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
img_prepare_orientations
Bimage * img_prepare_orientations(Bstring &tempfile, Bsymmetry *sym, double hires, long bin)
Definition: mg_pick.cpp:1059
FILL_USER
#define FILL_USER
Definition: utilities.h:176
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
mg_pick.h
Header file for single particle picking functions.
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:105
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:299
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
project_extract_orient_particles
double project_extract_orient_particles(Bproject *project, Bstring &tempfile, Bsymmetry *sym, double hires, double lores, long bin)
Picks particles using cross-correlation.
Definition: mg_pick.cpp:1301
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
asymmetric_unit_views
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
Definition: symmetry.cpp:564
Bimage::fft_back
int fft_back()
Definition: Bimage.h:831
View
Definition: View.h:26
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
mg_pick_particles
double mg_pick_particles(Bmicrograph *mg, Bimage *p, Bmarker *markin, Bmarker *markout, int avg_kernel, int contrast)
Locates particles using a fore/background difference measure.
Definition: mg_pick.cpp:473
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
Bsymmetry
Definition: symmetry.h:38
Bimage::maximum
double maximum()
Definition: Bimage.h:542
part_mask_particles
int part_mask_particles(Bparticle *part, Bimage *pmask, long box_size)
Definition: mg_pick.cpp:729
mg_pick_background
double mg_pick_background(Bmicrograph *mg, Bimage *p, long number, long avg_kernel, long var_kernel, double excl_dist)
Definition: mg_pick.cpp:754
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:544
project_pick_particles
double project_pick_particles(Bproject *project, Bimage *ptemp, Bimage *pmask, double hires, double lores, double fommin, double fommax, double excl_dist, long bin)
Picks particles using cross-correlation.
Definition: mg_pick.cpp:533
Bimage::refine_peak
int refine_peak()
Refines the position of a peak to sub-voxel resolution.
Definition: Bimage_correlate.cpp:1615
planf
fft_plan planf
Definition: bico.cpp:24
Bmarker
Definition: marker.h:21
Bimage::complex_conjugate_product_one2many
Bimage * complex_conjugate_product_one2many(Bimage *p)
Calculates the product of a complex image with the conjugate of a second.
Definition: Bimage_complex.cpp:490
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:296
Bimage::images
long images()
Definition: Bimage.h:504
project
Bproject * project
Definition: bshow.cpp:33
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::project
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
Definition: Bimage_project.cpp:31
View::backward
View backward()
Definition: View.h:118
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bimage::orient
Bimage * orient(View *views)
Calculates multiple copies oriented according to views.
Definition: Bimage_transform.cpp:529
Bimage::quadric_correct
int quadric_correct(vector< double > param)
Corrects for a quadric surface.
Definition: Bimage_rescale.cpp:826
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
Bimage::fft
int fft()
Definition: Bimage.h:830
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
Bimage::bin_copy
Bimage * bin_copy(long b)
Definition: Bimage.h:1298
Bimage::mask_by_threshold
Bimage * mask_by_threshold(double threshold)
Generates a mask based on an image at a given threshold.
Definition: Bimage_mask.cpp:93
Bimage::data_size
long data_size()
Definition: Bimage.h:270
part_align
double part_align(Bparticle *part, Bimage *p, Bimage *ptemp, double hires, double lores, double shift_limit, long bin, fft_plan planf, fft_plan planb)
Definition: mg_pick.cpp:1120
marker_set_at_radius
Bmarker * marker_set_at_radius(double rad, double ainc)
Generates a marker set at a given radius with z=0.
Definition: marker.cpp:1258
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1371
Bproject
Definition: mg_processing.h:336
Bimage::data_alloc
unsigned char * data_alloc()
Definition: Bimage.h:271
rec_extract_orient_particles
long rec_extract_orient_particles(Breconstruction *rec, Bimage *ptemp, double hires, double lores, long bin, fft_plan planf, fft_plan planb)
Definition: mg_pick.cpp:1246
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bimage::quadric_fit
vector< double > quadric_fit()
Fits the whole image to a quadric surface.
Definition: Bimage_rescale.cpp:862
part_pick_sym_axis
Bparticle * part_pick_sym_axis(Bparticle *part, Bsymmetry *sym, View &refview, Vector3< double > refori, double axis_dist)
Definition: mg_pick.cpp:899
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
particles_pick_cc
Bparticle * particles_pick_cc(Bimage *p, Bimage *ptemp, Bimage *pmask, double hires, double lores, double fommin, double fommax, double excl_dist, long bin)
Picks particles using cross-correlation.
Definition: mg_pick.cpp:141
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
mg_extract_orient_particles
long mg_extract_orient_particles(Bmicrograph *mg, Bimage *ptemp, double hires, double lores, long bin, fft_plan planf, fft_plan planb)
Finds the centers of picked particles within a micrograph.
Definition: mg_pick.cpp:1206
Bimage::check_resolution
void check_resolution(double &resolution)
Checks that the resolution falls within reasonable limits.
Definition: Bimage.cpp:635
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
View::vector3
Vector3< double > vector3()
Definition: View.h:129
Bimage::complex_normalize
double complex_normalize()
Normalizes the power in a complex image.
Definition: Bimage_complex.cpp:225
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
particles_pick_var
Bparticle * particles_pick_var(Bimage *p, long avg_kernel, long var_kernel, double nsig, double part_ori, double excl_dist, long bin)
Picks particles in variance map.
Definition: mg_pick.cpp:220
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
img_marker_set_difference
Bimage * img_marker_set_difference(Bimage *p, Bmarker *markin, Bmarker *markout, int contrast)
Calculates the average difference between voxels tagged by two marker sets.
Definition: mg_pick.cpp:429
project_pick_sym_axis
long project_pick_sym_axis(Bproject *project, Bsymmetry *sym, int sym_axis, double axis_dist)
Picks subregions in 3D particles on the given symmetry axis.
Definition: mg_pick.cpp:944
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Bmicrograph::fom
double fom
Definition: mg_processing.h:239
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:221
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bimage::copy_header
Bimage * copy_header()
Definition: Bimage.h:658
img_prepare_projections
Bimage * img_prepare_projections(Bstring &tempfile, Bsymmetry *sym, double hires, long bin)
Definition: mg_pick.cpp:1002
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
Bparticle::group
int group
Definition: mg_processing.h:94
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
fft_plan
fftwf_plan fft_plan
Definition: fft.h:20
View::quaternion
Quaternion quaternion()
Definition: View.h:130
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
linked_list.h
Header file for generalized linked list functions.
Bmicrograph::select
long select
Definition: mg_processing.h:204
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Vector3::min
Type min()
Definition: Vector3.h:169
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
Bimage::minimum
double minimum()
Definition: Bimage.h:541
planb
fft_plan planb
Definition: bico.cpp:24
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
particles_from_peaks
Bparticle * particles_from_peaks(Bimage *pcc, long bin, double excl_dist, double part_ori, double &fommin, double fommax, long maxnum, double pix_min, double pix_max)
Finds the peaks in a cross-correlation map corresponding to particles.
Definition: mg_pick.cpp:75
Bsymmetry::label
Bstring label
Definition: symmetry.h:41
particle_kill
int particle_kill(Bparticle *part)
Frees a list of particles.
Definition: mg_processing.cpp:528
gauss_find_intersection
double gauss_find_intersection(long ngauss, vector< double > &gauss)
Definition: mg_pick.cpp:180
Vector3::length
double length()
Definition: Vector3.h:222
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:321
particle_count
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_select.cpp:755
verbose
int verbose
Float
@ Float
Definition: utilities.h:161
Bimage::complex_bandpass
int complex_bandpass(double hires, double lores)
Bandpasses a Fourier transform.
Definition: Bimage_complex.cpp:615
project_pick_background
long project_pick_background(Bproject *project, long number, long avg_kernel, long var_kernel, double excl_dist)
Picks background areas not overlapping existing particles.
Definition: mg_pick.cpp:848
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bparticle::rec
Breconstruction * rec
Definition: mg_processing.h:106
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bparticle::id
int id
Definition: mg_processing.h:93
kernel
Definition: kernlut.h:14
img_mask_above_threshold
int img_mask_above_threshold(Bimage *pvar, Bimage *p, double threshold)
Definition: mg_pick.cpp:742
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bimage::filter_extremes
int filter_extremes()
Filters the extremes out of a micrograph image.
Definition: Bimage_segment.cpp:620
Bimage::resize
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
Definition: Bimage_resize.cpp:28
FSI_Kernel
Definition: FSI_Kernel.h:14
Bimage::sphere
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
Definition: Bimage_edit.cpp:440
project_count_rec_particles
long project_count_rec_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_select.cpp:506
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
Vector3::max
Type max()
Definition: Vector3.h:175