Bsoft  2.1.0
Bernard's software package
mg_img_proc.cpp
Go to the documentation of this file.
1 
9 #include "mg_processing.h"
10 #include "mg_select.h"
11 #include "mg_ctf.h"
12 #include "img_combine.h"
13 #include "qsort_functions.h"
14 #include "rwimg.h"
15 #include "linked_list.h"
16 #include "math_util.h"
17 #include "random_numbers.h"
18 #include "utilities.h"
19 
20 // Declaration of global variables
21 extern int verbose; // Level of output to the screen
22 
39 {
40  type = type.lower();
41 
42  if ( type.contains("micro") ) type = "mg";
43  else if ( type.contains("frame") ) type = "frame";
44  else if ( type.contains("rec") ) type = "rec";
45  else if ( type.contains("part") ) type = "part";
46  else if ( type.contains("fil") ) type = "fil";
47  else if ( type.contains("power") ) type = "ps";
48  else if ( type.contains("trans") ) type = "ft";
49 
50  return type;
51 }
52 
70 {
71  long j, k, pid, nid, flen, finc(1);
72  Vector3<double> pixel_size(p->sampling(0));
74  Bfield* field = NULL;
75  Bmicrograph* mg = NULL;
76  Breconstruction* rec = NULL;
77  Bframe* frame = NULL;
78  Bparticle* part = NULL;
79  Bparticle** partlist = NULL;
80  Bfilament* fil = NULL;
81  Bfilament** fillist = NULL;
82  Bfilnode* fnode = NULL;
83  Vector3<double> start, fildir;
84  Bstring id, base(p->file_name());
85  base = base.alnum();
86 
87  type = image_type(type);
88 
89  if ( type.length() < 1 ) {
90  if ( p->images() == 1 ) {
91  if ( p->sizeZ() > 1 ) {
92  type = "rec"; // Assume reconstructions
93  project->select = 1;
94  } else type = "mg"; // Assume micrographs
95  } else {
96  if ( p->sizeX() != p->sizeY() ) type = "fil"; // Assume filaments
97  else type = "part"; // Assume particles
98  if ( p->sizeZ() > 1 ) project->select = 1;
99  }
100  }
101 
102  if ( project->select < 1 ) {
103  if ( type == "frame" ) if ( p->sizeZ() > 1 ) p->slices_to_images();
104  field = field_add(&project->field, base);
105  if ( verbose & VERB_FULL )
106  cout << "Creating field \"" << field->id << endl;
107  k = 1;
108  if ( type == "mg" ) k = p->images();
109  for ( j=0; j<k; j++ ) {
110  id = base;
111  if ( k > 1 ) id += Bstring(j+1, "_%03d");
112  mg = micrograph_add(&field->mg, id);
113  if ( verbose & VERB_FULL )
114  cout << "Micrograph \"" << mg->id << endl;
115  if ( type == "mg" ) mg->fmg = p->file_name();
116  else if ( type == "frame" ) mg->fframe = p->file_name();
117  mg->img_num = j;
118  mg->block = j;
119  mg->pixel_size = pixel_size;
120  mg->intensity = p->image[j].average();
121  if ( type == "mg" ) mg->origin = p->image[j].origin();
122  mg->matrix = p->image[j].view().matrix();
123  mg->select = 1;
124  }
125  if ( type == "frame" ) {
126  k = p->images();
127  mg->origin = p->size()/2;
128  mg->intensity = 0;
129  for ( j=0; j<k; j++ ) {
130  frame = frame_add(&mg->frame, j+1);
131  frame->shift = p->image[j].origin() - mg->origin;
132  mg->intensity += p->image[j].average();
133  }
134  }
135  mg = field_find_zero_tilt_mg(field);
136  field->origin = mg->origin;
137  if ( type == "part" ) {
138  mg->fpart = p->file_name();
139  partlist = &mg->part;
140  pid = 0;
141  if ( verbose & VERB_FULL )
142  cout << " with " << p->images() << " particles";
143  } else if ( type == "fil" ) {
144  mg->ffil = p->file_name();
145  fillist = &mg->fil;
146  fildir = Vector3<double>(1,0,0);
147  start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, 0);
148  mg->filament_width = p->sizeY();
149  if ( p->sizeX() < p->sizeY() ) {
150  mg->filament_width = p->sizeX();
151  fildir = Vector3<double>(0,1,0);
152  start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, 0);
153  }
154  finc = (long) mg->filament_width/2;
155  pid = 0;
156  if ( verbose & VERB_FULL )
157  cout << " with " << p->images() << " filaments";
158  }
159  if ( verbose & VERB_FULL )
160  cout << endl;
161  } else {
163  if ( verbose & VERB_FULL )
164  cout << "Creating reconstruction \"" << rec->id << "\"" << endl;
165  if ( type == "rec" ) rec->frec = p->file_name();
166  else if ( type == "part" ) rec->fpart = p->file_name();
167  else if ( type == "fil" ) rec->ffil = p->file_name();
168  rec->voxel_size = pixel_size;
169  if ( type == "rec" ) rec->origin = p->image->origin();
170  rec->select = 1;
171  if ( type == "part" ) partlist = &rec->part;
172  if ( type == "fil" ) {
173  fillist = &rec->fil;
174  fildir = Vector3<double>(1,0,0);
175  start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, p->sizeY()/2);
176  rec->filament_width = p->sizeY();
177  if ( p->sizeX() < p->sizeY() ) {
178  rec->filament_width = p->sizeX();
179  fildir = Vector3<double>(0,1,0);
180  start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, p->sizeX()/2);
181  }
182  finc = (long) rec->filament_width/2;
183  }
184  }
185 
186  if ( partlist ) {
187  for ( j=pid=0; j<p->images(); j++ ) {
188  part = particle_add(partlist, ++pid);
189  part->pixel_size = pixel_size;
190  part->ori = p->image[j].origin();
191  if ( fabs(part->ori[0] - p->sizeX()/2) > p->sizeX()/4 ) part->ori[0] = p->sizeX()/2;
192  if ( fabs(part->ori[1] - p->sizeY()/2) > p->sizeY()/4 ) part->ori[1] = p->sizeY()/2;
193  if ( fabs(part->ori[2] - p->sizeZ()/2) > p->sizeZ()/4 ) part->ori[2] = p->sizeZ()/2;
194  part->view = p->image[j].view();
195  part->sel = j+1;
196  }
197  }
198 
199  if ( fillist ) {
200  flen = p->sizeX() - 2*finc;
201  if ( p->sizeY() > p->sizeX() ) flen = p->sizeY() - 2*finc;
202  for ( j=0; j<p->images(); j++ ) {
203  fil = filament_add(fillist, ++pid);
204  for ( nid = 0, k = 0; k < flen; k += finc ) {
205  fnode = filament_node_add(&fil->node, ++nid);
206  fnode->loc = start + fildir * k;
207  }
208  }
209  }
210 
211  return project;
212 }
213 
231 {
232  if ( file_list->empty() ) {
233  error_show("Error in project_create_from_images: No filenames given to create a project!", __FILE__, __LINE__);
234  return NULL;
235  }
236 
237  type = image_type(type);
238 
239  Bimage* p = read_img(*file_list, 0, -1);
240 
241  if ( !p ) {
242  cerr << "Error: Input image file " << *file_list << " not found!" << endl;
243  return NULL;
244  }
245 
246  int multi(0); // Flag for multiple files
247 
248  if ( type.length() < 1 ) {
249  if ( p->images() == 1 ) {
250  if ( p->sizeZ() > 1 ) type = "rec"; // Assume reconstructions
251  else type = "mg"; // Assume micrographs
252  } else {
253  if ( p->sizeX() != p->sizeY() ) type = "fil"; // Assume filaments
254  else type = "part"; // Assume particles
255  }
256  }
257 
258 // if ( type == "part" && p->images() == 1 ) multi = 1; // Single particle files - assume one mg or rec only
259 
260  if ( verbose )
261  cout << "Creating a project from images of type \"" << type << "\"" << endl << endl;
262 
263  if ( verbose & VERB_DEBUG )
264  cout << "DEBUG project_create_from_images: type=" << type << " multi=" << multi << endl;
265 
266  long i, j, k, pid(0), nid, flen, finc(1);
268  Bfield* field = NULL;
269  Bmicrograph* mg = NULL;
270  Breconstruction* rec = NULL;
271  Bframe* frame = NULL;
272  Bparticle* part = NULL;
273  Bparticle** partlist = NULL;
274  Bfilament* fil = NULL;
275  Bfilament** fillist = NULL;
276  Bfilnode* fnode = NULL;
277  Bstring* thisfile = NULL;
278  Bstring base("1"), id;
279  Vector3<double> start, fildir;
280 
281  if ( ( type == "part" || type == "mg" || type == "frame" ) && multi ) {
282  if ( type == "frame" ) if ( p->sizeZ() > 1 ) p->slices_to_images();
283  if ( p->sizeZ() == 1 ) {
284  field = field_add(&project->field, base);
285  mg = micrograph_add(&field->mg, base);
286  if ( verbose & VERB_FULL )
287  cout << "Creating field \"" << field->id << "\", micrograph \"" << mg->id << "\"" << endl;
288  mg->select = 1;
289  if ( type == "part" ) partlist = &mg->part;
290  if ( type == "fil" ) fillist = &mg->fil;
291  } else {
293  if ( verbose & VERB_FULL )
294  cout << "Creating reconstruction \"" << rec->id << "\"" << endl;
295  rec->select = 1;
296  if ( type == "part" ) partlist = &rec->part;
297  if ( type == "fil" ) fillist = &rec->fil;
298  }
299  }
300 
301  delete p;
302 
303  for ( i=0, thisfile = file_list; thisfile; thisfile = thisfile->next, i++ ) {
304  base = thisfile->base().alnum();
305  p = read_img(*thisfile, 0, -1);
306  if ( !multi ) {
307  partlist = NULL;
308  fillist = NULL;
309  if ( type == "frame" || type == "mg" ) if ( p->sizeZ() > 1 ) p->slices_to_images();
310  if ( p->image->origin().length() < 1 ) p->origin(p->size()/2);
311  if ( p->sizeZ() == 1 ) { // 2D files are assumed to be micrographs
312  field = field_add(&project->field, base);
313  if ( verbose & VERB_FULL )
314  cout << "Creating field \"" << field->id << endl;
315  k = 1;
316  if ( type == "mg" ) k = p->images();
317  for ( j=0; j<k; j++ ) {
318  id = base;
319  if ( k > 1 ) id += Bstring(j+1, "_%03d");
320  mg = micrograph_add(&field->mg, id);
321  if ( verbose & VERB_FULL )
322  cout << "Micrograph \"" << mg->id << endl;
323  if ( type == "mg" ) mg->fmg = *thisfile;
324  else if ( type == "frame" ) mg->fframe = *thisfile;
325  mg->img_num = j;
326  mg->block = i + j;
327  mg->pixel_size = p->sampling(0);
328  mg->intensity = p->image[j].average();
329  if ( type == "mg" ) mg->origin = p->image[j].origin();
330  mg->matrix = p->image[j].view().matrix();
331  mg->select = 1;
332  }
333  if ( type == "frame" ) {
334  k = p->images();
335  mg->origin = p->size()/2;
336  mg->intensity = 0;
337  for ( j=0; j<k; j++ ) {
338  frame = frame_add(&mg->frame, j+1);
339  frame->shift = p->image[j].origin() - mg->origin;
340  mg->intensity += p->image[j].average();
341  }
342  }
343  mg = field_find_zero_tilt_mg(field);
344  field->origin = mg->origin;
345  if ( type == "part" ) {
346  mg->fpart = *thisfile;
347  partlist = &mg->part;
348  pid = 0;
349  if ( verbose & VERB_FULL )
350  cout << " with " << p->images() << " particles";
351  } else if ( type == "fil" ) {
352  mg->ffil = *thisfile;
353  fillist = &mg->fil;
354  pid = 0;
355  if ( verbose & VERB_FULL )
356  cout << " with " << p->images() << " filaments";
357  }
358  if ( verbose & VERB_FULL )
359  cout << endl;
360  } else { // 3D files are assumed to be reconstructions
362  if ( verbose & VERB_FULL )
363  cout << "Creating reconstruction \"" << rec->id << "\"";
364  rec->block = i;
365  rec->select = 1;
366  if ( type == "part" ) {
367  rec->fpart = *thisfile;
368  partlist = &rec->part;
369  pid = 0;
370  if ( verbose & VERB_FULL )
371  cout << " with " << p->images() << " particles";
372  } else if ( type == "fil" ) {
373  rec->ffil = *thisfile;
374  fillist = &rec->fil;
375  pid = 0;
376  if ( verbose & VERB_FULL )
377  cout << " with " << p->images() << " filaments";
378  } else {
379  rec->frec = *thisfile;
380  rec->origin = p->image->origin();
381  }
382  if ( verbose & VERB_FULL )
383  cout << endl;
384  }
385  }
386 
387  if ( mg ) {
388  if ( type == "part" ) {
389  mg->box_size = p->size();
390  } else if ( type == "fil" ) {
391  fildir = Vector3<double>(1,0,0);
392  start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, 0);
393  mg->filament_width = p->sizeY();
394  if ( p->sizeX() < p->sizeY() ) {
395  mg->filament_width = p->sizeX();
396  fildir = Vector3<double>(0,1,0);
397  start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, 0);
398  }
399  finc = (long) mg->filament_width/2;
400  } else if ( type == "ft" || type == "ps" ) {
401  mg->filament_width = p->sizeY();
402  mg->helix_axis = 0;
403  if ( p->sizeX() < p->sizeY() ) {
404  mg->filament_width = p->sizeX();
405  mg->helix_axis = M_PI_2;
406  }
407  }
408  } else if ( rec ) {
409  rec->voxel_size = p->sampling(0);
410  if ( type == "part" ) {
411  rec->box_size = p->size();
412  } else if ( type == "fil" ) {
413  fildir = Vector3<double>(1,0,0);
414  start = Vector3<double>(p->sizeY()/2, p->sizeY()/2, p->sizeY()/2);
415  rec->filament_width = p->sizeY();
416  if ( p->sizeX() < p->sizeY() ) {
417  rec->filament_width = p->sizeX();
418  fildir = Vector3<double>(0,1,0);
419  start = Vector3<double>(p->sizeX()/2, p->sizeX()/2, p->sizeX()/2);
420  }
421  finc = (long) rec->filament_width/2;
422  } else if ( type == "ft" || type == "ps" ) {
423  rec->filament_width = p->sizeX();
424  if ( p->sizeY() < rec->filament_width ) rec->filament_width = p->sizeY();
425  if ( p->sizeZ() < rec->filament_width ) rec->filament_width = p->sizeZ();
426  }
427  }
428 
429  if ( partlist ) {
430  for ( j=0; j<p->images(); j++ ) {
431  part = particle_add(partlist, ++pid);
432  part->ori = p->image[j].origin();
433  if ( fabs(part->ori[0] - p->sizeX()/2) > p->sizeX()/4 ) part->ori[0] = p->sizeX()/2;
434  if ( fabs(part->ori[1] - p->sizeY()/2) > p->sizeY()/4 ) part->ori[1] = p->sizeY()/2;
435  if ( fabs(part->ori[2] - p->sizeZ()/2) > p->sizeZ()/4 ) part->ori[2] = p->sizeZ()/2;
436  part->view = p->image[j].view();
437 // cout << part->id << tab << part->view << endl;
438 // part->sel = 1;
439  part->sel = j+1;
440  }
441  if ( multi ) part->fpart = *thisfile;
442  }
443 
444  if ( fillist ) {
445  flen = p->sizeX() - 2*finc;
446  if ( p->sizeY() > p->sizeX() ) flen = p->sizeY() - 2*finc;
447  for ( j=0; j<p->images(); j++ ) {
448  fil = filament_add(fillist, ++pid);
449  for ( nid = 0, k = 0; k < flen; k += finc ) {
450  fnode = filament_node_add(&fil->node, ++nid);
451  fnode->loc = start + fildir * k;
452  }
453  }
454  if ( multi ) fil->ffil = *thisfile;
455  }
456 
457  delete p;
458  }
459 
460  return project;
461 }
462 
473 {
474  long i;
475  Bfield* field;
476  Bmicrograph* mg, *mg1;
477  Bstring* file_list = NULL;
478  Bimage* pcat = NULL;
479 
480  Bstring rawstring, filename;
481  Vector3<long> nusize;
482 
483  for ( field = project->field; field; field = field->next ) {
484  for ( mg = mg1 = field->mg; mg; mg = mg->next )
485  if ( mg->fmg != mg1->fmg )
486  string_add(&file_list, mg->fmg);
487  if ( file_list ) {
488  if ( verbose )
489  cout << "Catenating micrographs in field " << field->id << endl;
490 // filename = file_list->common(*(file_list->next));
491  filename = field->id;
492  filename += "." + file_list->extension();
493  cout << "New file name = " << filename << endl;
494  pcat = img_catenate(file_list, rawstring, Unknown_Type,
495  nusize, 0, FILL_USER, 0, 0, 0);
496  if ( verbose )
497  cout << "Writing concatenated file " << filename << endl;
498  write_img(filename, pcat, 0);
499  for ( i=0, mg = field->mg; mg; mg = mg->next, ++i ) {
500  mg->fmg = filename;
501  mg->img_num = i;
502  }
503  }
504  }
505 
506  return 0;
507 }
508 
519 Bimage* particle_read_img(Bparticle* part, int readflag)
520 {
521  if ( !part ) return NULL;
522 
523  Bstring filename(part->fpart);
524  long img_num(0);
525 
526  if ( !part->mg ) cerr << "Error: no micrograph for particle " << part->id << endl;
527 
528  if ( filename.length() < 2 ) {
529  if ( part->mg ) {
530  filename = part->mg->fpart;
531  img_num = part->id - 1;
532  } else if ( part->rec ) {
533  filename = part->rec->fpart;
534  img_num = part->id - 1;
535  }
536  }
537 
538  if ( verbose & VERB_PROCESS )
539  cout << "Particle image filename:" << tab << filename << " (" << img_num << ")" << endl;
540 
541  Bimage* p = NULL;
542 
543  if ( filename.length() ) {
544  p = read_img(filename, readflag, img_num);
545  if ( !p ) {
546  error_show("Particle file not read", __FILE__, __LINE__);
547  return NULL;
548  }
549  }
550 
551  return p;
552 }
553 
565 int particle_write_img(Bparticle* part, Bimage* p, int compression)
566 {
567  if ( !part ) return 0;
568 
569  Bstring filename(part->fpart);
570  long img_num(p->images());
571 
572  if ( !part->mg ) cerr << "Error: no micrograph for particle " << part->id << endl;
573 
574  if ( filename.length() < 2 ) {
575  if ( part->mg )
576  filename = part->mg->fpart;
577  else if ( part->rec )
578  filename = part->rec->fpart;
579  }
580 
581  if ( verbose & VERB_PROCESS )
582  cout << "Particle image filename:" << tab << filename << " (" << img_num << ")" << endl;
583 
584  if ( filename.length() ) {
585  write_img(filename, p, compression);
586  if ( !p ) {
587  error_show("Particle file not written", __FILE__, __LINE__);
588  return 0;
589  }
590  }
591 
592  return 1;
593 }
594 
605 {
606  if ( !project ) return -1;
607 
608  int oldverbose = verbose;
609  verbose = 0;
610 
611  int err(0);
612  long n;
613  Bimage* p = NULL; // image currently being processed
614  Bfield* field = NULL; // field-of-view currently being processed
615  Bmicrograph* mg = NULL; // micrograph currently being processed
616  Bparticle* part = NULL; // particle currently being processed
617 
618  cout << "Checking particle numbers:" << endl;
619 
620  for ( field = project->field; field; field = field->next) {
621  for ( mg = field->mg; mg; mg = mg->next) if ( mg->fpart.length() ) {
622  p = read_img(mg->fpart, 0, -1);
623  if ( verbose & VERB_DEBUG )
624  cout << "DEBUG project_check_particles: " << mg->fpart << ":" << p->images() << endl;
625  if ( p ) {
626  mg->box_size = p->size();
627  for ( n=0, part = mg->part; part; part = part->next, n++ ) {
628  if ( part->pixel_size[0] < 0.01 )
629  part->pixel_size = mg->pixel_size;
630  if ( part->ori[0]*part->ori[1] < mg->box_size.volume()/16 )
631  part->ori += mg->box_size/2;
632  }
633  if ( n != p->images() ) {
634  cerr << "Error: Micrograph " << mg->id << " has " << n << " particles," << endl;
635  cerr << " but particle image file " << p->file_name() << " has " << p->images() << " images!" << endl;
636  err--;
637  } else {
638  cout << mg->id << ": " << n << " = " << p->images() << endl;
639  }
640  delete p;
641  p = NULL;
642  }
643  }
644  }
645 
646  verbose = oldverbose;
647 
648  return err;
649 }
650 
660 {
661  Bimage* p = NULL;
662 
663  if ( mg->fmg.length() ) {
664  p = read_img(mg->fmg, 0, mg->img_num);
665  if ( !p )
666  error_show("micrograph_intensity", __FILE__, __LINE__);
667  else {
668  if ( p->standard_deviation() < 1e-10 ) {
669  delete p;
670  p = read_img(mg->fmg, 1, mg->img_num);
671  p->statistics();
672  }
673  mg->intensity = p->image->average();
674  delete p;
675  }
676  }
677 
678  return mg->intensity;
679 }
680 
690 {
691  Bfield* field;
692  Bmicrograph* mg;
693 
694  if ( verbose & VERB_FULL )
695  cout << "Getting the average micrograph intensities" << endl << endl;
696 
697  for ( field = project->field; field; field = field->next )
698  for ( mg = field->mg; mg; mg = mg->next )
700 
701  return 0;
702 }
703 
713 {
714  Vector3<long> size;
715 
716  Bimage* p = NULL;
717 
718  if ( mg->fmg.length() )
719  p = read_img(mg->fmg, 0, 0);
720  else if ( mg->fframe.length() )
721  p = read_img(mg->fframe, 0, 0);
722 
723  if ( !p )
724  error_show("micrograph_get_size", __FILE__, __LINE__);
725  else {
726  size = p->size();
727  delete p;
728  }
729 
730  return size;
731 }
732 
742 {
743  Vector3<double> origin;
744 
745  Bimage* p = NULL;
746 
747  if ( mg->fmg.length() )
748  p = read_img(mg->fmg, 0, 0);
749  else if ( mg->fframe.length() )
750  p = read_img(mg->fframe, 0, 0);
751 
752  if ( !p )
753  error_show("micrograph_get_nominal_origin", __FILE__, __LINE__);
754  else {
755  origin = Vector3<double>(p->size()/2);
756  delete p;
757  }
758 
759  return origin;
760 }
761 
771 {
772  Bmicrograph* mg;
773  Bimage* p = NULL;
774 
775  if ( verbose & VERB_FULL )
776  cout << "Setting nominal micrograph origins" << endl << endl;
777 
778  for ( mg = project->field->mg; mg; mg = mg->next ) {
779  p = read_img(mg->fmg, 0, mg->img_num);
780  if ( !p )
781  error_show("project_set_nominal_mg_origins", __FILE__, __LINE__);
782  else {
783  mg->origin = p->size()/2;
784  delete p;
785  }
786  }
787 
788  return 0;
789 }
790 
801 {
802  if ( !project ) return 0;
803  if ( !project->field ) return 0;
804  if ( !project->field->mg ) return 0;
805  if ( !project->field->mg->part ) return 0;
806 
807  Bfield* field;
808  Bmicrograph* mg;
809  Bparticle* part;
810  Bimage* p;
811 
812  if ( verbose & VERB_FULL )
813  cout << "Resetting origins" << endl << endl;
814 
815  for ( field = project->field; field; field = field->next )
816  for ( mg = field->mg; mg; mg = mg->next ) {
817  if ( mg->fpart.length() ) p = read_img(mg->fpart, 0, -1);
818  else p = read_img(mg->fmg, 0, -1);
819  if ( !p )
820  error_show("project_reset_origins", __FILE__, __LINE__);
821  for ( part = mg->part; part; part = part->next )
822  part->ori = p->size()/2;
823  delete p;
824  }
825 
826  return 0;
827 }
828 
840 {
841  if ( !project ) return -1;
842 
843  Bimage* p = NULL; // image currently being processed
844  Bfield* field = NULL; // field-of-view currently being processed
845  Bmicrograph* mg = NULL; // micrograph currently being processed
846  Bparticle* part = NULL; // particle currently being processed
847 
848  for ( field = project->field; field; field = field->next) {
849  for ( mg = field->mg; mg; mg = mg->next) {
850  p = read_img(mg->fpart, 1, -1);
851  for ( part = mg->part; part; part = part->next )
852  p->image[part->id-1].origin(part->ori);
853  write_img(mg->fpart, p, 0);
854  delete p;
855  }
856  }
857 
858  return 0;
859 }
860 
868 {
869  if ( !project ) return -1;
870 
871  long nsel(0);
872  Bimage* p = NULL; // image currently being processed
873  Bfield* field = NULL; // field-of-view currently being processed
874  Bmicrograph* mg = NULL; // micrograph currently being processed
875  Bparticle* part = NULL; // particle currently being processed
876  Vector3<double> min, max;
877 
878  for ( field = project->field; field; field = field->next) {
879  for ( mg = field->mg; mg; mg = mg->next) {
880  p = read_img(mg->fmg, 0, 0);
881  min = mg->box_size/2;
882  max = p->size() - min;
883  if ( verbose & VERB_DEBUG )
884  cout << "DEBUG project_delesect_edge_particles: limits:" << tab << min << tab << max << endl;
885  for ( part = mg->part; part; part = part->next ) if ( part->sel ) {
886  if ( part->loc >= min || part->loc <= max ) nsel++;
887  else part->sel = 0;
888  }
889  delete p;
890  }
891  }
892 
893  return 0;
894 }
895 
905 {
906  if ( !project ) return -1;
907 
908  Bimage* p = NULL; // image currently being processed
909  Bfield* field = NULL; // field-of-view currently being processed
910  Bmicrograph* mg = NULL; // micrograph currently being processed
911  Bparticle* part = NULL; // particle currently being processed
912 
913  for ( field = project->field; field; field = field->next) {
914  for ( mg = field->mg; mg; mg = mg->next) if ( mg->fpart.length() ) {
915  p = particle_read_img(mg->part, 0);
916  if ( p ) {
917  mg->box_size = p->size();
918  delete p;
919  for ( part = mg->part; part; part = part->next )
920  if ( part->ori[0]*part->ori[1] < mg->box_size.volume()/16 )
921  part->ori += mg->box_size/2;
922  }
923  }
924  }
925 
926  return 0;
927 }
928 
938 {
939  Vector3<long> size;
940 
941  Bimage* p = particle_read_img(part, 0);
942 
943  if ( p ) {
944  size = p->size();
945  delete p;
946  }
947 
948  return size;
949 }
950 
960 {
961  if ( !project ) return -1;
962 
963  long i, n(0);
964  Bfield* field = NULL;
965  Bmicrograph* mg = NULL;
966  Bparticle* part = NULL;
967  Bimage* p = NULL;
968  Bimage* pt = NULL;
969  Bstring filename;
970 
971  for ( field = project->field; field; field = field->next)
972  for ( mg = field->mg; mg; mg = mg->next)
973  for ( part = mg->part; part; part = part->next )
974  if ( part->sel > n ) n = part->sel;
975 
976  long* cn = new long[n];
977  Bimage** pn = new Bimage*[n];
978 
979  if ( verbose )
980  cout << "Writing " << n << " particle classes to separate files:" << endl;
981 
982  for ( field = project->field; field; field = field->next) {
983  for ( mg = field->mg; mg; mg = mg->next) {
984  if ( n ) {
985  p = read_img(mg->fpart, 1, -1);
986  for ( i=0; i<n; i++ ) cn[i] = 0;
987  for ( part = mg->part; part; part = part->next )
988  if ( part->sel > 0 ) cn[part->sel-1]++;
989  for ( i=0; i<n; i++ ) if ( cn[i] ) {
990  if ( verbose & VERB_FULL )
991  cout << "Creating image with " << cn[i] << " particles" << endl;
992  pn[i] = p->copy_header(cn[i]);
993  pn[i]->data_alloc();
994  }
995  for ( i=0; i<n; i++ ) cn[i] = 0;
996  for ( part = mg->part; part; part = part->next )
997  if ( part->sel > 0 ) {
998  pt = p->extract(part->id-1);
999  pn[part->sel-1]->replace(cn[part->sel-1]++, pt);
1000  delete pt;
1001  }
1002  delete p;
1003  for ( i=0; i<n; i++ ) if ( cn[i] ) {
1004  filename = mg->fpart.pre_rev('.') + Bstring(i+1, "_%03d.") + mg->fpart.post_rev('.');
1005  if ( verbose )
1006  cout << "Writing " << filename << " with " << cn[i] << " particles" << endl;
1007  write_img(filename, pn[i], 0);
1008  delete pn[i];
1009  }
1010  }
1011  }
1012  }
1013 
1014  delete[] cn;
1015  delete[] pn;
1016 
1017  return 0;
1018 }
1019 
1030 {
1031  if ( ! project->class_avg ) return 0;
1032  if ( list.length() < 1 ) return 0;
1033 
1034  long navg(0), i, id;
1035  Bparticle* part, *part_list, *part_nu;
1036 
1037  for ( part = project->class_avg; part; part = part->next ) navg++;
1038 
1039 // int* numsel = new int[navg];
1040 // select_numbers(list, navg, numsel);
1041  vector<int> numsel = select_numbers(list, navg);
1042 
1043  Bstring filename(project->class_avg->fpart);
1044  Bimage* pavg = read_img(filename, 1, -1);
1045  pavg->delete_images(list);
1046 
1047  filename = filename.pre_rev('.') + "_del." + filename.post_rev('.');
1048  write_img(filename, pavg, 0);
1049 
1050  for ( i=id=0, part_list = NULL, part = project->class_avg; part; part = part->next, ++i ) {
1051  if ( !numsel[i] ) {
1052  part_nu = particle_copy(&part_list, part);
1053  part_nu->id = ++id;
1054  part_nu->fpart = filename;
1055  }
1056  }
1057 
1059  project->class_avg = part_list;
1060 
1061 // delete[] numsel;
1062 
1063  if ( verbose & VERB_PROCESS )
1064  cout << "Number of class averages: " << id << endl << endl;
1065 
1066  return 0;
1067 }
1068 
1082 {
1083  Bfield* field;
1084  Bmicrograph* mg;
1085  Breconstruction* rec;
1086  Bparticle* part;
1087  Bbadarea* bad;
1088  Bimage* p = NULL;
1089  int fz = flip/4;
1090  int fy = (flip - 4*fz)/2;
1091  int fx = flip - 4*fz - 2*fy;
1092 
1093  if ( verbose & VERB_PROCESS ) {
1094  cout << "Flipping locations along ";
1095  if ( fx ) cout << "x";
1096  if ( fy ) cout << "y";
1097  if ( fz ) cout << "z";
1098  cout << endl;
1099  }
1100 
1101  if ( project->select ) {
1102  for ( rec = project->rec; rec; rec = rec->next ) {
1103  if ( rec->frec.length() ) p = read_img(rec->frec, 0, -1);
1104  for ( part = rec->part; part; part = part->next ) {
1105  if ( fx ) part->loc[0] = p->sizeX() - part->loc[0];
1106  if ( fy ) part->loc[1] = p->sizeY() - part->loc[1];
1107  if ( fz ) part->loc[2] = p->sizeZ() - part->loc[2];
1108  }
1109  for ( bad = rec->bad; bad; bad = bad->next ) {
1110  if ( fx ) bad->loc[0] = p->sizeX() - bad->loc[0];
1111  if ( fy ) bad->loc[1] = p->sizeY() - bad->loc[1];
1112  if ( fz ) bad->loc[2] = p->sizeZ() - bad->loc[2];
1113  }
1114  delete p;
1115  }
1116  } else {
1117  for ( field = project->field; field; field = field->next ) {
1118  for ( mg = field->mg; mg; mg = mg->next ) {
1119  if ( mg->fmg.length() ) p = read_img(mg->fmg, 0, -1);
1120  else if ( mg->fframe.length() ) p = read_img(mg->fframe, 0, -1);
1121  for ( part = mg->part; part; part = part->next ) {
1122  if ( fx ) part->loc[0] = p->sizeX() - part->loc[0];
1123  if ( fy ) part->loc[1] = p->sizeY() - part->loc[1];
1124  if ( fz ) part->loc[2] = p->sizeZ() - part->loc[2];
1125  }
1126  for ( bad=mg->bad; bad; bad=bad->next ) {
1127  if ( fx ) bad->loc[0] = p->sizeX() - bad->loc[0];
1128  if ( fy ) bad->loc[1] = p->sizeY() - bad->loc[1];
1129  if ( fz ) bad->loc[2] = p->sizeZ() - bad->loc[2];
1130  }
1131  delete p;
1132  }
1133  }
1134  }
1135 
1136  return 0;
1137 }
1138 
1145 {
1146  if ( !project ) return 0;
1147 
1148  long n;
1149  Bfield* field;
1150  Bmicrograph* mg;
1151  Bparticle* part;
1152  Bimage* p = NULL;
1153 
1154  if ( verbose & VERB_PROCESS )
1155  cout << "Getting parameters from picked particle files" << endl << endl;
1156 
1157  for ( field = project->field; field; field = field->next ) {
1158  for ( mg = field->mg; mg; mg = mg->next ) {
1159  if ( mg->fpart.length() && ( p = read_img(mg->fpart, 0, -1) ) ) {
1160  if ( verbose & VERB_DEBUG )
1161  cout << "DEBUG project_set_views_from_images: File=" << mg->fpart << " particles=" << p->images() << endl;
1162  if ( p->images() < 2 ) mg->fmg = mg->fpart;
1163  if ( !mg->part )
1164  for ( n=0; n<p->images(); n++ ) particle_add(&mg->part, n+1);
1165  if ( mg->pixel_size[0] < 0.01 && p->sampling(0)[0] > 0 )
1166  mg->pixel_size = p->sampling(0);
1167  for ( part = mg->part; part; part = part->next ) {
1168  n = part->id - 1;
1169  if ( part->pixel_size[0] < 0.01 && p->sampling(0)[0] > 0 )
1170  part->pixel_size = p->sampling(0);
1171  part->ori = p->size()/2;
1172  if ( p->image[n].origin()[0] >= 0 && p->image[n].origin()[0] < p->sizeX() )
1173  part->ori[0] = p->image[n].origin()[0];
1174  if ( p->image[n].origin()[1] >= 0 && p->image[n].origin()[1] < p->sizeY() )
1175  part->ori[1] = p->image[n].origin()[1];
1176  if ( p->image[n].origin()[2] >= 0 && p->image[n].origin()[2] < p->sizeZ() )
1177  part->ori[2] = p->image[n].origin()[2];
1178  part->view = p->image[n].view();
1179  }
1180  delete p;
1181  }
1182  }
1183  }
1184 
1185  return 0;
1186 }
1187 
1194 {
1195  if ( !project ) return 0;
1196 
1197  long n;
1198  Bfield* field;
1199  Bmicrograph* mg;
1200  Bparticle* part;
1201  Bimage* p = NULL;
1202 
1203  if ( verbose & VERB_PROCESS )
1204  cout << "Setting view parameters in picked particle files" << endl << endl;
1205 
1206  for ( field = project->field; field; field = field->next ) {
1207  for ( mg = field->mg; mg; mg = mg->next ) {
1208  p = read_img(mg->fpart, 1, -1);
1209  if ( p ) {
1210  if ( verbose & VERB_DEBUG )
1211  cout << "DEBUG project_set_views_in_images: File=" << mg->fpart << " particles=" << p->images() << endl;
1212  if ( p->images() < 2 ) mg->fmg = mg->fpart;
1213  if ( mg->pixel_size[0] > 0 )
1214  p->sampling(mg->pixel_size);
1215  if ( mg->part ) {
1216  for ( part = mg->part; part; part = part->next ) {
1217  n = part->id - 1;
1218  if ( part->pixel_size[0] > 0 )
1219  p->image[n].sampling(part->pixel_size);
1220  p->image[n].origin(p->size()/2);
1221  if ( part->ori[0] < 0 || part->ori[0] >= p->sizeX() )
1222  part->ori[0] = p->sizeX()/2;
1223  if ( part->ori[1] < 0 || part->ori[1] >= p->sizeY() )
1224  part->ori[1] = p->sizeY()/2;
1225  if ( part->ori[2] < 0 || part->ori[2] >= p->sizeZ() )
1226  part->ori[2] = p->sizeZ()/2;
1227  p->image[n].origin(part->ori);
1228  p->image[n].view(part->view);
1229  }
1230  write_img(mg->fpart, p, 0);
1231  }
1232  delete p;
1233  }
1234  }
1235  }
1236 
1237  return 0;
1238 }
1239 
1241  double scale, Vector3<double> origin, Vector3<double> pixel_size)
1242 {
1243  if ( filename.length() < 1 ) return filename;
1244 
1245  Bimage* p = read_img(filename, 1, -1);
1246 
1247  if ( !p ) {
1248  delete p;
1249  return filename;
1250  }
1251 
1252  if ( verbose )
1253  cout << "Binning " << filename << endl;
1254 
1255  p->sampling(pixel_size);
1256 
1257  Bstring nufile(filename);
1258 
1259  if ( nufile.contains("/") ) nufile = nufile.post_rev('/');
1260  nufile = nufile.pre_rev('.') + insert + nufile.post_rev('.');
1261  if ( path.length() ) nufile = path + nufile;
1262 
1263  Vector3<long> size(p->size() * scale);
1264  size = size.max(1);
1265 
1266  Vector3<double> svec(scale, scale, 1);
1267 
1268  Vector3<double> translate = (origin*scale - origin).round(0);
1269 
1270  Matrix3 mat(1);
1271 
1272  Bimage* ps = p->transform(size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1273 
1274  write_img(nufile, ps, 0);
1275 
1276  delete p;
1277  delete ps;
1278 
1279  return nufile;
1280 }
1281 
1299 int project_scale_box(Bproject* project, double scale, Bstring mgpath, Bstring partpath, Bstring insert)
1300 {
1301  if ( !project ) return 0;
1302 
1303  if ( scale <= 0 ) return 0;
1304 
1305  Vector3<long> size;
1306  Vector3<double> shift, origin, translate;
1307  Vector3<double> svec(scale, scale, scale);
1308  Matrix3 mat(1);
1309  Bstring newfile;
1310  Bimage* p = NULL;
1311  Bimage* ps = NULL;
1312 
1313  Bfield* field;
1314  Bmicrograph* mg;
1315  Breconstruction* rec;
1316  Bparticle* part;
1317  Bfilament* fil;
1318  Bfilnode* fnode;
1319  Bbadarea* bad;
1320  Bmarker* mark;
1321 
1322  if ( verbose )
1323  cout << "Scaling by " << scale << endl;
1324 
1325  if ( mgpath == "." || mgpath == "./" ) mgpath = 0;
1326  if ( partpath == "." || partpath == "./" ) partpath = 0;
1327 
1328  if ( mgpath.length() ) {
1329  if ( mgpath[-1] != '/' ) mgpath += "/";
1330  if ( verbose )
1331  cout << "Micrograph path: " << mgpath << endl;
1332  }
1333 
1334  if ( partpath.length() ) {
1335  if ( partpath[-1] != '/' ) partpath += "/";
1336  if ( verbose )
1337  cout << "Particle path: " << partpath << endl;
1338  }
1339 
1340  if ( verbose )
1341  cout << endl;
1342 
1343  if ( !project->select ) {
1344  svec[2] = 1;
1345  for ( field = project->field; field; field = field->next ) {
1346  for ( mg = field->mg; mg; mg = mg->next ) {
1347  if ( verbose & VERB_DEBUG )
1348  cout << "DEBUG project_scale_box: scale=" << scale << endl;
1349 /* mg->pixel_size /= scale;
1350  origin = mg->origin;
1351  mg->origin = mg->origin * scale;
1352  p = NULL;
1353  if ( mg->fmg.length() ) p = read_img(mg->fmg, 1, -1);
1354  if ( p ) {
1355  newfile = mg->fmg;
1356  if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1357  newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1358  if ( mgpath.length() ) newfile = mgpath + newfile;
1359  mg->fmg = newfile;
1360  size = p->size() * scale;
1361  size = size.max(1);
1362  translate = (mg->origin - origin).round(0);
1363  ps = p->transform(size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1364  ps->sampling(mg->pixel_size);
1365  write_img(mg->fmg, ps, 0);
1366  delete p;
1367  delete ps;
1368  }*/
1369  if ( mg->fmg.length() )
1370  mg->fmg = mg_img_scale(mg->fmg, mgpath, insert, scale, mg->origin, mg->pixel_size);
1371  if ( mg->fframe.length() )
1372  mg->fframe = mg_img_scale(mg->fframe, mgpath, insert, scale, mg->origin, mg->pixel_size);
1373  mg->origin = mg->origin * scale;
1374  mg->pixel_size /= scale;
1375  origin = mg->box_size/2;
1376  mg->box_size = mg->box_size * scale;
1377  mg->box_size = mg->box_size.max(1);
1378  mg->bad_radius = bround(mg->bad_radius*scale, 0);
1379  mg->mark_radius = bround(mg->mark_radius*scale, 0);
1380  for ( part = mg->part; part; part = part->next ) {
1381  part->loc *= scale;
1382  part->pixel_size /= scale;
1383  shift = part->loc.remainder(1);
1384  part->loc = part->loc.floor(0);
1385  part->ori = (part->ori * scale) + shift;
1386  }
1387  for ( fil=mg->fil; fil; fil=fil->next ) {
1388  for ( fnode=fil->node; fnode; fnode=fnode->next )
1389  fnode->loc = (fnode->loc * scale).round(0);
1390  }
1391  for ( bad=mg->bad; bad; bad=bad->next )
1392  bad->loc = (bad->loc * scale).round(0);
1393  for ( mark=mg->mark; mark; mark=mark->next )
1394  mark->loc = (mark->loc * scale).round(0);
1395 /* if ( mg->fpart.length() ) {
1396  p = read_img(mg->fpart, 1, -1);
1397  if ( p ) {
1398  newfile = mg->fpart;
1399  if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1400  newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1401  if ( partpath.length() ) newfile = partpath + newfile;
1402  mg->fpart = newfile;
1403  translate = mg->box_size/2 - origin;
1404  ps = p->transform(mg->box_size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1405  ps->sampling(mg->pixel_size);
1406  write_img(mg->fpart, ps, 0);
1407  delete p;
1408  delete ps;
1409  }
1410  }*/
1411  if ( mg->fpart.length() )
1412  mg->fpart = mg_img_scale(mg->fpart, partpath, insert, scale, origin, mg->pixel_size);
1413  }
1414  }
1415  } else {
1416  for ( rec = project->rec; rec; rec = rec->next ) {
1417  if ( verbose & VERB_DEBUG )
1418  cout << "DEBUG project_scale_box: scale=" << scale << endl;
1419  rec->voxel_size /= scale;
1420  origin = rec->origin;
1421  rec->origin = rec->origin * scale;
1422  p = NULL;
1423  if ( rec->frec.length() ) p = read_img(rec->frec, 1, -1);
1424  if ( p ) {
1425  newfile = rec->frec;
1426  if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1427  newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1428  if ( mgpath.length() ) newfile = mgpath + newfile;
1429  rec->frec = newfile;
1430  size = p->size() * scale;
1431  translate = (rec->origin - origin).round(0);
1432 // img_transform(p, size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1433  ps = p->transform(size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1434  ps->sampling(rec->voxel_size);
1435  write_img(rec->frec, ps, 0);
1436  delete p;
1437  delete ps;
1438  }
1439  rec->box_size = rec->box_size * scale;
1440  rec->bad_radius = bround(rec->bad_radius*scale, 0);
1441  rec->mark_radius = bround(rec->mark_radius*scale, 0);
1442  for ( part=rec->part; part; part=part->next ) {
1443  part->loc *= scale;
1444  part->pixel_size /= scale;
1445  shift = part->loc.remainder(1);
1446  part->loc = part->loc.floor(0);
1447  part->ori = (part->ori * scale) + shift;
1448  }
1449  for ( fil=rec->fil; fil; fil=fil->next ) {
1450  for ( fnode=fil->node; fnode; fnode=fnode->next )
1451  fnode->loc = (fnode->loc * scale).round(0);
1452  }
1453  for ( bad=rec->bad; bad; bad=bad->next )
1454  bad->loc = (bad->loc * scale).round(0);
1455  for ( mark=rec->mark; mark; mark=mark->next )
1456  mark->loc = (mark->loc * scale).round(0);
1457  if ( rec->fpart.length() ) {
1458  p = read_img(rec->fpart, 1, -1);
1459  if ( p ) {
1460  newfile = rec->fpart;
1461  if ( newfile.contains("/") ) newfile = newfile.post_rev('/');
1462  newfile = newfile.pre_rev('.') + insert + newfile.post_rev('.');
1463  if ( partpath.length() ) newfile = partpath + newfile;
1464  rec->fpart = newfile;
1465 // translate = (rec->box_size/2 - origin).round(0);
1466  translate = rec->box_size/2 - origin;
1467 // img_transform(p, rec->box_size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1468  ps = p->transform(rec->box_size, svec, origin, translate, mat, FILL_BACKGROUND, 0);
1469  ps->sampling(rec->voxel_size);
1470  write_img(rec->fpart, ps, 0);
1471  delete p;
1472  delete ps;
1473  }
1474  }
1475  }
1476  }
1477 
1478  return 0;
1479 }
1480 
1495 int project_bin_micrographs(Bproject* project, int bin, Bstring mgpath, Bstring partpath)
1496 {
1497  if ( bin <= 1 ) return -1;
1498 
1499  if ( verbose )
1500  cout << "Binning micrographs by " << bin << endl;
1501 
1502  double scale = 1.0/bin;
1503  Bstring insert(bin, "_b%d.");
1504 
1505  project_scale_box(project, scale, mgpath, partpath, insert);
1506 
1507  return 0;
1508 }
1509 
1527  Vector3<double> new_pixel_size,
1528  Bstring mgpath, Bstring partpath)
1529 {
1530  if ( !project ) return 0;
1531 
1532  if ( new_pixel_size[0] <= 0 ) return 0;
1533 
1534  double scale(0);
1535 
1536  if ( project->select ) {
1537  if ( project->rec )
1538  scale = project->rec->voxel_size[0]/new_pixel_size[0];
1539  } else {
1540  if ( project->field && project->field->mg )
1541  scale = project->field->mg->pixel_size[0]/new_pixel_size[0];
1542  }
1543 
1544  Bstring insert(scale, "_s%3.1lf.");
1545 
1546  if ( scale ) project_scale_box(project, scale, mgpath, partpath, insert);
1547 
1548  return 0;
1549 }
1550 
1551 
qsort_functions.h
Header file for utility functions for use in qsort calls.
Bsub_image::average
double average()
Definition: Bimage.h:119
Bbadarea::loc
Vector3< double > loc
Definition: mg_processing.h:146
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:307
Breconstruction::id
Bstring id
Definition: mg_processing.h:285
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:310
Bmicrograph::filament_width
double filament_width
Definition: mg_processing.h:234
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Vector3::remainder
Vector3 remainder(int divisor)
Definition: Vector3.h:216
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:291
Bframe::shift
Vector3< double > shift
Definition: mg_processing.h:78
Breconstruction::fil
Bfilament * fil
Definition: mg_processing.h:308
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:347
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bproject::select
int select
Definition: mg_processing.h:342
Bparticle::view
View view
Definition: mg_processing.h:102
Bfilament
Definition: mg_processing.h:129
Bstring
Definition: Bstring.h:29
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:121
Breconstruction::voxel_size
Vector3< double > voxel_size
Definition: mg_processing.h:295
Bstring::extension
Bstring extension()
Definition: Bstring.cpp:523
Bparticle
Definition: mg_processing.h:90
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bproject::field
Bfield * field
Definition: mg_processing.h:346
base
string base(string &filename)
Definition: string_util.cpp:28
Breconstruction::filament_width
double filament_width
Definition: mg_processing.h:300
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:236
Vector3< double >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
random_numbers.h
Header file for functions for creating random images.
filament_add
Bfilament * filament_add(Bfilament **fil, int pid)
Adds a filament parameter structure to a linked list.
Definition: mg_processing.cpp:319
Bfilament::next
Bfilament * next
Definition: mg_processing.h:130
Bmicrograph::helix_axis
double helix_axis
Definition: mg_processing.h:229
micrograph_get_nominal_origin
Vector3< double > micrograph_get_nominal_origin(Bmicrograph *mg)
Gets the nominal origin for a micrograph.
Definition: mg_img_proc.cpp:741
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:212
mg_select.h
Header file for micrograph processing.
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Bfield::origin
Vector3< double > origin
Definition: mg_processing.h:263
project_init
Bproject * project_init()
Initializes a micrograph processing project parameter structure.
Definition: mg_processing.cpp:30
Bstring::empty
bool empty()
Definition: Bstring.h:71
FILL_USER
#define FILL_USER
Definition: utilities.h:176
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:105
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:299
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bfield::id
Bstring id
Definition: mg_processing.h:262
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
micrograph_intensity
double micrograph_intensity(Bmicrograph *mg)
Gets the average of a micrograph.
Definition: mg_img_proc.cpp:659
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Breconstruction::mark_radius
double mark_radius
Definition: mg_processing.h:304
Bfield
Definition: mg_processing.h:260
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
mg_img_scale
Bstring mg_img_scale(Bstring &filename, Bstring &path, Bstring &insert, double scale, Vector3< double > origin, Vector3< double > pixel_size)
Definition: mg_img_proc.cpp:1240
M_PI_2
#define M_PI_2
Definition: utilities.h:66
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:544
Bmicrograph::fframe
Bstring fframe
Definition: mg_processing.h:207
Bbadarea
Definition: mg_processing.h:143
Bmicrograph::frame
Bframe * frame
Definition: mg_processing.h:240
Bframe
Definition: mg_processing.h:75
Bmarker
Definition: marker.h:21
Bimage::delete_images
long delete_images(Bstring list, int retain=0)
Retains or deletes sub-images from a multi-image structure.
Definition: Bimage.cpp:2156
Bmicrograph::fil
Bfilament * fil
Definition: mg_processing.h:243
Breconstruction::origin
Vector3< double > origin
Definition: mg_processing.h:296
Bimage::images
long images()
Definition: Bimage.h:504
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:770
project
Bproject * project
Definition: bshow.cpp:33
Matrix3
Definition: Matrix3.h:18
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
micrograph_get_size
Vector3< long > micrograph_get_size(Bmicrograph *mg)
Gets the size of a micrograph.
Definition: mg_img_proc.cpp:712
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bmarker::next
Bmarker * next
Definition: marker.h:22
image_type
Bstring image_type(Bstring type)
Converts an image type string to a standard form.
Definition: mg_img_proc.cpp:38
Bmicrograph::ffil
Bstring ffil
Definition: mg_processing.h:209
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
insert
string insert(string &filename, string ins)
Definition: string_util.cpp:48
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
Bimage::slices_to_images
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
Definition: Bimage.cpp:2074
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:1029
Bmicrograph::origin
Vector3< double > origin
Definition: mg_processing.h:223
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bimage
General image parameter class.
Definition: Bimage.h:177
Bfilament::node
Bfilnode * node
Definition: mg_processing.h:133
Bproject
Definition: mg_processing.h:336
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
Bimage::data_alloc
unsigned char * data_alloc()
Definition: Bimage.h:271
Bbadarea::next
Bbadarea * next
Definition: mg_processing.h:144
Bparticle::sel
long sel
Definition: mg_processing.h:104
Bparticle::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:99
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2830
project_set_views_from_images
int project_set_views_from_images(Bproject *project)
Gets views from particle images.
Definition: mg_img_proc.cpp:1144
Bstring::alnum
Bstring alnum()
Definition: Bstring.cpp:357
project_catenate_micrographs
int project_catenate_micrographs(Bproject *project)
Concatenates all micrograph image files into one file.
Definition: mg_img_proc.cpp:472
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:238
Bfilament::ffil
Bstring ffil
Definition: mg_processing.h:131
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:100
project_mg_avg_intensities
int project_mg_avg_intensities(Bproject *project)
Retrieves the average micrograph intensities.
Definition: mg_img_proc.cpp:689
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
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:69
Bfilnode::next
Bfilnode * next
Definition: mg_processing.h:117
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
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:230
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:233
project_reset_origins
int project_reset_origins(Bproject *project)
Resets particle origins to nominal values.
Definition: mg_img_proc.cpp:800
Breconstruction
Definition: mg_processing.h:283
Bstring::length
long length() const
Definition: Bstring.cpp:263
Breconstruction::select
long select
Definition: mg_processing.h:286
Bmicrograph::matrix
Matrix3 matrix
Definition: mg_processing.h:225
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:206
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:839
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:867
Bproject::class_avg
Bparticle * class_avg
Definition: mg_processing.h:348
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_select.cpp:281
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:937
Vector3::volume
double volume()
Definition: Vector3.h:237
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:221
rwimg.h
Header file for 2D and 3D image I/O.
project_change_pixel_size
int project_change_pixel_size(Bproject *project, Vector3< double > new_pixel_size, Bstring mgpath, Bstring partpath)
Changes all the micrograph fields linked to the pixel size.
Definition: mg_img_proc.cpp:1526
Bfield::next
Bfield * next
Definition: mg_processing.h:261
Bstring::next
Bstring * next
Definition: Bstring.h:31
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:1299
Vector3::floor
Vector3 floor(int places)
Definition: Vector3.h:206
Bimage::copy_header
Bimage * copy_header()
Definition: Bimage.h:658
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:245
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
mg_processing.h
Header file for micrograph processing.
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
Bmicrograph::intensity
double intensity
Definition: mg_processing.h:217
Bmicrograph::block
int block
Definition: mg_processing.h:205
Bsub_image::sampling
void sampling(double x, double y, double z)
Definition: Bimage.h:127
micrograph_add
Bmicrograph * micrograph_add(Bmicrograph **mg, Bstring &mg_id)
Adds a micrograph parameter structure to a linked list.
Definition: mg_processing.cpp:154
Breconstruction::bad_radius
double bad_radius
Definition: mg_processing.h:302
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
project_write_particle_classes
int project_write_particle_classes(Bproject *project)
Writes particles to different stacks based on class.
Definition: mg_img_proc.cpp:959
linked_list.h
Header file for generalized linked list functions.
math_util.h
Header file for general utilities.
Bmicrograph::select
long select
Definition: mg_processing.h:204
Breconstruction::block
int block
Definition: mg_processing.h:287
Breconstruction::ffil
Bstring ffil
Definition: mg_processing.h:292
Bfilnode::loc
Vector3< double > loc
Definition: mg_processing.h:119
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
particle_copy
Bparticle * particle_copy(Bparticle **partlist, Bparticle *part)
Adds one particle onto a list of particle parameters.
Definition: mg_processing.cpp:614
Breconstruction::bad
Bbadarea * bad
Definition: mg_processing.h:309
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:290
frame_add
Bframe * frame_add(Bframe **frame, int pid)
Adds a movie frame parameter structure to a linked list.
Definition: mg_processing.cpp:189
Bstring::base
Bstring base()
Definition: Bstring.cpp:516
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
img_combine.h
Header file for combining two images in various ways.
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:1495
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
bround
double bround(double value, int places)
Rounds a value to a specified number of decimal places.
Definition: math_util.cpp:39
particle_read_img
Bimage * particle_read_img(Bparticle *part, int readflag)
Reads a particle image file.
Definition: mg_img_proc.cpp:519
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:904
Bfilnode
Definition: mg_processing.h:116
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:592
particle_kill
int particle_kill(Bparticle *part)
Frees a list of particles.
Definition: mg_processing.cpp:528
Bmicrograph::bad
Bbadarea * bad
Definition: mg_processing.h:244
reconstruction_add
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Definition: mg_processing.cpp:398
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:349
project_flip_particle_coordinates
int project_flip_particle_coordinates(Bproject *project, int flip)
Reverses one or more particle coordinates.
Definition: mg_img_proc.cpp:1081
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
Bparticle::rec
Breconstruction * rec
Definition: mg_processing.h:106
Bstring::lower
Bstring lower()
Definition: Bstring.cpp:316
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
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:335
Bparticle::id
int id
Definition: mg_processing.h:93
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
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:1193
project_check_particles
int project_check_particles(Bproject *project)
Checks particle numbers and box sizes.
Definition: mg_img_proc.cpp:604
img_catenate
Bimage * img_catenate(Bstring *file_list, Bstring &rawstring, DataType newdatatype, Vector3< long > nusize, int setZslices=0, int fill_type=0, double fill=0, double newavg=0, double newstd=0)
Catenates a list of images into a multi-image structure.
Definition: img_combine.cpp:163
particle_write_img
int particle_write_img(Bparticle *part, Bimage *p, int compression)
Writes a particle image file.
Definition: mg_img_proc.cpp:565
verbose
int verbose
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:284
Vector3::max
Type max()
Definition: Vector3.h:175