| Bsoft 2.0.5 Bernard's software package

mg_img_proc.cpp
Go to the documentation of this file.
1
9 #include "mg_processing.h"
10 #include "mg_ctf.h"
11 #include "qsort_functions.h"
12 #include "rwimg.h"
13 #include "linked_list.h"
14 #include "math_util.h"
15 #include "random_numbers.h"
16 #include "utilities.h"
17
18 // Declaration of global variables
19 extern int verbose; // Level of output to the screen
20
36 Bstring image_type(Bstring type)
37 {
38 type = type.lower();
39
40 if ( type.contains("micro") ) type = "mg";
41 else if ( type.contains("frame") ) type = "frame";
42 else if ( type.contains("rec") ) type = "rec";
43 else if ( type.contains("part") ) type = "part";
44 else if ( type.contains("fil") ) type = "fil";
45 else if ( type.contains("power") ) type = "ps";
46 else if ( type.contains("trans") ) type = "ft";
47
48 return type;
49 }
50
67 Bproject* project_create_from_image(Bimage* p, Bstring type)
68 {
69 long j, k, pid, nid, flen, finc(1);
70 double pixel_size(p->sampling()[0]);
71 Bproject* project = project_init();
72 Bfield* field = NULL;
73 Bmicrograph* mg = NULL;
74 Breconstruction* rec = NULL;
75 Bframe* frame = NULL;
76 Bparticle* part = NULL;
77 Bparticle** partlist = NULL;
78 Bfilament* fil = NULL;
79 Bfilament** fillist = NULL;
80 Bfilnode* fnode = NULL;
81 Vector3<double> start, fildir;
82 Bstring id, base(p->file_name());
83 base = base.alnum();
84
85 type = image_type(type);
86
87 if ( type.length() < 1 ) {
88 if ( p->images() == 1 ) {
89 if ( p->sizeZ() > 1 ) {
90 type = "rec"; // Assume reconstructions
91 project->select = 1;
92 } else type = "mg"; // Assume micrographs
93 } else {
94 if ( p->sizeX() != p->sizeY() ) type = "fil"; // Assume filaments
95 else type = "part"; // Assume particles
96 if ( p->sizeZ() > 1 ) project->select = 1;
97 }
98 }
99
100 if ( project->select < 1 ) {
101 if ( type == "frame" ) if ( p->sizeZ() > 1 ) p->slices_to_images();
102 field = field_add(&project->field, base);
103 if ( verbose & VERB_FULL )
104 cout << "Creating field \"" << field->id << endl;
105 k = 1;
106 if ( type == "mg" ) k = p->images();
107 for ( j=0; j<k; j++ ) {
108 id = base;
109 if ( k > 1 ) id += Bstring(j+1, "_%03d");
110 mg = micrograph_add(&field->mg, id);
111 if ( verbose & VERB_FULL )
112 cout << "Micrograph \"" << mg->id << endl;
113 if ( type == "mg" ) mg->fmg = p->file_name();
114 else if ( type == "frame" ) mg->fframe = p->file_name();
115 mg->img_num = j;
116 mg->block = j;
117 mg->pixel_size = pixel_size;
118 if ( type == "mg" ) mg->origin = p->image[j].origin();
119 mg->matrix = p->image[j].view().matrix();
120 mg->select = 1;
121 }
122 if ( type == "frame" ) {
123 mg->origin = p->size()/2;
124 for ( j=0; j<k; j++ ) {
125 frame = frame_add(&mg->frame, j+1);
126 frame->shift = p->image[j].origin() - mg->origin;
127 }
128 }
129 mg = field_find_zero_tilt_mg(field);
130 field->origin = mg->origin;
131 if ( type == "part" ) {
132 mg->fpart = p->file_name();
133 partlist = &mg->part;
134 pid = 0;
135 if ( verbose & VERB_FULL )
136 cout << " with " << p->images() << " particles";
137 } else if ( type == "fil" ) {
138 mg->ffil = p->file_name();
139 fillist = &mg->fil;
140 fildir = Vector3<double>(1,0,0);
141 start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, 0);
142 mg->filament_width = p->sizeY();
143 if ( p->sizeX() < p->sizeY() ) {
144 mg->filament_width = p->sizeX();
145 fildir = Vector3<double>(0,1,0);
146 start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, 0);
147 }
148 finc = (long) mg->filament_width/2;
149 pid = 0;
150 if ( verbose & VERB_FULL )
151 cout << " with " << p->images() << " filaments";
152 }
153 if ( verbose & VERB_FULL )
154 cout << endl;
155 } else {
156 rec = reconstruction_add(&project->rec, base);
157 if ( verbose & VERB_FULL )
158 cout << "Creating reconstruction \"" << rec->id << "\"" << endl;
159 if ( type == "rec" ) rec->frec = p->file_name();
160 else if ( type == "part" ) rec->fpart = p->file_name();
161 else if ( type == "fil" ) rec->ffil = p->file_name();
162 rec->voxel_size = pixel_size;
163 if ( type == "rec" ) rec->origin = p->image->origin();
164 rec->select = 1;
165 if ( type == "part" ) partlist = &rec->part;
166 if ( type == "fil" ) {
167 fillist = &rec->fil;
168 fildir = Vector3<double>(1,0,0);
169 start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, p->sizeY()/2);
170 rec->filament_width = p->sizeY();
171 if ( p->sizeX() < p->sizeY() ) {
172 rec->filament_width = p->sizeX();
173 fildir = Vector3<double>(0,1,0);
174 start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, p->sizeX()/2);
175 }
176 finc = (long) rec->filament_width/2;
177 }
178 }
179
180 if ( partlist ) {
181 for ( j=pid=0; j<p->images(); j++ ) {
182 part = particle_add(partlist, ++pid);
183 part->pixel_size = pixel_size;
184 part->ori = p->image[j].origin();
185 if ( fabs(part->ori[0] - p->sizeX()/2) > p->sizeX()/4 ) part->ori[0] = p->sizeX()/2;
186 if ( fabs(part->ori[1] - p->sizeY()/2) > p->sizeY()/4 ) part->ori[1] = p->sizeY()/2;
187 if ( fabs(part->ori[2] - p->sizeZ()/2) > p->sizeZ()/4 ) part->ori[2] = p->sizeZ()/2;
188 part->view = p->image[j].view();
189 part->sel = j+1;
190 }
191 }
192
193 if ( fillist ) {
194 flen = p->sizeX() - 2*finc;
195 if ( p->sizeY() > p->sizeX() ) flen = p->sizeY() - 2*finc;
196 for ( j=0; j<p->images(); j++ ) {
197 fil = filament_add(fillist, ++pid);
198 for ( nid = 0, k = 0; k < flen; k += finc ) {
199 fnode = filament_node_add(&fil->node, ++nid);
200 fnode->loc = start + fildir * k;
201 }
202 }
203 }
204
205 return project;
206 }
207
224 Bproject* project_create_from_images(Bstring* file_list, Bstring type)
225 {
226 if ( file_list->empty() ) {
227 error_show("Error in project_create_from_images: No filenames given to create a project!", __FILE__, __LINE__);
228 return NULL;
229 }
230
231 type = image_type(type);
232
233 Bimage* p = read_img(*file_list, 0, -1);
234
235 if ( !p ) {
236 cerr << "Error: Input image file " << *file_list << " not found!" << endl;
237 return NULL;
238 }
239
240 int multi(0); // Flag for multiple files
241
242 if ( type.length() < 1 ) {
243 if ( p->images() == 1 ) {
244 if ( p->sizeZ() > 1 ) type = "rec"; // Assume reconstructions
245 else type = "mg"; // Assume micrographs
246 } else {
247 if ( p->sizeX() != p->sizeY() ) type = "fil"; // Assume filaments
248 else type = "part"; // Assume particles
249 }
250 }
251
252 // if ( type == "part" && p->images() == 1 ) multi = 1; // Single particle files - assume one mg or rec only
253
254 if ( verbose )
255 cout << "Creating a project from images of type \"" << type << "\"" << endl << endl;
256
257 if ( verbose & VERB_DEBUG )
258 cout << "DEBUG project_create_from_images: type=" << type << " multi=" << multi << endl;
259
260 long i, j, k, pid(0), nid, flen, finc(1);
261 Bproject* project = project_init();
262 Bfield* field = NULL;
263 Bmicrograph* mg = NULL;
264 Breconstruction* rec = NULL;
265 Bframe* frame = NULL;
266 Bparticle* part = NULL;
267 Bparticle** partlist = NULL;
268 Bfilament* fil = NULL;
269 Bfilament** fillist = NULL;
270 Bfilnode* fnode = NULL;
271 Bstring* thisfile = NULL;
272 Bstring base("1"), id;
273 Vector3<double> start, fildir;
274
275 if ( ( type == "part" || type == "mg" || type == "frame" ) && multi ) {
276 if ( type == "frame" ) if ( p->sizeZ() > 1 ) p->slices_to_images();
277 if ( p->sizeZ() == 1 ) {
278 field = field_add(&project->field, base);
279 mg = micrograph_add(&field->mg, base);
280 if ( verbose & VERB_FULL )
281 cout << "Creating field \"" << field->id << "\", micrograph \"" << mg->id << "\"" << endl;
282 mg->select = 1;
283 if ( type == "part" ) partlist = &mg->part;
284 if ( type == "fil" ) fillist = &mg->fil;
285 } else {
286 rec = reconstruction_add(&project->rec, base);
287 if ( verbose & VERB_FULL )
288 cout << "Creating reconstruction \"" << rec->id << "\"" << endl;
289 rec->select = 1;
290 if ( type == "part" ) partlist = &rec->part;
291 if ( type == "fil" ) fillist = &rec->fil;
292 }
293 }
294
295 delete p;
296
297 for ( i=0, thisfile = file_list; thisfile; thisfile = thisfile->next, i++ ) {
298 base = thisfile->base().alnum();
299 p = read_img(*thisfile, 0, -1);
300 if ( !multi ) {
301 partlist = NULL;
302 fillist = NULL;
303 if ( type == "frame" || type == "mg" ) if ( p->sizeZ() > 1 ) p->slices_to_images();
304 if ( p->image->origin().length() < 1 ) p->origin(p->size()/2);
305 if ( p->sizeZ() == 1 ) { // 2D files are assumed to be micrographs
306 field = field_add(&project->field, base);
307 if ( verbose & VERB_FULL )
308 cout << "Creating field \"" << field->id << endl;
309 k = 1;
310 if ( type == "mg" ) k = p->images();
311 for ( j=0; j<k; j++ ) {
312 id = base;
313 if ( k > 1 ) id += Bstring(j+1, "_%03d");
314 mg = micrograph_add(&field->mg, id);
315 if ( verbose & VERB_FULL )
316 cout << "Micrograph \"" << mg->id << endl;
317 if ( type == "mg" ) mg->fmg = *thisfile;
318 else if ( type == "frame" ) mg->fframe = *thisfile;
319 mg->img_num = j;
320 mg->block = i + j;
321 mg->pixel_size = p->sampling()[0];
322 if ( type == "mg" ) mg->origin = p->image[j].origin();
323 mg->matrix = p->image[j].view().matrix();
324 mg->select = 1;
325 }
326 if ( type == "frame" ) {
327 mg->origin = p->size()/2;
328 for ( j=0; j<k; j++ ) {
329 frame = frame_add(&mg->frame, j+1);
330 frame->shift = p->image[j].origin() - mg->origin;
331 }
332 }
333 mg = field_find_zero_tilt_mg(field);
334 field->origin = mg->origin;
335 if ( type == "part" ) {
336 mg->fpart = *thisfile;
337 partlist = &mg->part;
338 pid = 0;
339 if ( verbose & VERB_FULL )
340 cout << " with " << p->images() << " particles";
341 } else if ( type == "fil" ) {
342 mg->ffil = *thisfile;
343 fillist = &mg->fil;
344 pid = 0;
345 if ( verbose & VERB_FULL )
346 cout << " with " << p->images() << " filaments";
347 }
348 if ( verbose & VERB_FULL )
349 cout << endl;
350 } else { // 3D files are assumed to be reconstructions
351 rec = reconstruction_add(&project->rec, base);
352 if ( verbose & VERB_FULL )
353 cout << "Creating reconstruction \"" << rec->id << "\"";
354 rec->block = i;
355 rec->select = 1;
356 if ( type == "part" ) {
357 rec->fpart = *thisfile;
358 partlist = &rec->part;
359 pid = 0;
360 if ( verbose & VERB_FULL )
361 cout << " with " << p->images() << " particles";
362 } else if ( type == "fil" ) {
363 rec->ffil = *thisfile;
364 fillist = &rec->fil;
365 pid = 0;
366 if ( verbose & VERB_FULL )
367 cout << " with " << p->images() << " filaments";
368 } else {
369 rec->frec = *thisfile;
370 rec->origin = p->image->origin();
371 }
372 if ( verbose & VERB_FULL )
373 cout << endl;
374 }
375 }
376
377 if ( mg ) {
378 if ( type == "part" ) {
379 mg->box_size = p->size();
380 } else if ( type == "fil" ) {
381 fildir = Vector3<double>(1,0,0);
382 start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, 0);
383 mg->filament_width = p->sizeY();
384 if ( p->sizeX() < p->sizeY() ) {
385 mg->filament_width = p->sizeX();
386 fildir = Vector3<double>(0,1,0);
387 start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, 0);
388 }
389 finc = (long) mg->filament_width/2;
390 } else if ( type == "ft" || type == "ps" ) {
391 mg->filament_width = p->sizeY();
392 mg->helix_axis = 0;
393 if ( p->sizeX() < p->sizeY() ) {
394 mg->filament_width = p->sizeX();
395 mg->helix_axis = M_PI_2;
396 }
397 }
398 } else if ( rec ) {
399 rec->voxel_size = p->sampling()[0];
400 if ( type == "part" ) {
401 rec->box_size = p->size();
402 } else if ( type == "fil" ) {
403 fildir = Vector3<double>(1,0,0);
404 start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, p->sizeY()/2);
405 rec->filament_width = p->sizeY();
406 if ( p->sizeX() < p->sizeY() ) {
407 rec->filament_width = p->sizeX();
408 fildir = Vector3<double>(0,1,0);
409 start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, p->sizeX()/2);
410 }
411 finc = (long) rec->filament_width/2;
412 } else if ( type == "ft" || type == "ps" ) {
413 rec->filament_width = p->sizeX();
414 if ( p->sizeY() < rec->filament_width ) rec->filament_width = p->sizeY();
415 if ( p->sizeZ() < rec->filament_width ) rec->filament_width = p->sizeZ();
416 }
417 }
418
419 if ( partlist ) {
420 for ( j=0; j<p->images(); j++ ) {
421 part = particle_add(partlist, ++pid);
422 part->ori = p->image[j].origin();
423 if ( fabs(part->ori[0] - p->sizeX()/2) > p->sizeX()/4 ) part->ori[0] = p->sizeX()/2;
424 if ( fabs(part->ori[1] - p->sizeY()/2) > p->sizeY()/4 ) part->ori[1] = p->sizeY()/2;
425 if ( fabs(part->ori[2] - p->sizeZ()/2) > p->sizeZ()/4 ) part->ori[2] = p->sizeZ()/2;
426 part->view = p->image[j].view();
427 // cout << part->id << tab << part->view << endl;
428 // part->sel = 1;
429 part->sel = j+1;
430 }
431 if ( multi ) part->fpart = *thisfile;
432 }
433
434 if ( fillist ) {
435 flen = p->sizeX() - 2*finc;
436 if ( p->sizeY() > p->sizeX() ) flen = p->sizeY() - 2*finc;
437 for ( j=0; j<p->images(); j++ ) {
438 fil = filament_add(fillist, ++pid);
439 for ( nid = 0, k = 0; k < flen; k += finc ) {
440 fnode = filament_node_add(&fil->node, ++nid);
441 fnode->loc = start + fildir * k;
442 }
443 }
444 if ( multi ) fil->ffil = *thisfile;
445 }
446
447 delete p;
448 }
449
450 return project;
451 }
452
463 Bimage* particle_read_img(Bparticle* part, int readflag)
464 {
465 if ( !part ) return NULL;
466
467 Bstring filename(part->fpart);
468 long img_num(0);
469
470 if ( !part->mg ) cerr << "Error: no micrograph for particle " << part->id << endl;
471
472 if ( filename.length() < 2 ) {
473 if ( part->mg ) {
474 filename = part->mg->fpart;
475 img_num = part->id - 1;
476 } else if ( part->rec ) {
477 filename = part->rec->fpart;
478 img_num = part->id - 1;
479 }
480 }
481
482 if ( verbose & VERB_PROCESS )
483 cout << "Particle image filename:" << tab << filename << " (" << img_num << ")" << endl;
484
485 Bimage* p = NULL;
486
487 if ( filename.length() ) {
488 p = read_img(filename, readflag, img_num);
489 if ( !p ) {
490 error_show("Particle file not read", __FILE__, __LINE__);
491 return NULL;
492 }
493 }
494
495 return p;
496 }
497
509 int particle_write_img(Bparticle* part, Bimage* p, int compression)
510 {
511 if ( !part ) return 0;
512
513 Bstring filename(part->fpart);
514 long img_num(p->images());
515
516 if ( !part->mg ) cerr << "Error: no micrograph for particle " << part->id << endl;
517
518 if ( filename.length() < 2 ) {
519 if ( part->mg )
520 filename = part->mg->fpart;
521 else if ( part->rec )
522 filename = part->rec->fpart;
523 }
524
525 if ( verbose & VERB_PROCESS )
526 cout << "Particle image filename:" << tab << filename << " (" << img_num << ")" << endl;
527
528 if ( filename.length() ) {
529 write_img(filename, p, compression);
530 if ( !p ) {
531 error_show("Particle file not written", __FILE__, __LINE__);
532 return 0;
533 }
534 }
535
536 return 1;
537 }
538
548 int project_check_particles(Bproject* project)
549 {
550 if ( !project ) return -1;
551
552 int oldverbose = verbose;
553 verbose = 0;
554
555 int err(0);
556 long n;
557 Bimage* p = NULL; // image currently being processed
558 Bfield* field = NULL; // field-of-view currently being processed
559 Bmicrograph* mg = NULL; // micrograph currently being processed
560 Bparticle* part = NULL; // particle currently being processed
561
562 cout << "Checking particle numbers:" << endl;
563
564 for ( field = project->field; field; field = field->next) {
565 for ( mg = field->mg; mg; mg = mg->next) if ( mg->fpart.length() ) {
566 p = read_img(mg->fpart, 0, -1);
567 if ( verbose & VERB_DEBUG )
568 cout << "DEBUG project_check_particles: " << mg->fpart << ":" << p->images() << endl;
569 if ( p ) {
570 mg->box_size = p->size();
571 for ( n=0, part = mg->part; part; part = part->next, n++ ) {
572 if ( part->pixel_size < 0.01 ) part->pixel_size = mg->pixel_size;
573 if ( part->ori[0]*part->ori[1] < mg->box_size.volume()/16 )
574 part->ori += mg->box_size/2;
575 }
576 if ( n != p->images() ) {
577 cerr << "Error: Micrograph " << mg->id << " has " << n << " particles," << endl;
578 cerr << " but particle image file " << p->file_name() << " has " << p->images() << " images!" << endl;
579 err--;
580 } else {
581 cout << mg->id << ": " << n << " = " << p->images() << endl;
582 }
583 delete p;
584 p = NULL;
585 }
586 }
587 }
588
589 verbose = oldverbose;
590
591 return err;
592 }
593
602 Vector3<long> micrograph_get_size(Bmicrograph* mg)
603 {
604 Vector3<long> size;
605
606 Bimage* p = NULL;
607
608 if ( mg->fmg.length() )
609 p = read_img(mg->fmg, 0, 0);
610 else if ( mg->fframe.length() )
611 p = read_img(mg->fframe, 0, 0);
612
613 if ( !p )
614 error_show("micrograph_get_size", __FILE__, __LINE__);
615 else {
616 size = p->size();
617 delete p;
618 }
619
620 return size;
621 }
622
631 Vector3<double> micrograph_get_nominal_origin(Bmicrograph* mg)
632 {
633 Vector3<double> origin;
634
635 Bimage* p = NULL;
636
637 if ( mg->fmg.length() )
638 p = read_img(mg->fmg, 0, 0);
639 else if ( mg->fframe.length() )
640 p = read_img(mg->fframe, 0, 0);
641
642 if ( !p )
643 error_show("micrograph_get_nominal_origin", __FILE__, __LINE__);
644 else {
645 origin = Vector3<double>(p->size()/2);
646 delete p;
647 }
648
649 return origin;
650 }
651
660 int project_set_nominal_mg_origins(Bproject* project)
661 {
662 Bmicrograph* mg;
663 Bimage* p = NULL;
664
665 if ( verbose & VERB_FULL )
666 cout << "Setting nominal micrograph origins" << endl << endl;
667
668 for ( mg = project->field->mg; mg; mg = mg->next ) {
669 p = read_img(mg->fmg, 0, mg->img_num);
670 if ( !p )
671 error_show("project_set_nominal_mg_origins", __FILE__, __LINE__);
672 else {
673 mg->origin = p->size()/2;
674 delete p;
675 }
676 }
677
678 return 0;
679 }
680
690 int project_reset_origins(Bproject* project)
691 {
692 if ( !project ) return 0;
693 if ( !project->field ) return 0;
694 if ( !project->field->mg ) return 0;
695 if ( !project->field->mg->part ) return 0;
696
697 Bfield* field;
698 Bmicrograph* mg;
699 Bparticle* part;
700 Bimage* p;
701
702 if ( verbose & VERB_FULL )
703 cout << "Resetting origins" << endl << endl;
704
705 for ( field = project->field; field; field = field->next )
706 for ( mg = field->mg; mg; mg = mg->next ) {
707 if ( mg->fpart.length() ) p = read_img(mg->fpart, 0, -1);
708 else p = read_img(mg->fmg, 0, -1);
709 if ( !p )
710 error_show("project_reset_origins", __FILE__, __LINE__);
711 for ( part = mg->part; part; part = part->next )
712 part->ori = p->size()/2;
713 delete p;
714 }
715
716 return 0;
717 }
718
729 int project_set_part_img_origins(Bproject* project)
730 {
731 if ( !project ) return -1;
732
733 Bimage* p = NULL; // image currently being processed
734 Bfield* field = NULL; // field-of-view currently being processed
735 Bmicrograph* mg = NULL; // micrograph currently being processed
736 Bparticle* part = NULL; // particle currently being processed
737
738 for ( field = project->field; field; field = field->next) {
739 for ( mg = field->mg; mg; mg = mg->next) {
740 p = read_img(mg->fpart, 1, -1);
741 for ( part = mg->part; part; part = part->next )
742 p->image[part->id-1].origin(part->ori);
743 write_img(mg->fpart, p, 0);
744 delete p;
745 }
746 }
747
748 return 0;
749 }
750
757 long project_delesect_edge_particles(Bproject* project)
758 {
759 if ( !project ) return -1;
760
761 long nsel(0);
762 Bimage* p = NULL; // image currently being processed
763 Bfield* field = NULL; // field-of-view currently being processed
764 Bmicrograph* mg = NULL; // micrograph currently being processed
765 Bparticle* part = NULL; // particle currently being processed
766 Vector3<double> min, max;
767
768 for ( field = project->field; field; field = field->next) {
769 for ( mg = field->mg; mg; mg = mg->next) {
770 p = read_img(mg->fmg, 0, 0);
771 min = mg->box_size/2;
772 max = p->size() - min;
773 if ( verbose & VERB_DEBUG )
774 cout << "DEBUG project_delesect_edge_particles: limits:" << tab << min << tab << max << endl;
775 for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
776 if ( part->loc >= min || part->loc <= max ) nsel++;
777 else part->sel = 0;
778 }
779 delete p;
780 }
781 }
782
783 return 0;
784 }
785
794 int project_get_part_box_size(Bproject* project)
795 {
796 if ( !project ) return -1;
797
798 Bimage* p = NULL; // image currently being processed
799 Bfield* field = NULL; // field-of-view currently being processed
800 Bmicrograph* mg = NULL; // micrograph currently being processed
801 Bparticle* part = NULL; // particle currently being processed
802
803 for ( field = project->field; field; field = field->next) {
804 for ( mg = field->mg; mg; mg = mg->next) if ( mg->fpart.length() ) {
805 p = particle_read_img(mg->part, 0);
806 if ( p ) {
807 mg->box_size = p->size();
808 delete p;
809 for ( part = mg->part; part; part = part->next )
810 if ( part->ori[0]*part->ori[1] < mg->box_size.volume()/16 )
811 part->ori += mg->box_size/2;
812 }
813 }
814 }
815
816 return 0;
817 }
818
827 Vector3<long> particle_get_box_size(Bparticle* part)
828 {
829 Vector3<long> size;
830
831 Bimage* p = particle_read_img(part, 0);
832
833 if ( p ) {
834 size = p->size();
835 delete p;
836 }
837
838 return size;
839 }
840
849 int project_write_particle_classes(Bproject* project)
850 {
851 if ( !project ) return -1;
852
853 long i, n(0);
854 Bfield* field = NULL;
855 Bmicrograph* mg = NULL;
856 Bparticle* part = NULL;
857 Bimage* p = NULL;
858 Bimage* pt = NULL;
859 Bstring filename;
860
861 for ( field = project->field; field; field = field->next)
862 for ( mg = field->mg; mg; mg = mg->next)
863 for ( part = mg->part; part; part = part->next )
864 if ( part->sel > n ) n = part->sel;
865
866 long* cn = new long[n];
867 Bimage** pn = new Bimage*[n];
868
869 if ( verbose )
870 cout << "Writing " << n << " particle classes to separate files:" << endl;
871
872 for ( field = project->field; field; field = field->next) {
873 for ( mg = field->mg; mg; mg = mg->next) {
874 if ( n ) {
875 p = read_img(mg->fpart, 1, -1);
876 for ( i=0; i<n; i++ ) cn[i] = 0;
877 for ( part = mg->part; part; part = part->next )
878 if ( part->sel > 0 ) cn[part->sel-1]++;
879 for ( i=0; i<n; i++ ) if ( cn[i] ) {
880 if ( verbose & VERB_FULL )
881 cout << "Creating image with " << cn[i] << " particles" << endl;
882 pn[i] = p->copy_header(cn[i]);
883 pn[i]->data_alloc();
884 }
885 for ( i=0; i<n; i++ ) cn[i] = 0;
886 for ( part = mg->part; part; part = part->next )
887 if ( part->sel > 0 ) {
888 pt = p->extract(part->id-1);
889 pn[part->sel-1]->replace(cn[part->sel-1]++, pt);
890 delete pt;
891 }
892 delete p;
893 for ( i=0; i<n; i++ ) if ( cn[i] ) {
894 filename = mg->fpart.pre_rev('.') + Bstring(i+1, "_%03d.") + mg->fpart.post_rev('.');
895 if ( verbose )
896 cout << "Writing " << filename << " with " << cn[i] << " particles" << endl;
897 write_img(filename, pn[i], 0);
898 delete pn[i];
899 }
900 }
901 }
902 }
903
904 delete[] cn;
905 delete[] pn;
906
907 return 0;
908 }
909
919 int project_trim_class_averages(Bproject* project, Bstring& list)
920 {
921 if ( ! project->class_avg ) return 0;
922 if ( list.length() < 1 ) return 0;
923
924 long navg(0), i, id;
925 Bparticle* part, *part_list, *part_nu;
926
927 for ( part = project->class_avg; part; part = part->next ) navg++;
928
929 int* numsel = new int[navg];
930 select_numbers(list, navg, numsel);
931
932 Bstring filename(project->class_avg->fpart);
933 Bimage* pavg = read_img(filename, 1, -1);
934 pavg->delete_images(list);
935
936 filename = filename.pre_rev('.') + "_del." + filename.post_rev('.');
937 write_img(filename, pavg, 0);
938
939 for ( i=id=0, part_list = NULL, part = project->class_avg; part; part = part->next, ++i ) {
940 if ( !numsel[i] ) {
941 part_nu = particle_copy(&part_list, part);
942 part_nu->id = ++id;
943 part_nu->fpart = filename;
944 }
945 }
946
947 particle_kill(project->class_avg);
948 project->class_avg = part_list;
949
950 delete[] numsel;
951
952 if ( verbose & VERB_PROCESS )
953 cout << "Number of class averages: " << id << endl << endl;
954
955 return 0;
956 }
957
970 int project_flip_particle_coordinates(Bproject* project, int flip)
971 {
972 Bfield* field;
973 Bmicrograph* mg;
974 Breconstruction* rec;
975 Bparticle* part;
976 Bbadarea* bad;
977 Bimage* p = NULL;
978 int fz = flip/4;
979 int fy = (flip - 4*fz)/2;
980 int fx = flip - 4*fz - 2*fy;
981
982 if ( verbose & VERB_PROCESS ) {
983 cout << "Flipping locations along ";
984 if ( fx ) cout << "x";
985 if ( fy ) cout << "y";
986 if ( fz ) cout << "z";
987 cout << endl;
988 }
989
990 if ( project->select ) {
991 for ( rec = project->rec; rec; rec = rec->next ) {
992 if ( rec->frec.length() ) p = read_img(rec->frec, 0, -1);
993 for ( part = rec->part; part; part = part->next ) {
994 if ( fx ) part->loc[0] = p->sizeX() - part->loc[0];
995 if ( fy ) part->loc[1] = p->sizeY() - part->loc[1];
996 if ( fz ) part->loc[2] = p->sizeZ() - part->loc[2];
997 }
998 for ( bad = rec->bad; bad; bad = bad->next ) {
999 if ( fx ) bad->loc[0] = p->sizeX() - bad->loc[0];
1000 if ( fy ) bad->loc[1] = p->sizeY() - bad->loc[1];
1001 if ( fz ) bad->loc[2] = p->sizeZ() - bad->loc[2];
1002 }
1003 delete p;
1004 }
1005 } else {
1006 for ( field = project->field; field; field = field->next ) {
1007 for ( mg = field->mg; mg; mg = mg->next ) {
1008 if ( mg->fmg.length() ) p = read_img(mg->fmg, 0, -1);
1009 else if ( mg->fframe.length() ) p = read_img(mg->fframe, 0, -1);
1010 for ( part = mg->part; part; part = part->next ) {
1011 if ( fx ) part->loc[0] = p->sizeX() - part->loc[0];
1012 if ( fy ) part->loc[1] = p->sizeY() - part->loc[1];
1013 if ( fz ) part->loc[2] = p->sizeZ() - part->loc[2];
1014 }
1015 for ( bad=mg->bad; bad; bad=bad->next ) {
1016 if ( fx ) bad->loc[0] = p->sizeX() - bad->loc[0];
1017 if ( fy ) bad->loc[1] = p->sizeY() - bad->loc[1];
1018 if ( fz ) bad->loc[2] = p->sizeZ() - bad->loc[2];
1019 }
1020 delete p;
1021 }
1022 }
1023 }
1024
1025 return 0;
1026 }
1027
1033 int project_set_views_from_images(Bproject* project)
1034 {
1035 if ( !project ) return 0;
1036
1037 long n;
1038 Bfield* field;
1039 Bmicrograph* mg;
1040 Bparticle* part;
1041 Bimage* p = NULL;
1042
1043 if ( verbose & VERB_PROCESS )
1044 cout << "Getting parameters from picked particle files" << endl << endl;
1045
1046 for ( field = project->field; field; field = field->next ) {
1047 for ( mg = field->mg; mg; mg = mg->next ) {
1048 if ( mg->fpart.length() && ( p = read_img(mg->fpart, 0, -1) ) ) {
1049 if ( verbose & VERB_DEBUG )
1050 cout << "DEBUG project_set_views_from_images: File=" << mg->fpart << " particles=" << p->images() << endl;
1051 if ( p->images() < 2 ) mg->fmg = mg->fpart;
1052 if ( !mg->part )
1053 for ( n=0; n<p->images(); n++ ) particle_add(&mg->part, n+1);
1054 if ( mg->pixel_size < 0.01 && p->sampling()[0] > 0 )
1055 mg->pixel_size = p->sampling()[0];
1056 for ( part = mg->part; part; part = part->next ) {
1057 n = part->id - 1;
1058 if ( part->pixel_size < 0.01 && p->sampling()[0] > 0 )
1059 part->pixel_size = p->sampling()[0];
1060 part->ori = p->size()/2;
1061 if ( p->image[n].origin()[0] >= 0 && p->image[n].origin()[0] < p->sizeX() )
1062 part->ori[0] = p->image[n].origin()[0];
1063 if ( p->image[n].origin()[1] >= 0 && p->image[n].origin()[1] < p->sizeY() )
1064 part->ori[1] = p->image[n].origin()[1];
1065 if ( p->image[n].origin()[2] >= 0 && p->image[n].origin()[2] < p->sizeZ() )
1066 part->ori[2] = p->image[n].origin()[2];
1067 part->view = p->image[n].view();
1068 }
1069 delete p;
1070 }
1071 }
1072 }
1073
1074 return 0;
1075 }
1076
1082 int project_set_views_in_images(Bproject* project)
1083 {
1084 if ( !project ) return 0;
1085
1086 long n;
1087 Bfield* field;
1088 Bmicrograph* mg;
1089 Bparticle* part;
1090 Bimage* p = NULL;
1091
1092 if ( verbose & VERB_PROCESS )
1093 cout << "Setting view parameters in picked particle files" << endl << endl;
1094
1095 for ( field = project->field; field; field = field->next ) {
1096 for ( mg = field->mg; mg; mg = mg->next ) {
1097 p = read_img(mg->fpart, 1, -1);
1098 if ( p ) {
1099 if ( verbose & VERB_DEBUG )
1100 cout << "DEBUG project_set_views_in_images: File=" << mg->fpart << " particles=" << p->images() << endl;
1101 if ( p->images() < 2 ) mg->fmg = mg->fpart;
1102 if ( mg->pixel_size > 0 ) p->sampling(mg->pixel_size, mg->pixel_size, 1);
1103 if ( mg->part ) {
1104 for ( part = mg->part; part; part = part->next ) {
1105 n = part->id - 1;
1106 if ( part->pixel_size > 0 )
1107 p->image[n].sampling(part->pixel_size, part->pixel_size, 1);
1108 p->image[n].origin(p->size()/2);
1109 if ( part->ori[0] < 0 || part->ori[0] >= p->sizeX() )
1110 part->ori[0] = p->sizeX()/2;
1111 if ( part->ori[1] < 0 || part->ori[1] >= p->sizeY() )
1112 part->ori[1] = p->sizeY()/2;
1113 if ( part->ori[2] < 0 || part->ori[2] >= p->sizeZ() )
1114 part->ori[2] = p->sizeZ()/2;
1115 p->image[n].origin(part->ori);
1116 p->image[n].view(part->view);
1117 }
1118 write_img(mg->fpart, p, 0);
1119 }
1120 delete p;
1121 }
1122 }
1123 }
1124
1125 return 0;
1126 }
1127
1128 Bstring mg_img_scale(Bstring& filename, Bstring& path, Bstring& insert,
1129 double scale, Vector3<double> origin, double pixel_size)
1130 {
1131 if ( filename.length() < 1 ) return filename;
1132
1133 Bimage* p = read_img(filename, 1, -1);
1134
1135 if ( !p ) {
1136 delete p;
1137 return filename;
1138 }
1139
1140 if ( verbose )
1141 cout << "Binning " << filename << endl;
1142
1143 p->sampling(pixel_size, pixel_size, 1);
1144
1145 Bstring nufile(filename);
1146
1147 if ( nufile.contains("/") ) nufile = nufile.post_rev('/');
1148 nufile = nufile.pre_rev('.') + insert + nufile.post_rev('.');
1149 if ( path.length() ) nufile = path + nufile;
1150
1151 Vector3<long> size(p->size() * scale);
1152 size = size.max(1);
1153
1154 Vector3<double> svec(scale, scale, 1);
1155
1156 Vector3<double> translate = (origin*scale - origin).round(0);
1157
1158 Matrix3 mat(1);
1159
1160 Bimage* ps = p->transform(size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1161
1162 write_img(nufile, ps, 0);
1163
1164 delete p;
1165 delete ps;
1166
1167 return nufile;
1168 }
1169
1187 int project_scale_box(Bproject* project, double scale, Bstring mgpath, Bstring partpath, Bstring insert)
1188 {
1189 if ( !project ) return 0;
1190
1191 if ( scale <= 0 ) return 0;
1192
1193 Vector3<long> size;
1194 Vector3<double> shift, origin, translate;
1195 Vector3<double> svec(scale, scale, scale);
1196 Matrix3 mat(1);
1197 Bstring newfile;
1198 Bimage* p = NULL;
1199 Bimage* ps = NULL;
1200
1201 Bfield* field;
1202 Bmicrograph* mg;
1203 Breconstruction* rec;
1204 Bparticle* part;
1205 Bfilament* fil;
1206 Bfilnode* fnode;
1207 Bbadarea* bad;
1208 Bmarker* mark;
1209
1210 if ( verbose )
1211 cout << "Scaling by " << scale << endl;
1212
1213 if ( mgpath == "." || mgpath == "./" ) mgpath = 0;
1214 if ( partpath == "." || partpath == "./" ) partpath = 0;
1215
1216 if ( mgpath.length() ) {
1217 if ( mgpath[-1] != '/' ) mgpath += "/";
1218 if ( verbose )
1219 cout << "Micrograph path: " << mgpath << endl;
1220 }
1221
1222 if ( partpath.length() ) {
1223 if ( partpath[-1] != '/' ) partpath += "/";
1224 if ( verbose )
1225 cout << "Particle path: " << partpath << endl;
1226 }
1227
1228 if ( verbose )
1229 cout << endl;
1230
1231 if ( !project->select ) {
1232 svec[2] = 1;
1233 for ( field = project->field; field; field = field->next ) {
1234 for ( mg = field->mg; mg; mg = mg->next ) {
1235 if ( verbose & VERB_DEBUG )
1236 cout << "DEBUG project_scale_box: scale=" << scale << endl;
1237 /* mg->pixel_size /= scale;
1238 origin = mg->origin;
1239 mg->origin = mg->origin * scale;
1240 p = NULL;
1241 if ( mg->fmg.length() ) p = read_img(mg->fmg, 1, -1);
1242 if ( p ) {
1243 newfile = mg->fmg;
1244 if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1245 newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1246 if ( mgpath.length() ) newfile = mgpath + newfile;
1247 mg->fmg = newfile;
1248 size = p->size() * scale;
1249 size = size.max(1);
1250 translate = (mg->origin - origin).round(0);
1251 ps = p->transform(size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1252 ps->sampling(mg->pixel_size, mg->pixel_size, 1);
1253 write_img(mg->fmg, ps, 0);
1254 delete p;
1255 delete ps;
1256 }*/
1257 if ( mg->fmg.length() )
1258 mg->fmg = mg_img_scale(mg->fmg, mgpath, insert, scale, mg->origin, mg->pixel_size);
1259 if ( mg->fframe.length() )
1260 mg->fframe = mg_img_scale(mg->fframe, mgpath, insert, scale, mg->origin, mg->pixel_size);
1261 mg->origin = mg->origin * scale;
1262 mg->pixel_size /= scale;
1263 origin = mg->box_size/2;
1264 mg->box_size = mg->box_size * scale;
1265 mg->box_size = mg->box_size.max(1);
1266 mg->bad_radius = bround(mg->bad_radius*scale, 0);
1267 mg->mark_radius = bround(mg->mark_radius*scale, 0);
1268 for ( part = mg->part; part; part = part->next ) {
1269 part->loc *= scale;
1270 part->pixel_size /= scale;
1271 shift = part->loc.remainder(1);
1272 part->loc = part->loc.floor(0);
1273 part->ori = (part->ori * scale) + shift;
1274 }
1275 for ( fil=mg->fil; fil; fil=fil->next ) {
1276 for ( fnode=fil->node; fnode; fnode=fnode->next )
1277 fnode->loc = (fnode->loc * scale).round(0);
1278 }
1279 for ( bad=mg->bad; bad; bad=bad->next )
1280 bad->loc = (bad->loc * scale).round(0);
1281 for ( mark=mg->mark; mark; mark=mark->next )
1282 mark->loc = (mark->loc * scale).round(0);
1283 /* if ( mg->fpart.length() ) {
1284 p = read_img(mg->fpart, 1, -1);
1285 if ( p ) {
1286 newfile = mg->fpart;
1287 if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1288 newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1289 if ( partpath.length() ) newfile = partpath + newfile;
1290 mg->fpart = newfile;
1291 translate = mg->box_size/2 - origin;
1292 ps = p->transform(mg->box_size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1293 ps->sampling(mg->pixel_size, mg->pixel_size, 1);
1294 write_img(mg->fpart, ps, 0);
1295 delete p;
1296 delete ps;
1297 }
1298 }*/
1299 if ( mg->fpart.length() )
1300 mg->fpart = mg_img_scale(mg->fpart, partpath, insert, scale, origin, mg->pixel_size);
1301 }
1302 }
1303 } else {
1304 for ( rec = project->rec; rec; rec = rec->next ) {
1305 if ( verbose & VERB_DEBUG )
1306 cout << "DEBUG project_scale_box: scale=" << scale << endl;
1307 rec->voxel_size /= scale;
1308 origin = rec->origin;
1309 rec->origin = rec->origin * scale;
1310 p = NULL;
1311 if ( rec->frec.length() ) p = read_img(rec->frec, 1, -1);
1312 if ( p ) {
1313 newfile = rec->frec;
1314 if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1315 newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1316 if ( mgpath.length() ) newfile = mgpath + newfile;
1317 rec->frec = newfile;
1318 size = p->size() * scale;
1319 translate = (rec->origin - origin).round(0);
1320 // img_transform(p, size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1321 ps = p->transform(size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1322 ps->sampling(rec->voxel_size, rec->voxel_size, rec->voxel_size);
1323 write_img(rec->frec, ps, 0);
1324 delete p;
1325 delete ps;
1326 }
1327 rec->box_size = rec->box_size * scale;
1328 rec->bad_radius = bround(rec->bad_radius*scale, 0);
1329 rec->mark_radius = bround(rec->mark_radius*scale, 0);
1330 for ( part=rec->part; part; part=part->next ) {
1331 part->loc *= scale;
1332 part->pixel_size /= scale;
1333 shift = part->loc.remainder(1);
1334 part->loc = part->loc.floor(0);
1335 part->ori = (part->ori * scale) + shift;
1336 }
1337 for ( fil=rec->fil; fil; fil=fil->next ) {
1338 for ( fnode=fil->node; fnode; fnode=fnode->next )
1339 fnode->loc = (fnode->loc * scale).round(0);
1340 }
1341 for ( bad=rec->bad; bad; bad=bad->next )
1342 bad->loc = (bad->loc * scale).round(0);
1343 for ( mark=rec->mark; mark; mark=mark->next )
1344 mark->loc = (mark->loc * scale).round(0);
1345 if ( rec->fpart.length() ) {
1346 p = read_img(rec->fpart, 1, -1);
1347 if ( p ) {
1348 newfile = rec->fpart;
1349 if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1350 newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1351 if ( partpath.length() ) newfile = partpath + newfile;
1352 rec->fpart = newfile;
1353 // translate = (rec->box_size/2 - origin).round(0);
1354 translate = rec->box_size/2 - origin;
1355 // img_transform(p, rec->box_size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1356 ps = p->transform(rec->box_size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1357 ps->sampling(rec->voxel_size, rec->voxel_size, rec->voxel_size);
1358 write_img(rec->fpart, ps, 0);
1359 delete p;
1360 delete ps;
1361 }
1362 }
1363 }
1364 }
1365
1366 return 0;
1367 }
1368
1383 int project_bin_micrographs(Bproject* project, int bin, Bstring mgpath, Bstring partpath)
1384 {
1385 if ( bin <= 1 ) return -1;
1386
1387 if ( verbose )
1388 cout << "Binning micrographs by " << bin << endl;
1389
1390 double scale = 1.0/bin;
1391 Bstring insert(bin, "_b%d.");
1392
1393 project_scale_box(project, scale, mgpath, partpath, insert);
1394
1395 return 0;
1396 }
1397
1414 int project_change_pixel_size(Bproject* project, double new_pixel_size, Bstring mgpath, Bstring partpath)
1415 {
1416 if ( !project ) return 0;
1417
1418 if ( new_pixel_size <= 0 ) return 0;
1419
1420 double scale(0);
1421
1422 if ( project->select ) {
1423 if ( project->rec )
1424 scale = project->rec->voxel_size/new_pixel_size;
1425 } else {
1426 if ( project->field && project->field->mg )
1427 scale = project->field->mg->pixel_size/new_pixel_size;
1428 }
1429
1430 Bstring insert(scale, "_s%3.1lf.");
1431
1432 if ( scale ) project_scale_box(project, scale, mgpath, partpath, insert);
1433
1434 return 0;
1435 }
1436
1437
Breconstruction::fil
Bfilament * fil
Definition: mg_processing.h:305
filament_node_add
Bfilnode * filament_node_add(Bfilnode **fnode, int pid)
Adds a filament node parameter structure to a linked list.
Definition: mg_processing.cpp:655
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
qsort_functions.h
Header file for utility functions for use in qsort calls.
particle_write_img
int particle_write_img(Bparticle *part, Bimage *p, int compression)
Writes a particle image file.
Definition: mg_img_proc.cpp:509
Bframe::shift
Vector3< double > shift
Definition: mg_processing.h:77
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
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
Bparticle::rec
Breconstruction * rec
Definition: mg_processing.h:105
Vector3::remainder
Vector3 remainder(int divisor)
Definition: Vector3.h:216
Bparticle::view
View view
Definition: mg_processing.h:101
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bstring::alnum
Bstring alnum()
Definition: Bstring.cpp:349
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:288
Bimage::slices_to_images
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
Definition: Bimage.cpp:2052
Bmicrograph::id
Bstring id
Definition: mg_processing.h:202
Bbadarea
Definition: mg_processing.h:142
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:211
Breconstruction::filament_width
double filament_width
Definition: mg_processing.h:297
Bfilnode
Definition: mg_processing.h:115
utilities.h
Header file for general utilities.
particle_copy
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
Definition: mg_processing.cpp:1409
particle_get_box_size
Vector3< long > particle_get_box_size(Bparticle *part)
Gets the box size from particle image file.
Definition: mg_img_proc.cpp:827
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Bmicrograph::filament_width
double filament_width
Definition: mg_processing.h:231
Breconstruction
Definition: mg_processing.h:280
Bbadarea::loc
Vector3< double > loc
Definition: mg_processing.h:145
Bmarker
Definition: marker.h:21
Matrix3
Definition: Matrix3.h:17
frame_add
Bframe * frame_add(Bframe **frame, int pid)
Adds a movie frame parameter structure to a linked list.
Definition: mg_processing.cpp:495
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
Bimage::delete_images
long delete_images(Bstring list, int retain=0)
Retains or deletes sub-images from a multi-image structure.
Definition: Bimage.cpp:2134
project_get_part_box_size
int project_get_part_box_size(Bproject *project)
Gets the box size from particle image files.
Definition: mg_img_proc.cpp:794
particle_kill
int particle_kill(Bparticle *part)
Frees a list of particles.
Definition: mg_processing.cpp:1323
micrograph_get_nominal_origin
Vector3< double > micrograph_get_nominal_origin(Bmicrograph *mg)
Gets the nominal origin for a micrograph.
Definition: mg_img_proc.cpp:631
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bmicrograph::fil
Bfilament * fil
Definition: mg_processing.h:240
Bfield::origin
Vector3< float > origin
Definition: mg_processing.h:260
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
Bmicrograph::ffil
Bstring ffil
Definition: mg_processing.h:208
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:293
project_set_views_in_images
int project_set_views_in_images(Bproject *project)
Sets views in particle images from the project parameter structure.
Definition: mg_img_proc.cpp:1082
Bfield::next
Bfield * next
Definition: mg_processing.h:258
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:29
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
Breconstruction::mark_radius
double mark_radius
Definition: mg_processing.h:301
Bfilament::node
Bfilnode * node
Definition: mg_processing.h:132
project_set_nominal_mg_origins
int project_set_nominal_mg_origins(Bproject *project)
Sets micrograph origins to the centers of the micrographs.
Definition: mg_img_proc.cpp:660
Vector3::max
Type max()
Definition: Vector3.h:175
Bframe
Definition: mg_processing.h:74
Bmicrograph::matrix
Matrix3 matrix
Definition: mg_processing.h:222
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
Bfilament::next
Bfilament * next
Definition: mg_processing.h:129
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:704
Bimage::data_alloc
unsigned char * data_alloc()
Definition: Bimage.h:256
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bparticle::sel
long sel
Definition: mg_processing.h:103
Bimage::transform
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
Definition: Bimage_transform.cpp:37
Bfield
Definition: mg_processing.h:257
linked_list.h
Header file for generalized linked list functions.
project_set_part_img_origins
int project_set_part_img_origins(Bproject *project)
Writes particle origins into particle image files.
Definition: mg_img_proc.cpp:729
Bmicrograph::frame
Bframe * frame
Definition: mg_processing.h:237
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
base
string base(string &filename)
Definition: string_util.cpp:28
select_numbers
int select_numbers(Bstring &string, int n, int *numsel)
Converts a string with a selection specification into an integer array.
Definition: utilities.cpp:328
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:206
project_delesect_edge_particles
long project_delesect_edge_particles(Bproject *project)
Deselects particles that are too close to the image edges.
Definition: mg_img_proc.cpp:757
Bbadarea::next
Bbadarea * next
Definition: mg_processing.h:143
project_trim_class_averages
int project_trim_class_averages(Bproject *project, Bstring &list)
Deletes selected class averages from the project..
Definition: mg_img_proc.cpp:919
Bfield::id
Bstring id
Definition: mg_processing.h:259
Bstring::next
Bstring * next
Definition: Bstring.h:31
Bmicrograph::select
long select
Definition: mg_processing.h:203
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:235
Bproject::field
Bfield * field
Definition: mg_processing.h:343
verbose
int verbose
Bmicrograph::helix_axis
double helix_axis
Definition: mg_processing.h:226
field_find_zero_tilt_mg
Bmicrograph * field_find_zero_tilt_mg(Bfield *field)
Finds the micrograph closest to a zero degree tilt in a series.
Definition: mg_processing.cpp:400
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
Bproject::class_avg
Bparticle * class_avg
Definition: mg_processing.h:345
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
project_bin_micrographs
int project_bin_micrographs(Bproject *project, int bin, Bstring mgpath, Bstring partpath)
Bins all micrographs a project.
Definition: mg_img_proc.cpp:1383
image_type
Bstring image_type(Bstring type)
Converts an image type string to a standard form.
Definition: mg_img_proc.cpp:36
particle_read_img
Bimage * particle_read_img(Bparticle *part, int readflag)
Reads a particle image file.
Definition: mg_img_proc.cpp:463
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:91
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
project_flip_particle_coordinates
int project_flip_particle_coordinates(Bproject *project, int flip)
Reverses one or more particle coordinates.
Definition: mg_img_proc.cpp:970
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
Bsub_image::sampling
void sampling(double x, double y, double z)
Definition: Bimage.h:123
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:242
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
field_add
Bfield * field_add(Bfield **field, Bstring &field_id)
Adds a field-of-view parameter structure to a linked list.
Definition: mg_processing.cpp:120
Bstring::base
Bstring base()
Definition: Bstring.cpp:508
project_set_views_from_images
int project_set_views_from_images(Bproject *project)
Gets views from particle images.
Definition: mg_img_proc.cpp:1033
Bparticle
Definition: mg_processing.h:89
random_numbers.h
Header file for functions for creating random images.
project_reset_origins
int project_reset_origins(Bproject *project)
Resets particle origins to nominal values.
Definition: mg_img_proc.cpp:690
Bmicrograph::block
int block
Definition: mg_processing.h:204
Bstring
Definition: Bstring.h:29
project_check_particles
int project_check_particles(Bproject *project)
Checks particle numbers and box sizes.
Definition: mg_img_proc.cpp:548
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
project_create_from_image
Bproject * project_create_from_image(Bimage *p, Bstring type)
Creates a project structure using image file names.
Definition: mg_img_proc.cpp:67
micrograph_get_size
Vector3< long > micrograph_get_size(Bmicrograph *mg)
Gets the size of a micrograph.
Definition: mg_img_proc.cpp:602
Vector3::floor
Vector3 floor(int places)
Definition: Vector3.h:206
Bproject::select
int select
Definition: mg_processing.h:339
Breconstruction::bad_radius
double bad_radius
Definition: mg_processing.h:299
Breconstruction::select
long select
Definition: mg_processing.h:283
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
Bfilament::ffil
Bstring ffil
Definition: mg_processing.h:130
project_change_pixel_size
int project_change_pixel_size(Bproject *project, double new_pixel_size, Bstring mgpath, Bstring partpath)
Changes all the micrograph fields linked to the pixel size.
Definition: mg_img_proc.cpp:1414
filament_add
Bfilament * filament_add(Bfilament **fil, int pid)
Adds a filament parameter structure to a linked list.
Definition: mg_processing.cpp:625
Breconstruction::ffil
Bstring ffil
Definition: mg_processing.h:289
Breconstruction::bad
Bbadarea * bad
Definition: mg_processing.h:306
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
bround
double bround(double value, int places)
Rounds a value to a specified number of decimal places.
Definition: math_util.cpp:39
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:308
project_write_particle_classes
int project_write_particle_classes(Bproject *project)
Writes particles to different stacks based on class.
Definition: mg_img_proc.cpp:849
Bfilnode::next
Bfilnode * next
Definition: mg_processing.h:116
Bmicrograph::bad
Bbadarea * bad
Definition: mg_processing.h:241
mg_img_scale
Bstring mg_img_scale(Bstring &filename, Bstring &path, Bstring &insert, double scale, Vector3< double > origin, double pixel_size)
Definition: mg_img_proc.cpp:1128
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
Breconstruction::block
int block
Definition: mg_processing.h:284
mg_processing.h
Header file for micrograph processing.
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Breconstruction::voxel_size
double voxel_size
Definition: mg_processing.h:292
rwimg.h
Header file for 2D and 3D image I/O.
Bimage::images
long images()
Definition: Bimage.h:491
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:233
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
Bstring::empty
bool empty()
Definition: Bstring.h:71
Vector3::volume
double volume()
Definition: Vector3.h:235
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
project_create_from_images
Bproject * project_create_from_images(Bstring *file_list, Bstring type)
Creates a project structure using image file names.
Definition: mg_img_proc.cpp:224
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
project_scale_box
int project_scale_box(Bproject *project, double scale, Bstring mgpath, Bstring partpath, Bstring insert)
Changes all the micrograph fields linked to the box size and write new particle files.
Definition: mg_img_proc.cpp:1187
Bfilnode::loc
Vector3< double > loc
Definition: mg_processing.h:118
micrograph_add
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Definition: mg_processing.cpp:461
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
Breconstruction::id
Bstring id
Definition: mg_processing.h:282
math_util.h
Header file for general utilities.
Bfilament
Definition: mg_processing.h:128
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201