| Bsoft 2.0.5 Bernard's software package

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