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