Bsoft  2.1.0
Bernard's software package
mg_orient.cpp
Go to the documentation of this file.
1 
9 #include "mg_orient.h"
10 #include "mg_processing.h"
11 #include "rwmg.h"
12 #include "mg_particle_select.h"
13 #include "mg_ctf.h"
14 #include "symmetry.h"
15 #include "linked_list.h"
16 #include "rwimg.h"
17 #include "ps_views.h"
18 #include "utilities.h"
19 
20 #include <fstream>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 
24 
25 // Declaration of global variables
26 extern int verbose; // Level of output to the screen
27 
28 int part_determine_orientation(Bparticle* part, Bimage* proj, Bimage* part_mask,
29  Bimage* prs_mask, Bsymmetry* sym, int bin,
30  double res_lo, double res_hi, double res_polar, int ann_min, int ann_max,
31  double shift_limit, double angle_limit, double edge_radius, int flags,
32  fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D);
33 
34 
35 double correlation_coefficient_adjust(double cc, double std)
36 {
37  int i;
38  double ccc = cc, ccd = 1;
39  double fac = sqrt(2.0)*std;
40 
41  for ( i=0; i<100 && fabs(ccd) > 1e-10; i++ ) {
42  ccd = cc - ccc*ccc*ccc - fac*ccc*(1-ccc);
43  ccc += ccd;
44  }
45 
46 // if ( verbose & VERB_DEBUG )
47 // cout << "DEBUG correlation_coefficient_adjust: i=" << i << " ccd=" << ccd << endl;
48 
49  return ccc;
50 }
51 
66  long number, int bin, int ctf_action, double wiener)
67 {
68  if ( bin < 1 ) bin = 1;
69  if ( bin > 4 ) bin = 4;
70 
72  Bmicrograph* mg = part->mg;
73  Bfield* field = project->field;
74  Bimage* p = NULL;
75  Vector3<double> pixel_size(part->pixel_size);
76 
77  if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
78  else p = read_img(mg->fpart, 1, part->id - 1);
79 
80  if ( pixel_size[0] < 0.01 ) pixel_size = p->sampling(0);
81  if ( pixel_size[0] < 0.01 ) pixel_size = mg->pixel_size;
82 
83  Bimage* pref = new Bimage(Float, TSimple, p->size(), number);
84  pref->sampling(pixel_size);
85  pref->origin(pref->size()/2);
86 
87  delete p;
88 
89  if ( verbose ) {
90  cout << "Preparing particle images as references: " << endl;
91  cout << "Size: " << pref->size() << endl;
92  cout << "Pixel size: " << pixel_size << endl;
93  cout << "Number: " << number << endl;
94  cout << "Binning: " << bin << endl;
95  }
96 
97  long i(0), npart(0);
98 
99  for ( field = project->field; field && npart < number; field = field->next ) {
100  for ( mg = field->mg; mg && npart < number; mg = mg->next ) {
101  for ( part = mg->part; part && npart < number; part = part->next, ++i )
102  if ( i > first ) {
103  if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
104  else p = read_img(mg->fpart, 1, part->id - 1);
105  if ( !p ) {
106  error_show("project_prepare_2D_references", __FILE__, __LINE__);
107  return NULL;
108  }
109  p->change_type(Float);
110  p->sampling(pixel_size);
111  if ( ctf_action && mg->ctf )
112  img_ctf_apply(p, *mg->ctf, ctf_action, wiener, 0, 0);
113  p->rescale_to_avg_std(0, 1);
114  p->shift_background(0);
115  if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->origin(part->ori);
116  else p->origin(p->size()/2);
117  if ( verbose )
118  cout << mg->id << tab << part->id << tab << p->image->origin() << endl;
119  p->center();
120  pref->replace(npart, p);
121  npart++;
122  delete p;
123  }
124  }
125  }
126 
127  if ( bin > 1 ) pref->bin(bin);
128 
129  pref->statistics();
130  pref->shift_background(0);
131 
132  if ( verbose & VERB_DEBUG )
133  write_img("ref.pif", pref, 0);
134 
135  return pref;
136 }
137 
157  int bin, Bsymmetry* sym,
158  double theta_step, double phi_step, double side_ang)
159 {
160  if ( theta_step < SMALLFLOAT || phi_step < SMALLFLOAT ) {
161  if ( theta_step < SMALLFLOAT )
162  cerr << "Error: The theta step size is too small! (" << theta_step*180.0/M_PI << ")" << endl;
163  if ( phi_step < SMALLFLOAT )
164  cerr << "Error: The phi step size is too small! (" << phi_step*180.0/M_PI << ")" << endl;
165  return NULL;
166  }
167 
168  // Read the reference
169  Bimage* pref = read_img(filename, 1, -1);
170  if ( pref == NULL ) {
171  error_show("Error in img_prepare_projections", __FILE__, __LINE__);
172  return NULL;
173  }
174 
175  pref->change_type(Float);
176  pref->rescale_to_avg_std(0, 1);
177  pref->statistics();
178 
179  if ( bin < 1 ) bin = 1;
180  if ( bin > 4 ) bin = 4;
181  if ( bin > 1 ) pref->bin(bin);
182 
183  int i;
184  Vector3<double> origin;
185  for ( i=0; i<pref->images(); i++ ) {
186  origin = pref->image[i].origin();
187  if ( fabs(origin[0] - pref->sizeX()/2) > pref->sizeX()/10 )
188  origin[0] = pref->sizeX()/2;
189  if ( fabs(origin[1] - pref->sizeY()/2) > pref->sizeY()/10 )
190  origin[1] = pref->sizeY()/2;
191  if ( fabs(origin[2] - pref->sizeZ()/2) > pref->sizeZ()/10 )
192  origin[2] = pref->sizeZ()/2;
193  if ( pref->sizeZ() < 2 ) origin[2] = 0;
194  pref->image[i].origin(origin);
195  }
196 
197  if ( verbose ) {
198  cout << "Preparing projections for the full asymmetric unit: " << endl;
199  cout << "Reference: " << pref->file_name() << endl;
200  if ( pref->images() > 1 ) cout << " (" << pref->images() << " projections)" << endl;
201  cout << "Reference origin: " << pref->image->origin() << endl;
202  cout << "Theta and phi steps: " << theta_step*180.0/M_PI << " " << phi_step*180.0/M_PI << endl;
203  if ( side_ang < 0 )
204  cout << "Symmetry: " << sym->label << endl;
205  else
206  cout << "Side views within: " << side_ang*180.0/M_PI << " degrees" << endl;
207  if ( mask_file.length() ) cout << "Mask file name: " << mask_file << endl;
208  }
209 
210  Bimage* proj = NULL;
211  View* views = NULL;
212  int nviews(0);
213 
214  time_t t = time(NULL);
215 
216  FSI_Kernel* kernel = new FSI_Kernel(10, 2);
217 
218  // Mask to apply to projections
219  Bimage* pmask = NULL;
220  if ( mask_file.length() ) {
221  pmask = read_img(mask_file, 1, 0);
222  if ( bin > 1 ) pmask->bin(bin);
223  }
224 
225  long mem_req(0);
226  long mem_avail = system_memory();
227 
228  if ( pref->sizeZ() > 1 && pref->images() < 2 ) {
229  if ( side_ang < 0 )
230  views = asymmetric_unit_views(sym, theta_step, phi_step, 1);
231  else
232  views = side_views(sym, side_ang, theta_step, phi_step);
233  nviews = count_list((char *)views);
234  mem_req = pref->size()[0]*pref->size()[1]*sizeof(float)*nviews;
235  if ( verbose ) {
236  cout << "Number of projections: " << nviews << endl;
237  cout << "Memory required: " << mem_req << endl;
238  cout << "Memory available: " << mem_avail << endl;
239  }
240  if ( mem_req > mem_avail ) {
241  cerr << "Not enough memory to run!" << endl;
242  bexit(-1);
243  }
244  proj = pref->project(views, pref->sampling(0)[0], kernel);
245  if ( pmask ) proj->multiply(pmask);
246  kill_list((char *) views, sizeof(View));
247  delete pref;
248  if ( verbose )
249  cout << "Time to generate projections: " << (long)(time(NULL) - t) << " seconds" << endl << endl;
250  } else {
251  proj = pref;
252  proj->shift_background(0);
253  mem_req = proj->size()[0]*proj->size()[1]*proj->images()*sizeof(float);
254  if ( verbose ) {
255  cout << "Number of projections: " << proj->images() << endl;
256  cout << "Memory required: " << mem_req << endl;
257  cout << "Memory available: " << mem_avail << endl;
258  }
259  if ( mem_req > mem_avail ) {
260  cerr << "Not enough memory to run!" << endl;
261  bexit(-1);
262  }
263  }
264 
265  delete kernel;
266  delete pmask;
267 
268  return proj;
269 }
270 
271 Bimage* img_read_projection(Bstring& proj_file, int multi_file, int proj_num)
272 {
273  if ( verbose & VERB_DEBUG )
274  cout << "DEBUG img_read_projection: proj_file=" << proj_file << " proj_num=" << proj_num << endl;
275 
276  Bimage* proj = NULL;
277  Bstring proj_name = NULL;
278 
279  if ( multi_file ) {
280  proj_name = proj_file.pre_rev('.') + Bstring(proj_num, "%04d.") + proj_file.post_rev('.');
281  proj = read_img(proj_name, 1, 0);
282  } else
283  proj = read_img(proj_file, 1, proj_num);
284 
285  if ( !proj )
286  error_show("Error in img_read_projection", __FILE__, __LINE__);
287 
288  return proj;
289 }
290 
330  int bin, Bsymmetry* sym, int part_select, vector<double>& band,
331  double res_lo, double res_hi, double res_polar, int ann_min, int ann_max,
332  double shift_limit, double angle_limit, double edge_radius, int flags)
333 {
334  int mode = flags & MODE;
335  int ctf_apply = (flags & APPLY_CTF)? 1: 0;
336  int part_log = (flags & PART_LOG)? 1: 0;
337 
338 // Bfield* field = project->field;
339 
341  Bmicrograph* mg = part->mg;
342 
343  if ( !part ) {
344  cerr << "Error in project_determine_orientations: No particles found!" << endl;
345  return -1;
346  }
347 
348 // cout << proj->image->origin() << endl;
349 
350  // Note that the reference projections are already binned
351  if ( bin < 1 ) bin = 1;
352  if ( bin > 4 ) bin = 4;
353  edge_radius /= bin;
354 
355  Vector3<double> pixel_size = mg->pixel_size*bin;
356 
357  // Read the reference (model) projections, convert to floating point and clean up
358  long i, nproj(0), npix(0);
359 
360  nproj = proj->images();
361 
362  npix = proj->sizeX()*proj->sizeY();
363 
364 // cout << "Projection size:" << tab << proj->size() << tab << proj->images() << endl;
365 
366  // Specify FFTW arrays
367  fft_plan planf_1D = fft_setup_plan(NPOLANG, 1, 1, FFTW_FORWARD, 1);
368  fft_plan planb_1D = fft_setup_plan(NPOLANG, 1, 1, FFTW_BACKWARD, 1);
369  fft_plan planf_2D = fft_setup_plan(proj->sizeX(), proj->sizeY(), 1, FFTW_FORWARD, 1);
370  fft_plan planb_2D = fft_setup_plan(proj->sizeX(), proj->sizeY(), 1, FFTW_BACKWARD, 1);
371 
372  // Set resolution limits
373  if ( res_lo < res_hi ) swap(res_hi, res_lo);
374  if ( res_lo > proj->sizeX()*mg->pixel_size[0] )
375  res_lo = proj->sizeX()*mg->pixel_size[0];
376  if ( res_hi > proj->sizeX()*mg->pixel_size[0]/2 )
377  res_hi = proj->sizeX()*mg->pixel_size[0]/2;
378  if ( res_lo < 4*pixel_size[0] ) res_lo = 4*pixel_size[0];
379  if ( res_hi < 2*pixel_size[0] ) res_hi = 2*pixel_size[0];
380 
381 // cout << "Resolution:" << tab << res_hi << tab << res_lo << endl;
382 
383  // Check the annulus limits
384  ann_min /= bin;
385  ann_max /= bin;
386  if ( ann_min > ann_max ) swap(ann_min, ann_max);
387  if ( ann_min < 0 ) ann_min = 0;
388  if ( ann_max > proj->sizeX()/2 - 1 ) ann_max = proj->sizeX()/2 - 1;
389 
390 // cout << "Annuli:" << tab << ann_min << tab << ann_max << endl;
391 
392  // Check the shift limit
393  shift_limit /= bin;
394  if ( shift_limit < 0 ) shift_limit = proj->sizeX()/10; // Default shift limit
395 
396  // Generate the masks for cross-correlation and cross-validation
397  Bimage* prs_mask = new Bimage(SCharacter, TSimple, proj->size(), 1);
398  prs_mask->sampling(pixel_size);
399  if ( band.size() < 2 || band[0] < 1 )
400  band = prs_mask->fspace_default_bands(res_lo, res_hi);
401 
402  prs_mask->mask_fspace_banded(band);
403  write_img("mask.map", prs_mask, 0);
404 
405  if ( prs_mask->minimum() < 0 ) project->fom_tag[1] = FOM_CV;
406 
407  // Mask to apply to particles
408  Bimage* part_mask = NULL;
409  if ( mask_file.length() ) {
410  part_mask = read_img(mask_file, 1, 0);
411  if ( bin > 1 ) part_mask->bin(bin);
412  }
413 
414  long npart(0);
416 
417  if ( verbose & VERB_RESULT ) {
418  cout << "Determining orientations:" << endl;
419  if ( mode == 0 ) cout << "Mode: PPS based followed by one CC (fast)" << endl;
420  if ( mode == 1 ) cout << "Mode: PPS followed by selected CC's" << endl;
421  if ( mode == 2 ) cout << "Mode: PPS followed by all CC's (slow)" << endl;
422  cout << "Projection file name: " << proj->file_name() << endl;
423  cout << "Number of projections: " << nproj << endl;
424  cout << "Binning: " << bin << endl;
425  cout << "Pixel size: " << pixel_size << endl;
426  if ( prs_mask->minimum() < 0 ) cout << "Reciprocal space mask file: " << prs_mask->file_name() << endl;
427  if ( band[0] > 0 ) {
428  cout << "Reciprocal space bands:" << endl;
429  for ( i=0; band[i+1]; i+=2 ) {
430  cout << tab << setw(5) << band[i] << " - " << setw(5) << band[i+2];
431  if ( band[i+1] > 0 ) cout << "\tcross-correlation" << endl;
432  else cout << "\tcross-validation" << endl;
433  }
434  }
435  if ( ctf_apply ) cout << "CTF applied to projections." << endl;
436  cout << "Resolution limits (low, high): " << res_lo << " - " << res_hi << " A" << endl;
437  if ( res_polar ) cout << "Polar resolution limit: " << res_polar << " A" << endl;
438  cout << "Annular range: " << ann_min << " - " << ann_max << " (max = " << proj->sizeX()/2 - 1 << ")" << endl;
439  cout << "Shift limit: " << shift_limit << " pixels" << endl;
440  if ( angle_limit )
441  cout << "Angle limit: " << angle_limit*180.0/M_PI << " degrees" << endl;
442  if ( edge_radius ) cout << "Edge mask radius: " << edge_radius << " pixels" << endl;
443  if ( mask_file.length() ) cout << "Real space mask file: " << mask_file << endl;
444  cout << endl;
445  cout << "Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
446  }
447 
448  // Directory for individual particle log files
449  if ( part_log ) {
450  mkdir("log", O_CREAT );
451  chmod("log", 0755);
452  }
453 
454  // Directory for individual particle parameter files
455  if ( flags & WRITE_PPX ) {
456  mkdir("ppx", O_CREAT );
457  chmod("ppx", 0755);
458  }
459 
460  time_t t = time(NULL);
461 
462 #ifdef HAVE_GCD
463  dispatch_queue_t myq = dispatch_queue_create(NULL, NULL);
464  dispatch_apply(npart, dispatch_get_global_queue(0, 0), ^(size_t i){
465  Bparticle* part = partarr[i];
466  Bmicrograph* mg = part->mg;
467  part_determine_orientation(part, proj, part_mask,
468  prs_mask, sym, bin,
469  res_lo, res_hi, res_polar, ann_min, ann_max,
470  shift_limit, angle_limit, edge_radius, flags,
471  planf_1D, planb_1D, planf_2D, planb_2D);
472  dispatch_sync(myq, ^{
473  if ( verbose & VERB_RESULT ) {
474  cout << setw(15) << mg->id << tab << part->id << tab << fixed <<
475  setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
476  setprecision(4) << part->view[0] << tab <<
477  part->view[1] << tab << part->view[2] << tab <<
478  setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
479  setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
480  (long)(time(NULL) - t) << endl << flush;
481  }
482  });
483  });
484 #else
485 #pragma omp parallel for
486  for ( i=0; i<npart; i++ ) {
487  Bparticle* part = partarr[i];
488  Bmicrograph* mg = part->mg;
489  part_determine_orientation(part, proj, part_mask,
490  prs_mask, sym, bin,
491  res_lo, res_hi, res_polar, ann_min, ann_max,
492  shift_limit, angle_limit, edge_radius, flags,
493  planf_1D, planb_1D, planf_2D, planb_2D);
494  #pragma omp critical
495  {
496  if ( verbose & VERB_RESULT ) {
497  cout << setw(15) << mg->id << tab << part->id << tab << fixed <<
498  setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
499  setprecision(4) << part->view[0] << tab <<
500  part->view[1] << tab << part->view[2] << tab <<
501  setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
502  setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
503  (long)(time(NULL) - t) << endl << flush;
504  }
505  }
506  }
507 #endif
508 
509  if ( verbose & VERB_DEBUG )
510  cout << "DEBUG project_determine_orientations: done, npart=" << npart << endl;
511 
512  t = (time(NULL) - t);
513 
514  long ts = (long) t;
515  long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
516 
517  if ( verbose & VERB_RESULT && npart ) {
518  cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
519  cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
520  cout << "Algorithm time: " << ts*1.0e6/(npart*nproj*npix) << " us/pixel" << endl << endl;
521  }
522 
523  delete[] partarr;
524  delete prs_mask;
525  delete part_mask;
526 
527  fft_destroy_plan(planf_1D);
528  fft_destroy_plan(planb_1D);
529  fft_destroy_plan(planf_2D);
530  fft_destroy_plan(planb_2D);
531 
532  return 0;
533 }
534 
535 int part_determine_orientation(Bparticle* part, Bimage* proj, Bimage* part_mask,
536  Bimage* prs_mask, Bsymmetry* sym, int bin,
537  double res_lo, double res_hi, double res_polar, int ann_min, int ann_max,
538  double shift_limit, double angle_limit, double edge_radius, int flags,
539  fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
540 {
541  FOMType fom_tag[NFOM] = {FOM, FOM_CV};
542 
543  if ( flags & CHECK_PPX )
544  if ( ppx_check(part, fom_tag) ) return 0;
545 
546  if ( verbose & VERB_DEBUG )
547  cout << "DEBUG part_determine_orientation: id=" << part->id << " flags=" << flags << endl;
548 
549  int mode = flags & MODE;
550  int ctf_apply = (flags & APPLY_CTF)? 1: 0;
551  int part_log = (flags & PART_LOG)? 1: 0;
552 
553  long k, imax(0), nproj(proj->images());
554  double cc_best(-1e37), cc_min, cc_max, cc_avg, cc_std, cc_cut;
555  double* angle = new double[nproj];
556  double* ox = new double[nproj];
557  double* oy = new double[nproj];
558  View* view = new View[nproj];
559  double* cc = new double[nproj];
560 
561  Bmicrograph* mg = part->mg;
562  if ( !mg )
563  return error_show("part_determine_orientation", __FILE__, __LINE__);
564 
565  Vector3<double> pixel_size = mg->pixel_size*bin;
566  ofstream flog;
567  Bstring log_name;
568  long edge_size = (long) (2*edge_radius);
569  Vector3<long> size(edge_size, edge_size, 1);
570  Vector3<double> start, shift;
571 
572  Bimage* p = NULL;
573  Bimage* pm;
574  Bimage* proj1;
575 
576  if ( part_log ) {
577  log_name = "log/" + mg->id + "_" + Bstring(part->id, "%04d") + "_orient.log";
578  flog.open(log_name.c_str());
579  if ( flog.fail() )
580  return error_show("Log file cannot be written!", __FILE__, __LINE__);
581  flog << mg->id << ": " << part->id << endl;
582  }
583 
584 // cout << "Reading particle " << part->id << endl;
585  if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
586  else if ( mg->fpart.length() ) p = read_img(mg->fpart, 1, part->id - 1);
587  if ( !p )
588  return error_show("part_determine_orientation", __FILE__, __LINE__);
589 
590 // cout << "Preparing particle " << part->id << endl;
591  p->change_type(Float);
592  if ( bin > 1 ) p->bin(bin);
593  p->statistics();
594  p->sampling(pixel_size);
595 // if ( part->id == 1 ) cout << "Image sampling = " << p->sampling(0) << endl;
596 // if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->image->origin(part->ori/bin);
597 // else p->image->origin(p->size());
598  if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->origin(part->ori/bin);
599  else p->origin(p->size()/2);
600 
601  p->rescale_to_avg_std(0, 1);
602  p->shift_background(0);
603 
604  if ( part_mask ) {
605  pm = part_mask->copy();
606  shift = p->image->origin() - pm->image->origin();
607  pm->shift(shift);
608  p->multiply(pm);
609  delete pm;
610  p->rescale_to_avg_std(0, 1);
611  p->shift_background(0);
612  }
613 
614  if ( edge_size ) {
615 // cout << "Edge masking" << endl;
616  start = Vector3<double>(p->image->origin()[0]-edge_radius, p->image->origin()[1]-edge_radius, 0);
617  p->edge(1, size, start, 1, FILL_BACKGROUND, 0);
618  }
619 
620  if ( verbose & VERB_DEBUG )
621  cout << "DEBUG part_determine_orientation: preprocessing done for image " << part->id << endl;
622  if ( part_log )
623  flog << "PartID\tProjID\tox\toy\tvx\tvy\tvz\tva\tcc" << endl;
624 
625  for ( k=0; k<nproj; k++ ) {
626  if ( verbose & VERB_DEBUG )
627  cout << "DEBUG part_determine_orientation: pps with proj " << k << endl;
628  proj1 = proj->extract(k);
629  if ( !proj1 )
630  return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
631  proj1->sampling(pixel_size);
632 // cout << "Projection sampling = " << proj1->sampling(0) << endl;
633  if ( ctf_apply && mg->ctf )
634  img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
635  p->image->view(part->view);
636  cc[k] = p->align2D_pps(proj1, res_hi, res_lo, shift_limit, angle_limit, planf_2D, planb_2D);
637  angle[k] = p->image->view_angle();
638  ox[k] = p->image->origin()[0];
639  oy[k] = p->image->origin()[1];
640  view[k] = proj1->image->view();
641 // if ( part->id == 43 ) cout << ox[k] << tab << oy[k] << tab << cc[k] << endl;
642  if ( angle[k] < 0 ) {
643  view[k].negate();
644  view[k][3] = angle_set_negPI_to_PI(M_PI - view[k].angle() + angle[k]);
645  } else {
646  view[k][3] = angle_set_negPI_to_PI(view[k].angle() - angle[k]);
647  }
648 // if ( verbose & VERB_DEBUG )
649  if ( part_log )
650  flog << fixed << setprecision(4) <<
651  part->id << tab << k+1 << tab <<
652  bin*ox[k] << tab << bin*oy[k] << tab << view[k][0] << tab << view[k][1] << tab <<
653  view[k][2] << tab << view[k].angle()*180.0/M_PI << tab << cc[k] << endl;
654 // cout << part->id << " " << k+1 << " " << ox[k] << " " << oy[k]
655 // << " " << view[k][0] << " " << view[k][1] << " " << view[k][2]
656 // << " " << view[k].angle()*180.0/M_PI << " " << cc[k] << endl;
657  if ( cc_best < cc[k] ) {
658  cc_best = cc[k];
659  imax = k;
660  }
661  delete proj1;
662  }
663 
664  cc_avg = cc_std = 0;
665  cc_min = cc_max = cc[0];
666  for ( k=imax=0; k<nproj; k++ ) {
667  if ( cc_min > cc[k] ) cc_min = cc[k];
668  if ( cc_max < cc[k] ) {
669  cc_max = cc[k];
670  imax = k;
671  }
672  cc_avg += cc[k];
673  cc_std += cc[k]*cc[k];
674  }
675  cc_avg /= nproj;
676  cc_std = cc_std/nproj - cc_avg*cc_avg;
677  if ( cc_std > 0 ) cc_std = sqrt(cc_std);
678  else cc_std = 0;
679  cc_cut = cc_avg + cc_std;
680  if ( cc_cut >= cc_max ) cc_cut = cc_max - 0.01;
681  if ( mode < 1 ) cc_cut = cc_max - 0.01;
682  else if ( mode > 1 ) cc_cut = cc_min - 1;
683  if ( verbose & VERB_DEBUG )
684  if ( part_log )
685  flog << "Particle, min, max, avg, std, max/avg:" <<
686  part->id << tab << cc_min << tab << cc_max << tab <<
687  cc_avg << tab << cc_std << tab << cc_max/cc_avg << endl;
688  if ( verbose & VERB_DEBUG ) {
689  cout << "DEBUG part_determine_orientation: cc_avg=" << cc_avg << " cc_std=" << cc_std << endl;
690  cout << "DEBUG part_determine_orientation: cc_min=" << cc_min << " cc_max=" << cc_max << endl;
691  cout << "DEBUG part_determine_orientation: cc_cut=" << cc_cut << endl;
692  }
693 
694  cc_best = -1e37;
695 // if ( mode > 0 )
696  for ( k=0; k<nproj; k++ ) if ( cc[k] > cc_cut ) {
697  if ( verbose & VERB_DEBUG )
698  cout << "DEBUG part_determine_orientation: cc with proj " << k << endl;
699  proj1 = proj->extract(k);
700  if ( !proj1 )
701  return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
702  proj1->sampling(pixel_size);
703  if ( ctf_apply && mg->ctf )
704  img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
705  p->image->view(part->view);
706  p->image->view_angle(angle[k]);
707  p->image->origin(ox[k], oy[k], 0);
708 // cc[k] = img_align2D(p, proj1, 1, res_polar, ann_min, ann_max,
709 // prs_mask, shift_limit, planf_1D, planb_1D, planf_2D, planb_2D);
710  cc[k] = p->align2D(proj1, res_polar, ann_min, ann_max,
711  prs_mask, shift_limit, angle_limit, planf_1D, planb_1D, planf_2D, planb_2D);
712  angle[k] = p->image->view_angle();
713  ox[k] = p->image->origin()[0];
714  oy[k] = p->image->origin()[1];
715  view[k] = proj1->image->view();
716 // if ( part->id == 43 ) {
717 // cout << k << tab << ox[k] << tab << oy[k] << tab << cc[k] << endl;
718 // if ( cc[k] > 1 ) bexit(-1);
719 // }
720  if ( angle[k] < 0 ) {
721  view[k].negate();
722  view[k][3] = angle_set_negPI_to_PI(M_PI - view[k].angle() + angle[k]);
723  } else {
724  view[k][3] = angle_set_negPI_to_PI(view[k].angle() - angle[k]);
725  }
726  if ( part_log )
727  flog << fixed << setprecision(4) <<
728  part->id << tab << k+1 << tab <<
729  bin*ox[k] << tab << bin*oy[k] << tab << view[k][0] << tab << view[k][1] << tab <<
730  view[k][2] << tab << view[k].angle()*180.0/M_PI << tab << cc[k] << endl;
731 // cout << part->id << " " << k+1 << " " << ox[k] << " " << oy[k]
732 // << " " << view[k][0] << " " << view[k][1] << " " << view[k][2]
733 // << " " << view[k].angle()*180.0/M_PI << " " << cc[k] << endl;
734  if ( cc_best < cc[k] ) {
735  cc_best = cc[k];
736  imax = k;
737  }
738  delete proj1;
739  }
740 
741  if ( verbose & VERB_DEBUG )
742  cout << "DEBUG part_determine_orientation: projection matching done for image " << part->id << endl;
743  part->ori = Vector3<double>(bin*ox[imax], bin*oy[imax], 0);
744  part->view = view[imax];
745  part->fom[0] = cc[imax];
746  if ( prs_mask->minimum() < 0 ) {
747  proj1 = proj->extract(imax);
748  if ( !proj1 )
749  return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
750  proj1->sampling(pixel_size);
751  if ( ctf_apply && mg->ctf )
752  img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
753  p->image->view_angle(angle[imax]);
754  p->image->origin(ox[imax], oy[imax], 0);
755  p->origin(0, ox[imax], oy[imax], 0.0);
756  part->fom[1] = img_cross_validate(p, proj1, prs_mask, planf_2D);
757  delete proj1;
758  }
759  part->view = find_asymmetric_unit_view(sym, part->view);
760  part->view[3] = angle_set_negPI_to_PI(part->view.angle());
761  part->sel = imax + 1;
762  if ( part_log ) {
763  flog << "Particle, min, max, avg, std, max/avg, cv:" << tab <<
764  part->id << tab << cc_min << tab << cc_max << tab <<
765  cc_avg << tab << cc_std << tab << cc_max/cc_avg << tab << part->fom[1] << endl;
766  flog << fixed << setprecision(4) <<
767  part->id << tab << part->ori[0] << tab << part->ori[1] << tab <<
768  part->view[0] << tab << part->view[1] << tab <<
769  part->view[2] << tab << part->view.angle()*180.0/M_PI << tab <<
770  part->fom[0] << tab << part->fom[1] << endl;
771  flog.close();
772  }
773 
774  delete[] angle;
775  delete[] ox;
776  delete[] oy;
777  delete[] view;
778  delete[] cc;
779  delete p;
780 
781  if ( flags & WRITE_PPX ) {
782  log_name = ppx_filename(mg->id, part->id);
783  write_particle(log_name, part, 0, 0, fom_tag);
784  }
785 
786  return 1;
787 }
788 
790  long k, int bin, CTFparam* ctf,
791  double res_lo, double res_hi, double res_polar, long ann_min, long ann_max,
792  double shift_limit, double angle_limit, double edge_radius, int flags,
793  fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
794 {
795  Bimage* pcopy = p->copy();
796  Bparticle part;
797 
798  if ( verbose & VERB_DEBUG )
799  cout << "DEBUG part_compare: proj " << k << endl;
800 
801  Bimage* proj1 = proj->extract(k);
802  if ( !proj1 ) {
803  error_show("Error in part_compare", __FILE__, __LINE__);
804  return part;
805  }
806 
807  proj1->sampling(p->sampling(0));
808 
809  if ( ctf )
810  img_ctf_apply_to_proj(proj1, *ctf, ctf->defocus_average(), 1e6, res_hi, planf_2D, planb_2D);
811 
812  part.fom[0] = pcopy->align2D_pps(proj1, res_hi, res_lo, shift_limit, angle_limit, planf_2D, planb_2D);
813 
814 
815  part.fom[0] = pcopy->align2D(proj1, res_polar, ann_min, ann_max,
816  prs_mask, shift_limit, angle_limit, planf_1D, planb_1D, planf_2D, planb_2D);
817 
818  View view = proj1->image->view();
819  double angle = pcopy->image->view_angle();
820 
821  if ( angle < 0 ) {
822  view.negate();
823  view[3] = angle_set_negPI_to_PI(M_PI - view.angle() + angle);
824  } else {
825  view[3] = angle_set_negPI_to_PI(view.angle() - angle);
826  }
827 
828  part.ori = pcopy->image->origin() * bin;
829  part.view = view;
830 
831  delete pcopy;
832  delete proj1;
833 
834  return part;
835 }
836 
837 int part_determine_orientation2(Bparticle* part, Bimage* proj, Bimage* part_mask,
838  Bimage* prs_mask, Bsymmetry* sym, int bin,
839  double res_lo, double res_hi, double res_polar, int ann_min, int ann_max,
840  double shift_limit, double angle_limit, double edge_radius, int flags,
841  fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
842 {
843  FOMType fom_tag[NFOM] = {FOM, FOM_CV};
844 
845  if ( flags & CHECK_PPX )
846  if ( ppx_check(part, fom_tag) ) return 0;
847 
848  if ( verbose & VERB_DEBUG )
849  cout << "DEBUG part_determine_orientation: id=" << part->id << " flags=" << flags << endl;
850 
851  int ctf_apply = (flags & APPLY_CTF)? 1: 0;
852  int part_log = (flags & PART_LOG)? 1: 0;
853 
854  long k, imax(0), nproj(proj->images());
855 
856  Bmicrograph* mg = part->mg;
857  if ( !mg )
858  return error_show("part_determine_orientation", __FILE__, __LINE__);
859 
860  Vector3<double> pixel_size = part->pixel_size*bin;
861  ofstream flog;
862  Bstring log_name;
863  long edge_size = (long) (2*edge_radius);
864  Vector3<long> size(edge_size, edge_size, 1);
865  Vector3<double> start, shift;
866 
867  Bimage* p = NULL;
868  Bimage* pm;
869  Bimage* proj1;
870 
871  if ( part_log ) {
872  log_name = "log/" + mg->id + "_" + Bstring(part->id, "%04d") + "_orient.log";
873  flog.open(log_name.c_str());
874  if ( flog.fail() )
875  return error_show("Log file cannot be written!", __FILE__, __LINE__);
876  flog << mg->id << ": " << part->id << endl;
877  }
878 
879 // cout << "Reading particle " << part->id << endl;
880  if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
881  else if ( mg->fpart.length() ) p = read_img(mg->fpart, 1, part->id - 1);
882  if ( !p )
883  return error_show("part_determine_orientation", __FILE__, __LINE__);
884 
885 // cout << "Preparing particle " << part->id << endl;
886  p->change_type(Float);
887  if ( bin > 1 ) p->bin(bin);
888  p->statistics();
889  p->sampling(pixel_size);
890 // if ( part->id == 1 ) cout << "Image sampling = " << p->sampling(0) << endl;
891 // if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->image->origin(part->ori/bin);
892 // else p->image->origin(p->size());
893  if ( part->ori[0] > 0 && part->ori[1] > 0 ) p->origin(part->ori/bin);
894  else p->origin(p->size()/2);
895 
896  p->rescale_to_avg_std(0, 1);
897  p->shift_background(0);
898 
899  if ( part_mask ) {
900  pm = part_mask->copy();
901  shift = p->image->origin() - pm->image->origin();
902  pm->shift(shift);
903  p->multiply(pm);
904  delete pm;
905  p->rescale_to_avg_std(0, 1);
906  p->shift_background(0);
907  }
908 
909  if ( edge_size ) {
910 // cout << "Edge masking" << endl;
911  start = Vector3<double>(p->image->origin()[0]-edge_radius, p->image->origin()[1]-edge_radius, 0);
912  p->edge(1, size, start, 1, FILL_BACKGROUND, 0);
913  }
914 
915  Bparticle* partarr = new Bparticle[nproj];
916 // vector<Bparticle> partarr(nproj);
917 
918  if ( verbose & VERB_DEBUG )
919  cout << "DEBUG part_determine_orientation: preprocessing done for image " << part->id << endl;
920  if ( part_log )
921  flog << "PartID\tProjID\tox\toy\tvx\tvy\tvz\tva\tcc" << endl;
922 
923 #ifdef HAVE_GCD
924  dispatch_apply(nproj, dispatch_get_global_queue(0, 0), ^(size_t k){
925  Bmicrograph* mg = part->mg;
926  partarr[k] = part_compare(p, proj, prs_mask, k, bin, mg->ctf,
927  res_lo, res_hi, res_polar, ann_min, ann_max,
928  shift_limit, angle_limit, edge_radius, flags,
929  planf_1D, planb_1D, planf_2D, planb_2D);
930  });
931 #else
932 #pragma omp parallel for
933  for ( k=0; k<nproj; ++k ) {
934  Bmicrograph* mg = part->mg;
935  partarr[k] = part_compare(p, proj, prs_mask, k, bin, mg->ctf,
936  res_lo, res_hi, res_polar, ann_min, ann_max,
937  shift_limit, angle_limit, edge_radius, flags,
938  planf_1D, planb_1D, planf_2D, planb_2D);
939  }
940 #endif
941 
942  double cc, cc_min(1), cc_avg(0), cc_std(0);
943 
944  part->fom[0] = -1;
945  for ( k=0; k<nproj; ++k ) {
946  cc = partarr[k].fom[0];
947  cc_avg += cc;
948  cc_std += cc * cc;
949  if ( part->fom[0] < cc ) {
950  part->fom[0] = cc;
951  imax = k;
952  }
953  if ( cc_min > cc ) cc_min = cc;
954  }
955  cc_avg /= nproj;
956  cc_std /= nproj;
957  cc_std -= cc_avg * cc_avg;
958  if ( cc_std > 0 ) cc_std = sqrt(cc_std);
959  else cc_std = 0;
960 
961  if ( verbose & VERB_DEBUG )
962  cout << "DEBUG part_determine_orientation: projection matching done for image " << part->id << endl;
963  part->ori = partarr[imax].ori;
964  part->view = partarr[imax].view;
965 
966  if ( prs_mask->minimum() < 0 ) {
967  proj1 = proj->extract(imax);
968  if ( !proj1 )
969  return error_show("Error in part_determine_orientation", __FILE__, __LINE__);
970  proj1->sampling(pixel_size);
971  if ( ctf_apply && mg->ctf )
972  img_ctf_apply_to_proj(proj1, *(mg->ctf), part->def, 1e6, res_hi, planf_2D, planb_2D);
973  p->image->origin(part->ori);
974  p->image->view(part->view);
975 // p->image->view_angle(angle[imax]);
976  part->fom[1] = img_cross_validate(p, proj1, prs_mask, planf_2D);
977  delete proj1;
978  }
979 
980  part->view = find_asymmetric_unit_view(sym, part->view);
981  part->view[3] = angle_set_negPI_to_PI(part->view.angle());
982  part->sel = imax + 1;
983 
984  if ( part_log ) {
985  flog << "Particle, min, max, avg, std, max/avg, cv:" << tab <<
986  part->id << tab << cc_min << tab << part->fom[0] << tab <<
987  cc_avg << tab << cc_std << tab << part->fom[0]/cc_avg << tab << part->fom[1] << endl;
988  flog << fixed << setprecision(4) <<
989  part->id << tab << part->ori[0] << tab << part->ori[1] << tab <<
990  part->view[0] << tab << part->view[1] << tab <<
991  part->view[2] << tab << part->view.angle()*180.0/M_PI << tab <<
992  part->fom[0] << tab << part->fom[1] << endl;
993  flog.close();
994  }
995 
996  delete p;
997  delete[] partarr;
998 
999  if ( flags & WRITE_PPX ) {
1000  log_name = ppx_filename(mg->id, part->id);
1001  write_particle(log_name, part, 0, 0, fom_tag);
1002  }
1003 
1004  return 1;
1005 }
1006 
1007 
1047  int bin, Bsymmetry* sym, int part_select, vector<double>& band,
1048  double res_lo, double res_hi, double res_polar, int ann_min, int ann_max,
1049  double shift_limit, double angle_limit, double edge_radius, int flags)
1050 {
1051  int mode = flags & MODE;
1052  int ctf_apply = (flags & APPLY_CTF)? 1: 0;
1053  int part_log = (flags & PART_LOG)? 1: 0;
1054 
1055 // Bfield* field = project->field;
1056 
1058  Bmicrograph* mg = part->mg;
1059 
1060  if ( !part ) {
1061  cerr << "Error in project_determine_orientations: No particles found!" << endl;
1062  return -1;
1063  }
1064 
1065 // cout << proj->image->origin() << endl;
1066 
1067  // Note that the reference projections are already binned
1068  if ( bin < 1 ) bin = 1;
1069  if ( bin > 4 ) bin = 4;
1070  edge_radius /= bin;
1071 
1072  Vector3<double> pixel_size = part->pixel_size*bin;
1073 
1074  // Read the reference (model) projections, convert to floating point and clean up
1075  long i, nproj(0), npix(0);
1076 
1077  nproj = proj->images();
1078 
1079  npix = proj->sizeX()*proj->sizeY();
1080 
1081 // cout << "Projection size:" << tab << proj->size() << tab << proj->images() << endl;
1082 
1083  // Specify FFTW arrays
1084  fft_plan planf_1D = fft_setup_plan(NPOLANG, 1, 1, FFTW_FORWARD, 1);
1085  fft_plan planb_1D = fft_setup_plan(NPOLANG, 1, 1, FFTW_BACKWARD, 1);
1086  fft_plan planf_2D = fft_setup_plan(proj->sizeX(), proj->sizeY(), 1, FFTW_FORWARD, 1);
1087  fft_plan planb_2D = fft_setup_plan(proj->sizeX(), proj->sizeY(), 1, FFTW_BACKWARD, 1);
1088 
1089  // Set resolution limits
1090  if ( res_lo < res_hi ) swap(res_hi, res_lo);
1091  if ( res_lo > proj->sizeX()*pixel_size[0] )
1092  res_lo = proj->sizeX()*pixel_size[0];
1093  if ( res_hi > proj->sizeX()*pixel_size[0]/2 )
1094  res_hi = proj->sizeX()*pixel_size[0]/2;
1095  if ( res_lo < 4*pixel_size[0] ) res_lo = 4*pixel_size[0];
1096  if ( res_hi < 2*pixel_size[0] ) res_hi = 2*pixel_size[0];
1097 
1098 // cout << "Resolution:" << tab << res_hi << tab << res_lo << endl;
1099 
1100  // Check the annulus limits
1101  ann_min /= bin;
1102  ann_max /= bin;
1103  if ( ann_min > ann_max ) swap(ann_min, ann_max);
1104  if ( ann_min < 0 ) ann_min = 0;
1105  if ( ann_max > proj->sizeX()/2 - 1 ) ann_max = proj->sizeX()/2 - 1;
1106 
1107 // cout << "Annuli:" << tab << ann_min << tab << ann_max << endl;
1108 
1109  // Check the shift limit
1110  shift_limit /= bin;
1111  if ( shift_limit < 0 ) shift_limit = proj->sizeX()/10; // Default shift limit
1112 
1113  // Generate the masks for cross-correlation and cross-validation
1114  Bimage* prs_mask = new Bimage(SCharacter, TSimple, proj->size(), 1);
1115  prs_mask->sampling(pixel_size);
1116  if ( band.size() < 2 || band[0] < 1 )
1117  band = prs_mask->fspace_default_bands(res_lo, res_hi);
1118 
1119  prs_mask->mask_fspace_banded(band);
1120  write_img("mask.map", prs_mask, 0);
1121 
1122  if ( prs_mask->minimum() < 0 ) project->fom_tag[1] = FOM_CV;
1123 
1124  // Mask to apply to particles
1125  Bimage* part_mask = NULL;
1126  if ( mask_file.length() ) {
1127  part_mask = read_img(mask_file, 1, 0);
1128  if ( bin > 1 ) part_mask->bin(bin);
1129  }
1130 
1131  long npart(0);
1133 
1134  if ( verbose & VERB_RESULT ) {
1135  cout << "Determining orientations:" << endl;
1136  if ( mode == 0 ) cout << "Mode: PPS based followed by one CC (fast)" << endl;
1137  if ( mode == 1 ) cout << "Mode: PPS followed by selected CC's" << endl;
1138  if ( mode == 2 ) cout << "Mode: PPS followed by all CC's (slow)" << endl;
1139  cout << "Projection file name: " << proj->file_name() << endl;
1140  cout << "Number of projections: " << nproj << endl;
1141  cout << "Binning: " << bin << endl;
1142  cout << "Pixel size: " << pixel_size << endl;
1143  if ( prs_mask->minimum() < 0 ) cout << "Reciprocal space mask file: " << prs_mask->file_name() << endl;
1144  if ( band[0] > 0 ) {
1145  cout << "Reciprocal space bands:" << endl;
1146  for ( i=0; band[i+1]; i+=2 ) {
1147  cout << tab << setw(5) << band[i] << " - " << setw(5) << band[i+2];
1148  if ( band[i+1] > 0 ) cout << "\tcross-correlation" << endl;
1149  else cout << "\tcross-validation" << endl;
1150  }
1151  }
1152  if ( ctf_apply ) cout << "CTF applied to projections." << endl;
1153  cout << "Resolution limits (low, high): " << res_lo << " - " << res_hi << " A" << endl;
1154  if ( res_polar ) cout << "Polar resolution limit: " << res_polar << " A" << endl;
1155  cout << "Annular range: " << ann_min << " - " << ann_max << " (max = " << proj->sizeX()/2 - 1 << ")" << endl;
1156  cout << "Shift limit: " << shift_limit << " pixels" << endl;
1157  if ( angle_limit )
1158  cout << "Angle limit: " << angle_limit*180.0/M_PI << " degrees" << endl;
1159  if ( edge_radius ) cout << "Edge mask radius: " << edge_radius << " pixels" << endl;
1160  if ( mask_file.length() ) cout << "Real space mask file: " << mask_file << endl;
1161  cout << endl;
1162  cout << "Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tCV\tTime" << endl;
1163  }
1164 
1165  // Directory for individual particle log files
1166  if ( part_log ) {
1167  mkdir("log", O_CREAT );
1168  chmod("log", 0755);
1169  }
1170 
1171  // Directory for individual particle parameter files
1172  if ( flags & WRITE_PPX ) {
1173  mkdir("ppx", O_CREAT );
1174  chmod("ppx", 0755);
1175  }
1176 
1177  time_t t = time(NULL);
1178 
1179  for ( i=0; i<npart; ++i ) {
1180  part = partarr[i];
1181  part_determine_orientation2(part, proj, part_mask,
1182  prs_mask, sym, bin,
1183  res_lo, res_hi, res_polar, ann_min, ann_max,
1184  shift_limit, angle_limit, edge_radius, flags,
1185  planf_1D, planb_1D, planf_2D, planb_2D);
1186  if ( verbose & VERB_RESULT ) {
1187  cout << setw(15) << mg->id << tab << part->id << tab << fixed <<
1188  setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
1189  setprecision(4) << part->view[0] << tab <<
1190  part->view[1] << tab << part->view[2] << tab <<
1191  setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
1192  setprecision(4) << part->fom[0] << tab << part->fom[1] << tab <<
1193  (long)(time(NULL) - t) << endl << flush;
1194  }
1195  }
1196 
1197  if ( verbose & VERB_DEBUG )
1198  cout << "DEBUG project_determine_orientations: done, npart=" << npart << endl;
1199 
1200  t = (time(NULL) - t);
1201 
1202  long ts = (long) t;
1203  long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
1204 
1205  if ( verbose & VERB_RESULT && npart ) {
1206  cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
1207  cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
1208  cout << "Algorithm time: " << ts*1.0e6/(npart*nproj*npix) << " us/pixel" << endl << endl;
1209  }
1210 
1211  delete[] partarr;
1212  delete prs_mask;
1213  delete part_mask;
1214 
1215  fft_destroy_plan(planf_1D);
1216  fft_destroy_plan(planb_1D);
1217  fft_destroy_plan(planf_2D);
1218  fft_destroy_plan(planb_2D);
1219 
1220  return 0;
1221 }
1222 
1244  Bsymmetry* sym, int part_select, double res_lo, double res_hi,
1245  double shift_limit, int flags)
1246 {
1247  int part_log = (flags & PART_LOG)? 1: 0;
1248 
1249  Bfield* field = project->field;
1250 
1252  Bmicrograph* mg = part->mg;
1253 
1254  if ( !part ) {
1255  cerr << "Error in project_determine_origins: No particles found!" << endl;
1256  return -1;
1257  }
1258 
1259  Bimage* p = NULL;
1260  Bimage* prs_mask = NULL;
1261 
1262  if ( bin < 1 ) bin = 1;
1263  if ( bin > 4 ) bin = 4;
1264 
1265  Vector3<double> pixel_size = mg->pixel_size*bin;
1266 
1267  // Read the reference (model) projections, convert to floating point and clean up
1268  long i, nproj(0), npart(0), npix(0), vmin(0);
1269 
1270  nproj = proj->images();
1271 
1272  npix = proj->sizeX()*proj->sizeY();
1273 
1274  // Specify FFTW arrays
1275  fft_plan planf_2D = proj->fft_setup(FFTW_FORWARD, 1);
1276  fft_plan planb_2D = proj->fft_setup(FFTW_BACKWARD, 1);
1277 
1278  // Set resolution limits
1279  if ( res_lo < res_hi ) swap(res_hi, res_lo);
1280  if ( res_lo < 4*pixel_size[0] ) res_lo = 4*pixel_size[0];
1281  if ( res_hi < 2*pixel_size[0] ) res_hi = 2*pixel_size[0];
1282 
1283  // Check the shift limit
1284  shift_limit /= bin;
1285  if ( shift_limit < 0 ) shift_limit = proj->sizeX()/10; // Default shift limit
1286 
1287  double cc, angle, da, da_min;
1288  View* pv = new View[nproj];
1289  View hasu_view;
1290 
1291  for ( i=0; i<nproj; i++ )
1292  pv[i] = proj->image->view();
1293 
1294  if ( verbose & VERB_RESULT ) {
1295  cout << "Determining origins:" << endl;
1296  cout << "Projection file name: " << proj->file_name() << endl;
1297  cout << "Number of projections: " << nproj << endl;
1298  cout << "Pixel size: " << pixel_size << endl;
1299  cout << "Resolution limits (low, high): " << res_lo << " - " << res_hi << " A" << endl;
1300  cout << "Shift limit: " << shift_limit << " pixels" << endl << endl;
1301  cout << "Micrograph\tPID\tOriX\tOriY\tViewX\tViewY\tViewZ\tAngle\tCC\tTime" << endl;
1302  }
1303 
1304 
1305  ofstream flog;
1306  Bstring log_name;
1307  Bimage* proj1;
1308  Vector3<double> shift;
1309 
1310  // Directory for individual particle log files
1311  if ( part_log ) {
1312  mkdir("log", O_CREAT );
1313  chmod("log", 0755);
1314  }
1315 
1316  time_t t = time(NULL);
1317 
1318  for ( field=project->field; field; field=field->next ) {
1319  for ( mg=field->mg; mg; mg=mg->next ) if ( mg->part ) {
1320  for ( part=mg->part; part; part=part->next )
1321  if ( ( part_select<0 && part->sel ) || ( part->sel==part_select ) ) {
1322  if ( verbose & VERB_DEBUG ) {
1323  cout << "DEBUG project_determine_origins: file=";
1324  if ( part->fpart.length() ) cout << mg->fpart;
1325  else cout << part->fpart;
1326  cout << " image=" << part->id << endl;
1327  }
1328  if ( part_log ) {
1329  log_name = "log/" + mg->id + "_" + Bstring(part->id, "%04d") + "_orient.log";
1330  flog.open(log_name.c_str());
1331  if ( flog.fail() )
1332  return error_show("Error in project_determine_origins: Log file cannot be written!", __FILE__, __LINE__);
1333  flog << field->id << ": " << mg->id << ": " << part->id << endl;
1334  }
1335  if ( part->fpart.length() ) p = read_img(part->fpart, 1, 0);
1336  else p = read_img(mg->fpart, 1, part->id - 1);
1337  if ( !p )
1338  return error_show("Error in project_determine_origins", __FILE__, __LINE__);
1339  p->change_type(Float);
1340  if ( bin > 1 ) p->bin(bin);
1341  p->statistics();
1342  p->rescale_to_avg_std(0, 1);
1343  p->shift_background(0);
1344  p->sampling(pixel_size);
1345  hasu_view = part->view;
1346  hasu_view[3] += TWOPI;
1347  for ( i=vmin=0, da_min = 1e10; i<nproj; i++ ) {
1348  da = hasu_view.angle(pv[i]);
1349  da = fabs(angle_set_negPI_to_PI(da));
1350  if ( da < da_min ) {
1351  da_min = da;
1352  vmin = i;
1353  }
1354  }
1355  part->sel = vmin + 1;
1356  proj1 = proj->extract(vmin);
1357  if ( !proj ) {
1358  error_show("Error in project_determine_origins", __FILE__, __LINE__);
1359  return -1;
1360  }
1361  angle = hasu_view.angle() - pv[vmin].angle();
1362  proj1->rotate(angle);
1363  shift = p->find_shift(proj1, prs_mask, res_hi, res_lo, shift_limit, 0, 1, planf_2D, planb_2D, cc);
1364  part->ori = (proj1->image->origin() + shift) * bin;
1365  part->fom[0] = cc;
1366  delete proj1;
1367  if ( part_log ) {
1368  flog << part->id << tab << part->ori[0] << tab << part->ori[1] << tab << cc << endl;
1369  flog.close();
1370  }
1371  if ( verbose & VERB_RESULT )
1372  cout << setw(15) << mg->id << tab << part->id << tab <<
1373  setprecision(2) << part->ori[0] << tab << part->ori[1] << tab <<
1374  setprecision(4) << part->view[0] << tab <<
1375  part->view[1] << tab << part->view[2] << tab <<
1376  setprecision(2) << part->view.angle()*180.0/M_PI << tab <<
1377  setprecision(4) << part->fom[0] << tab <<
1378  (long)(time(NULL) - t) << endl;
1379  delete p;
1380  npart++;
1381  } else part->fom[0] = part->sel = 0;
1382  }
1383  }
1384 
1385  t = (time(NULL) - t);
1386 
1387  long ts = (long) t;
1388  long hr = ts/3600, min = (ts - 3600*hr)/60, sec = ts - 3600*hr - 60*min;
1389 
1390  if ( verbose & VERB_RESULT ) {
1391  cout << "Time: " << ts << " s (" << hr << ":" << min << ":" << sec << ")" << endl;
1392  cout << "Time per particle: " << ts*1.0/npart << " s/particle" << endl;
1393  cout << "Algorithm time: " << ts*1.0e6/(npart*nproj*npix) << " us/pixel" << endl << endl;
1394  }
1395 
1396  fft_destroy_plan(planf_2D);
1397  fft_destroy_plan(planb_2D);
1398 
1399  delete[] pv;
1400 
1401  return 0;
1402 }
1403 
1404 
1422 double img_cross_validate(Bimage* p, Bimage* pref, Bimage* prs_mask, fft_plan planf)
1423 {
1424  Bimage* prot = pref->rotate(pref->size(), fabs(p->image->view_angle() - pref->image->view_angle()));
1425 
1426  Bimage* pcc = prot->pack_two_in_complex(p);
1427 
1428  delete prot;
1429 
1430  pcc->fft(planf, 0);
1431  pcc->complex_apply_negative_mask(prs_mask);
1432  pcc->combined_complex_product();
1433 
1434  double cv(0);
1435  long i, datasize = pcc->sizeX()*pcc->sizeY()*pcc->sizeZ()*pcc->images();
1436 
1437  for ( i=0; i<datasize; i++ )
1438  if ( (*prs_mask)[i] < 0 )
1439  cv += (pcc->complex(i)).real();
1440 
1441  delete pcc;
1442 
1443  if ( verbose & VERB_DEBUG )
1444  cout << "DEBUG img_cross_validate: cv=" << cv << endl;
1445 
1446  return cv;
1447 }
1448 
CHECK_PPX
#define CHECK_PPX
Definition: mg_processing.h:27
Bimage::fft_setup
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
Definition: Bimage_fft.cpp:29
img_prepare_projections
Bimage * img_prepare_projections(Bstring &filename, Bstring &mask_file, int bin, Bsymmetry *sym, double theta_step, double phi_step, double side_ang)
Generate projections if a 3D file, otherwise clean projections.
Definition: mg_orient.cpp:156
mg_particle_select.h
Select particles.
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
project_prepare_2D_references
Bimage * project_prepare_2D_references(Bproject *project, long first, long number, int bin, int ctf_action, double wiener)
Prepare reference images from particles.
Definition: mg_orient.cpp:65
WRITE_PPX
#define WRITE_PPX
Definition: mg_processing.h:26
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
NPOLANG
#define NPOLANG
Definition: Bimage.h:30
Bimage::shift
int shift(Vector3< double > vec, int fill_type=0, double fill=0)
Shifts an image.
Definition: Bimage_transform.cpp:589
kill_list
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
Definition: linked_list.cpp:214
Bparticle::view
View view
Definition: mg_processing.h:102
NFOM
#define NFOM
Definition: mg_processing.h:16
Bstring
Definition: Bstring.h:29
Bparticle
Definition: mg_processing.h:90
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:436
Bsub_image::view_angle
void view_angle(double d)
Definition: Bimage.h:161
Bproject::field
Bfield * field
Definition: mg_processing.h:346
img_ctf_apply_to_proj
int img_ctf_apply_to_proj(Bimage *proj, CTFparam em_ctf, double defocus, double res_lo, double res_hi, fft_plan planf_2D, fft_plan planb_2D)
Applies a CTF to a projection image.
Definition: mg_ctf.cpp:354
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2702
symmetry.h
Header file for general symmetry functions.
FOMType
FOMType
Definition: mg_processing.h:38
Bimage::center
int center(int fill_type=0, double fill=0)
Centers an image.
Definition: Bimage_transform.cpp:694
Vector3< double >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::pack_two_in_complex
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
Definition: Bimage_complex.cpp:679
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:719
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Bimage::complex_apply_negative_mask
int complex_apply_negative_mask(Bimage *pmask)
Applies a negative mask to a complex image.
Definition: Bimage_complex.cpp:550
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:105
PART_LOG
#define PART_LOG
Definition: mg_processing.h:25
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bfield::id
Bstring id
Definition: mg_processing.h:262
asymmetric_unit_views
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
Definition: symmetry.cpp:564
View
Definition: View.h:26
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:157
ppx_filename
Bstring ppx_filename(Bstring &id, int part_id)
Definition: rwmg.cpp:415
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
Bimage::find_shift
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Definition: Bimage_correlate.cpp:929
Bfield
Definition: mg_processing.h:260
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
Bsymmetry
Definition: symmetry.h:38
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:558
planf
fft_plan planf
Definition: bico.cpp:24
MODE
#define MODE
Definition: mg_processing.h:21
mg_orient.h
Library routines for single particle analysis.
Bimage::images
long images()
Definition: Bimage.h:504
project
Bproject * project
Definition: bshow.cpp:33
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
rwmg.h
Header file for reading and writing micrograph parameters.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
project_determine_orientations2
int project_determine_orientations2(Bproject *project, Bimage *proj, Bstring &mask_file, int bin, Bsymmetry *sym, int part_select, vector< double > &band, double res_lo, double res_hi, double res_polar, int ann_min, int ann_max, double shift_limit, double angle_limit, double edge_radius, int flags)
Find the orientation and origin of every image in a project.
Definition: mg_orient.cpp:1046
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:325
TSimple
@ TSimple
Definition: Bimage.h:59
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bimage::fspace_default_bands
vector< double > fspace_default_bands(double res_lo, double res_hi)
Sets up default frequency space bands to generate a mask.
Definition: Bimage_mask.cpp:773
Bimage::project
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
Definition: Bimage_project.cpp:31
Bimage::shift_background
int shift_background(double bkg)
Sets the background for each sub-image to a given value.
Definition: Bimage_background.cpp:351
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:92
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
SMALLFLOAT
#define SMALLFLOAT
Definition: utilities.h:46
Bimage::fft
int fft()
Definition: Bimage.h:830
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:255
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:109
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bimage
General image parameter class.
Definition: Bimage.h:177
part_find_first
Bparticle * part_find_first(Bproject *project)
Finds the first particle in a project.
Definition: mg_processing.cpp:283
Bproject
Definition: mg_processing.h:336
Bimage::align2D
double align2D(Bimage *pref, double res_polar, int ann_min, int ann_max, Bimage *prs_mask, double shift_limit, double angle_limit, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
Finds the best in-plane alignment for two 2D images using polar power spectra.
Definition: Bimage_align.cpp:881
find_asymmetric_unit_view
View find_asymmetric_unit_view(Bsymmetry *sym, View theview)
Finds the corresponding view in the asymmetric unit.
Definition: symmetry.cpp:850
part_select
Tcl_Obj * part_select(Bparticle *part, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bmg.cpp:563
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
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1027
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
side_views
View * side_views(Bsymmetry *sym, double side_ang, double theta_step, double phi_step)
Initializes a set of views around the z-axis for helical projection.
Definition: symmetry.cpp:763
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
verbose
int verbose
fft_setup_plan
fft_plan fft_setup_plan(long x, long y, long z, fft_direction dir, int opt)
Sets up a plan for fast Fourier transforms.
Definition: fft.cpp:31
Bstring::length
long length() const
Definition: Bstring.cpp:263
img_ctf_apply
int img_ctf_apply(Bimage *p, CTFparam em_ctf, int action, double wiener, double lores, double hires)
Applies or corrects for the contrast transfer function (CTF).
Definition: mg_ctf.cpp:237
Bparticle::def
double def
Definition: mg_processing.h:96
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
CTFparam
Definition: ctf.h:28
rwimg.h
Header file for 2D and 3D image I/O.
Bmicrograph::ctf
CTFparam * ctf
Definition: mg_processing.h:241
system_memory
long system_memory()
Returns system memory size.
Definition: utilities.cpp:211
Bfield::next
Bfield * next
Definition: mg_processing.h:261
APPLY_CTF
#define APPLY_CTF
Definition: mg_processing.h:24
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
fft_plan
fftwf_plan fft_plan
Definition: fft.h:20
part_compare
Bparticle part_compare(Bimage *p, Bimage *proj, Bimage *prs_mask, long k, int bin, CTFparam *ctf, double res_lo, double res_hi, double res_polar, long ann_min, long ann_max, double shift_limit, double angle_limit, double edge_radius, int flags, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
Definition: mg_orient.cpp:789
project_mg_particle_array
Bparticle ** project_mg_particle_array(Bproject *project, int part_select, long &npart)
Sets up an array of selected particle pointers.
Definition: mg_processing.cpp:1282
CTFparam::defocus_average
double defocus_average()
Definition: ctf.h:106
ppx_check
int ppx_check(Bparticle *part, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:441
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
linked_list.h
Header file for generalized linked list functions.
project_determine_orientations
int project_determine_orientations(Bproject *project, Bimage *proj, Bstring &mask_file, int bin, Bsymmetry *sym, int part_select, vector< double > &band, double res_lo, double res_hi, double res_polar, int ann_min, int ann_max, double shift_limit, double angle_limit, double edge_radius, int flags)
Find the orientation and origin of every image in a project.
Definition: mg_orient.cpp:329
SCharacter
@ SCharacter
Definition: utilities.h:154
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
Bimage::minimum
double minimum()
Definition: Bimage.h:541
Bimage::align2D_pps
double align2D_pps(Bimage *pref, double res_hi, double res_lo, double shift_limit, double angle_limit, fft_plan planf, fft_plan planb)
Finds the best in-plane alignment for two 2D images using polar power spectra.
Definition: Bimage_align.cpp:794
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
correlation_coefficient_adjust
double correlation_coefficient_adjust(double cc, double std)
Definition: mg_orient.cpp:35
View::negate
void negate()
Definition: View.h:117
img_read_projection
Bimage * img_read_projection(Bstring &proj_file, int multi_file, int proj_num)
Definition: mg_orient.cpp:271
Bsymmetry::label
Bstring label
Definition: symmetry.h:41
write_particle
int write_particle(Bstring &filename, Bparticle *part, int euler_flag, int omega_flag, FOMType fom_tag[NFOM])
Definition: rwmg.cpp:406
FOM_CV
@ FOM_CV
Definition: mg_processing.h:42
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:321
Float
@ Float
Definition: utilities.h:161
View::angle
double angle()
Definition: View.h:98
img_cross_validate
double img_cross_validate(Bimage *p, Bimage *pref, Bimage *prs_mask, fft_plan planf)
Rotates and shifts a reference image and calculates a cross-validation coefficient.
Definition: mg_orient.cpp:1422
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
ps_views.h
Header file for postscript tools dealing with views.
part_determine_orientation
int part_determine_orientation(Bparticle *part, Bimage *proj, Bimage *part_mask, Bimage *prs_mask, Bsymmetry *sym, int bin, double res_lo, double res_hi, double res_polar, int ann_min, int ann_max, double shift_limit, double angle_limit, double edge_radius, int flags, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
Definition: mg_orient.cpp:535
project_determine_origins
int project_determine_origins(Bproject *project, Bimage *proj, int bin, Bsymmetry *sym, int part_select, double res_lo, double res_hi, double shift_limit, int flags)
Find the origin of every image in a project.
Definition: mg_orient.cpp:1243
Bimage::mask_fspace_banded
int mask_fspace_banded(vector< double > &band)
Generate reciprocal space mask based on a specification of bands.
Definition: Bimage_mask.cpp:808
Bimage::combined_complex_product
int combined_complex_product()
Calculates the complex conjugate product of a complex image resulting from combining and Fourier tran...
Definition: Bimage_complex.cpp:813
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bparticle::id
int id
Definition: mg_processing.h:93
kernel
Definition: kernlut.h:14
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
FOM
@ FOM
Definition: mg_processing.h:40
FSI_Kernel
Definition: FSI_Kernel.h:14
TWOPI
#define TWOPI
Definition: utilities.h:72
Bproject::fom_tag
FOMType fom_tag[NFOM]
Definition: mg_processing.h:345
part_determine_orientation2
int part_determine_orientation2(Bparticle *part, Bimage *proj, Bimage *part_mask, Bimage *prs_mask, Bsymmetry *sym, int bin, double res_lo, double res_hi, double res_polar, int ann_min, int ann_max, double shift_limit, double angle_limit, double edge_radius, int flags, fft_plan planf_1D, fft_plan planb_1D, fft_plan planf_2D, fft_plan planb_2D)
Definition: mg_orient.cpp:837
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163