Bsoft  2.1.0
Bernard's software package
mg_hand.cpp
Go to the documentation of this file.
1 
10 #include "mg_hand.h"
11 #include "mg_select.h"
12 #include "Matrix3.h"
13 #include "qsort_functions.h"
14 #include "utilities.h"
15 
16 
17 // Global variables
18 extern int verbose; // Level of output to the screen
19 
20 
21 /*
22 @Object: struct Hand_Stats
23 @brief Statistical parameters for the hand functions (handedness tilt
24  experiment), and sums needed to compute them. Also, counts keep
25  score of hand A vs. hand B.
26 @Features:
27 **/
28 struct Hand_Stats {
29  int CountA; // Count of all particles that matched best with hand A, B, or neither
30  int CountB;
31  int Tie;
32  double Avg1A; // Average and Standard deviations:
33  double Avg2A; // control, view 1 hand A (1A); and hands A (2A) and B (2B)
34  double Avg2B;
35  double Std1A;
36  double Std2A;
37  double Std2B;
38  double AvgAbsDiff_2Aphi; // Absolute differences: measured angles - predicted angles
50  double Sum_1A; // Sums for computing averages and their standard deviations
51  double Sum_2A; // of correlation coefficients
52  double Sum_2B;
53  double Sum_1Asq;
54  double Sum_2Asq;
55  double Sum_2Bsq;
56  double Sum_AbsDiffPhi2A; // Sums for computing averages and their standard deviations
57  double Sum_AbsDiffThe2A; // of the absoluted differences between measured and predicted
58  double Sum_AbsDiffPsi2A; // angles
68 };
69 
70 
71 // Internal function prototypes
72 int field_get_handedness(Bimage* mapA, Bimage* mapB, Bmicrograph* mg1, Bmicrograph* mg2, Hand_Stats* Global,
73  double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min, int diff_out,
74  int origins2, Bstring outimg, int fieldnum);
76  Bparticle* particle1, Bparticle* particle2,
77  Hand_Stats* Pair, double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min,
78  int diff_out, int origins2, Bstring outimg, int fieldnum);
79 
80 int hand_compute_stats(Hand_Stats* stats, int diff_out);
81 int hand_prepare_image(Bimage* p, double resmin, double resmax);
82 int hand_print_outheader(int which_one, int diff_out);
83 int hand_print_stats(Hand_Stats* stats, int which_one, int diff_out);
84 int hand_write_img(Bimage* img, Bstring imgname, Bstring outimg, int fieldnum, int num);
85 
86 
87 
114 int project_get_handedness(Bimage* mapA, Bproject* project, double* mg_ang,
115  int* mg_index, int* mg_select, double rad_min, double rad_max,
116  double res_min, double res_max, double AmB_min, double AB_min,
117  int diff_out, int origins2, Bstring outimg)
118 {
119  project->fom_tag[1] = FOM_HAND_A;
120  project->fom_tag[2] = FOM_HAND_B;
121 
122  Bfield* field=NULL; // Placeholder for loop over the fields-of-view in project
123  int handedness; // Output to calling function: 1=hand A, 2=hand B, 0=undetermined
124  int ifield; // index for field block
125  Bmicrograph *mg1=NULL, *mg2=NULL; // Structures to hold input data for first and second views of a micrograph tilt pair
126  int n_Global; // Number of particle-image pairs analyzed, for statistical calculations
127  Bimage *mapB=NULL; // Mirror image of input map (mapA)
128 
129  Hand_Stats* Global = new Hand_Stats; // Global statistics (i.e. for all micrographs)
130  memset(Global, 0, sizeof(Hand_Stats)); // zero sums for global statistics
131 
132  if ( verbose ) {
133  cout << "Minimum Radius (pixels): " << rad_min << endl;
134  cout << "Maximum Radius (pixels): " << rad_max << endl;
135  cout << "High-Pass filter (angs.): " << res_min << endl;
136  cout << "Low-Pass filter (angs.): " << res_max << endl << endl;
137  }
138 
139 
140  // Copy enantiomer and invert it through origin where equation is
141  // mirror(x,y,z) = enantiomer(-x,-y,-z)
142  // if origin is given as (0,0,0). mapB is hand B map.
143  mapA->calculate_background(); // first be sure background is set correctly
144  Vector3<double> scale(-1,-1,-1), translate;
145  Matrix3 mat(1);
146 // mapB = img_transform_copy(mapA, mapA->size(), scale, mapA->image->origin(), translate, mat, FILL_BACKGROUND, 0);
147  mapB = mapA->transform(mapA->size(), scale, mapA->image->origin(), translate, mat, FILL_BACKGROUND, 0);
148 
149  if (verbose) {
150  cout << "Hand A map origin: " << mapA->image->origin() << endl;
151  cout << "Hand B map origin: " << mapB->image->origin() << endl;
152  cout << "Map Sampling (angs./pixel): " << mapA->sampling(0) << endl << endl;
153  }
154 
155 
156  // Determine handedness
157  for ( field = project->field, ifield=1; field; field = field->next, ifield++ ) {
158  // select first view
159  mg1 = field_find_micrograph(field, mg_select[0], mg_index[0], mg_ang[0]);
160  // select second view
161  mg2 = field_find_micrograph(field, mg_select[1], mg_index[1], mg_ang[1]);
162  // find handedness for a field
163  field_get_handedness(mapA, mapB, mg1, mg2, Global, rad_min, rad_max,
164  res_min, res_max, AmB_min, AB_min, diff_out, origins2, outimg, ifield);
165  }
166 
167 
168  // Calculate and print global statistics to screen
169  hand_compute_stats(Global, diff_out);
170  if (verbose) {
171  cout << endl << endl;
172  hand_print_stats(Global, 1, diff_out);
173  }
174 
175 
176  // If 95% of particles agree with one handedness, handedness=1 if hand A or 2 if hand B. 0 if < 95%.
177  n_Global = Global->CountA + Global->CountB + Global->Tie;
178  if ( (Global->CountA/n_Global) >= 0.95 ) {
179  handedness = 1;
180  if (verbose) cout << "Output map has hand A (same as input map)." << endl;
181  } else if ( (Global->CountB/n_Global) >= 0.95 ) {
182  handedness = 2;
183  if (verbose) cout << "Output map has hand B (opposite of input map)." << endl;
184  } else {
185  handedness = 0;
186  if (verbose)
187  cout << "Output map is undetermined because the number of selected" << endl;
188  cout << "particles favoring hand A or B was not 95% or greater." << endl;
189  }
190 
191 
192  // Memory clean-up
193  delete mapB;
194  delete Global;
195 
196 
197  return handedness;
198 }
199 
200 
201 
202 /*
203 @brief Determines handedness for all selected particles (sel > 0) for a
204  field--specifically a selected tilt pair of micrographs from the
205  field.
206 @param *mapA 3D map (hand A)
207 @param *mapB 3D map (hand B)
208 @param *mg1 Micrograph for view 1 of field
209 @param *mg2 Micrograph for view 2 of field
210 @param *Global Statistics for all fields-of-view
211 @param rad_min minimum radius for FOM calculation (pixels)
212 @param rad_max maximum radius for FOM calculation (pixels)
213 @param res_min minimum resolution for FOM calculation (angs.)
214 @param res_max maximum resolution for FOM calculation (angs.)
215 @param AmB_min |FOMA - FOMB| must be this value or greater
216 @param AB_min min. acceptable value for FOM of correct hand
217 @param diff_out output difference of measured & predicted orientations
218 @param origins2 flag to determine origins for second view
219 @param outimg prefix & suffix for output projection files
220 @param fieldnum index of current field (for image output)
221 @return int error code.
222 
223  Gets tilt-axis direction and rotation angle for a micrograph pair.
224  Then, loops through the selected particles in pair. Sends data to
225  function get_handedness_from_tilt_pair, where handedness is
226  determined. Statistics are calculated for each pair and sums for
227  global statistics are tabulated.
228 
229 **/
230 int field_get_handedness(Bimage* mapA, Bimage* mapB, Bmicrograph* mg1, Bmicrograph* mg2, Hand_Stats* Global,
231  double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min, int diff_out,
232  int origins2, Bstring outimg, int fieldnum)
233 {
234 
235  Bparticle* particle1 = NULL; // particles being processed
236  Bparticle* particle2 = NULL;
237 
238  Hand_Stats* Pair = new Hand_Stats; // Statistics for current micrograph pair
239  memset(Pair, 0, sizeof(Hand_Stats)); // zero sums for pair statistics
240 
241  // Get the pair's tilt-axis direction and the rotation angle from the mg1 and mg2 structures
242  if ( mg1->tilt_axis != mg2->tilt_axis ) {
243  error_show("Error in field_get_handedness", __FILE__, __LINE__);
244  cerr << "The tilt-axis direction is not the same or is invalid in this pair:" << endl;
245  cerr << mg1->fpart << " axis dir = " << mg1->tilt_axis*180.0/M_PI << endl;
246  cerr << mg2->fpart << " axis dir = " << mg2->tilt_axis*180.0/M_PI << endl;
247  cerr << "You may have a pair mismatch or may need to enter a value for both micrographs." << endl;
248  return -1;
249  }
250 
251  if ( verbose ) {
252  cout << "Tilt pair:" << endl;
253  cout << "Micrograph 1: " << mg1->fpart << endl;
254  cout << "Micrograph 2: " << mg2->fpart << endl;
255  cout << "Tilt-axis direction: " << mg1->tilt_axis*(180/M_PI) << endl;
256  cout << "Rotation angle: " << (mg2->tilt_angle - mg1->tilt_angle)*(180/M_PI) << endl << endl;
257  }
258 
259  // Loop through all particles in first micrograph
260  // -It is assumed that the ID numbers in the first and second micrographs refer to the same imaged object.
261  // -To be analyzed, a particle must
262  // a) have the identical number in second micrograph
263  // b) sel > 0
264  if (verbose) hand_print_outheader(0, diff_out); // Header for screen output
265  for ( particle1=mg1->part; particle1; particle1=particle1->next ) if ( particle1->sel ) {
266  // loop through particles in second mg to find identical particle ID
267  for ( particle2=mg2->part; particle2 && particle1->id != particle2->id; particle2=particle2->next ) ;
268  if ( particle2 )
269  get_handedness_from_tilt_pair(mapA, mapB, mg1, mg2, particle1, particle2, Pair,
270  rad_min, rad_max, res_min, res_max, AmB_min, AB_min, diff_out, origins2, outimg, fieldnum);
271  }
272 
273 
274  // Calculate and output pair statistics
275  hand_compute_stats(Pair, diff_out);
276  if ( verbose )
277  hand_print_stats(Pair, 0, diff_out);
278 
279  // Tabulate sums for global statistics
280  Global->Sum_1A += Pair->Sum_1A;
281  Global->Sum_2A += Pair->Sum_2A;
282  Global->Sum_2B += Pair->Sum_2B;
283  Global->Sum_1Asq += Pair->Sum_1Asq;
284  Global->Sum_2Asq += Pair->Sum_2Asq;
285  Global->Sum_2Bsq += Pair->Sum_2Bsq;
286  Global->CountA += Pair->CountA;
287  Global->CountB += Pair->CountB;
288  Global->Tie += Pair->Tie;
289  if (diff_out > 0) {
290  Global->Sum_AbsDiffPhi2A += Pair->Sum_AbsDiffPhi2A;
291  Global->Sum_AbsDiffThe2A += Pair->Sum_AbsDiffThe2A;
292  Global->Sum_AbsDiffPsi2A += Pair->Sum_AbsDiffPsi2A;
293  Global->Sum_AbsDiffPhi2B += Pair->Sum_AbsDiffPhi2B;
294  Global->Sum_AbsDiffThe2B += Pair->Sum_AbsDiffThe2B;
295  Global->Sum_AbsDiffPsi2B += Pair->Sum_AbsDiffPsi2B;
296  Global->Sum_AbsDiffPhi2Asq += Pair->Sum_AbsDiffPhi2Asq;
297  Global->Sum_AbsDiffThe2Asq += Pair->Sum_AbsDiffThe2Asq;
298  Global->Sum_AbsDiffPsi2Asq += Pair->Sum_AbsDiffPsi2Asq;
299  Global->Sum_AbsDiffPhi2Bsq += Pair->Sum_AbsDiffPhi2Bsq;
300  Global->Sum_AbsDiffThe2Bsq += Pair->Sum_AbsDiffThe2Bsq;
301  Global->Sum_AbsDiffPsi2Bsq += Pair->Sum_AbsDiffPsi2Bsq;
302  }
303 
304 
305  delete Pair;
306 
307  return 0;
308 
309 } // End of function field_get_handedness
310 
311 
312 
313 /*
314 @brief Determines handedness from tilt pair of images, (two views of the
315  same specimen in which the specimen was rotated about a known
316  axis and by a known angle).
317 
318 @param *mapA 3D map (hand A)
319 @param *mapB 3D map (hand B)
320 @param *mg1 Micrograph for view 1
321 @param *mg2 Micrograph for view 2
322 @param *particle1 Particle from view 1
323 @param *particle2 Particle from view 2
324 @param *Pair Statistics for current micrograph pair
325 @param rad_min minimum radius for FOM calculation (pixels)
326 @param rad_max maximum radius for FOM calculation (pixels)
327 @param res_min minimum resolution for FOM calculation (angs.)
328 @param res_max maximum resolution for FOM calculation (angs.)
329 @param AmB_min |FOMA - FOMB| must be this value or greater
330 @param AB_min min. acceptable value for FOM of correct hand
331 @param diff_out output difference of measured & predicted orientations
332 @param origins2 flag to determine origins for second view
333 @param outimg prefix & suffix for output projection files
334 @param fieldnum index of current field (for image output)
335 @return int 0.
336 
337  -Calculate two predicted orientations for second view from first
338  orientation, the tilt-axis direction, and the rotation angle. One
339  orientation is the predicted orientation for hand A (handedness
340  of input 3D map and first orientation) in the second view. The
341  other is the predicted orientation for hand B (mirror of hand A
342  map).
343  -Projections made of input map at first orientation and predicted
344  second orientation of hand A.
345  -Projection made of mirror map at predicted second orientation of
346  hand B.
347  -Projections of predicted second orientations are compared to image
348  of second view.
349  -As a control, projection of first orientation is compared to image
350  of first view.
351 **/
353  Bparticle* particle1, Bparticle* particle2,
354  Hand_Stats* Pair, double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min,
355  int diff_out, int origins2, Bstring outimg, int fieldnum)
356 {
357  double axis_dir(mg1->tilt_axis); // Angle of the tilt axis on the micrograph
358  double rotation_angle(mg2->tilt_angle - mg1->tilt_angle); // Angle of rotation about the tilt axis = tilt_angle (view2) - tilt_angle (view1)
359 
360  double max_radius; // radius of largest sphere that will fit inside the 3D map
361  double cc1A; // Correlation coefficient for first view and predicted second views
362  double cc2A, cc2B; // model projections vs. particle image
363  double diff2A_phi(0); // measured angle - predicted angle
364  double diff2A_the(0);
365  double diff2A_psi(0);
366  double diff2B_phi(0);
367  double diff2B_the(0);
368  double diff2B_psi(0);
369  int ThresholdOK(1); // flag for |A-B| threshold
370 
371  Vector3<double> translate1, translate2A, translate2B; // Translational-shift arrays for particle images
372  Vector3<double> translate0; // for cross-correlation option
373 
374  Euler angles1A; // Euler angles for first view
375  Euler angles2A, angles2B; // Euler angles for second view, hands A & B
376  Euler euler2; // Euler angles for second view (input data)
377  View view1A(particle1->view); // View vector and angle for first view, hand A
378  View view1B(view1A);
379  view1B.angle(angle_set_negPI_to_PI(view1B.angle()+M_PI));
380  View view2; // View vector and angle for second view (input data)
381 
382  Matrix3 rot_matrix1A(1); // 3x3 matrix for first and predicted second orientations,
383  Matrix3 rot_matrix1B(1); // for hands A and B
384  Matrix3 rot_matrix2A(1);
385  Matrix3 rot_matrix2B(1);
386  Matrix3 rot_matrixtilt(1); // 3x3 matrix for the tilt axis
387 
388  Bimage* img1 = NULL; // a particle image from first micrograph
389  Bimage* img2A = NULL; // a particle image from second micrograph
390  Bimage* img2B = NULL; // a copy of img2A, but it may have a different origin
391  Bimage* prj1A = NULL; // a projection image corresponding to the particle image from first micrograph
392  Bimage* prj2A = NULL; // a projection image from hand A map, corresponding to the particle image from second micrograph
393  Bimage* prj2B = NULL; // a projection image from hand B map, corresponding to the particle image from second micrograph
394 
395 
396  // General parameters
397  max_radius = mapA->maximum_included_radius(); // reduces unnecessary computations in rotate_project and img_find_shift
398 
399 
400  // Compute predicted orientations for second view (for both hand A and hand B)
401  // -The addition of Pi for the 1B orientation must be added to the psi 1A value, it cannot be added to the
402  // tilt-axis direction. This is because the tilt axis does not change--and neither does the first view.
403  // Only the psi value for the first view changes.
404  rot_matrix1A = view1A.matrix(); // rotation matrices for views 1A & 1B
405  rot_matrix1B = view1B.matrix();
406 
407  rot_matrixtilt = Matrix3(rotation_angle,angle_set_negPI_to_PI(axis_dir)); // rotation matrix for tilting operation
408 
409  rot_matrix2A = rot_matrix1A * rot_matrixtilt; // rotation matrices for predicted views 2A & 2B
410  rot_matrix2B = rot_matrix1B * rot_matrixtilt;
411 
412  // Get orientation angles
413  angles1A = Euler(view1A);
414  angles2A = Euler(rot_matrix2A); // get predicted angles from matrices
415  angles2B = Euler(rot_matrix2B);
416 
417  if ( verbose & VERB_PROCESS ) {
418  cout << "Input orientation (phi, theta, psi) = " <<
419  angles1A.phi()*(180/M_PI) << " " << angles1A.theta()*(180/M_PI) << " " << angles1A.psi()*(180/M_PI) << endl;
420  cout << "Predicted orientation 2A (phi, theta, psi) = " <<
421  angles2A.phi()*(180/M_PI) << " " << angles2A.theta()*(180/M_PI) << " " << angles2A.psi()*(180/M_PI) << endl;
422  cout << "Predicted orientation 2B (phi, theta, psi) = " <<
423  angles2B.phi()*(180/M_PI) << " " << angles2B.theta()*(180/M_PI) << " " << angles2B.psi()*(180/M_PI) << endl;
424  }
425  if ( verbose & VERB_FULL ) {
426  cout << "Matrix for first view, hand A" << endl;
427  cout << rot_matrix1A << endl;
428  cout << "Matrix for tilt" << endl;
429  cout << rot_matrixtilt << endl;
430  cout << "Matrix for second view, hand A" << endl;
431  cout << rot_matrix2A << endl;
432  cout << "Matrix for second view, hand B" << endl;
433  cout << rot_matrix2B << endl;
434  }
435 
436 
437  // Read images and convert to double point, set pixel size to value from micrograph structure (if different)
438  img1 = read_img(mg1->fpart,1,(particle1->id - 1));
439  img1->change_type(Float);
440  img1->sampling(mg1->pixel_size);
441  img1->origin(particle1->ori);
442 
443  img2A = read_img(mg2->fpart,1,(particle2->id - 1));
444  img2A->change_type(Float);
445  img2A->sampling(mg2->pixel_size);
446  img2A->origin(particle2->ori);
447 
448  img2B = img2A->copy(); // copy made for hand 2B test because origin may differ
449 
450  Vector3<double> oriA(mapA->image->origin()[0], mapA->image->origin()[1], 0);
451  Vector3<double> oriB(mapB->image->origin()[0], mapB->image->origin()[1], 0);
452 
453  // Get translational offset (x & y only, z offset = 0) and set origins of data images
454  // -The translational offset is the origin of the particle image minus the center of the map array
455  translate1 = particle1->ori - oriA;
456 
457  if (origins2 == 0) { // Get image origins (second view) from input parameter file
458  translate2A = particle2->ori - oriA;
459  translate2B = particle2->ori - oriB;
460  } else if (origins2 == 1) { // Determine origins of second view via cross-correlation with projections
461  prj2A = mapA->rotate_project(rot_matrix2A, translate0, max_radius); // project with no shifts
462  prj2B = mapB->rotate_project(rot_matrix2B, translate0, max_radius);
463 
464 // img_find_shift(img2A, prj2A, NULL, res_max, res_min, max_radius, 0, 1); // hand A
465  img2A->find_shift(prj2A, NULL, res_max, res_min, max_radius, 0, 1); // hand A
466  translate2A = prj2A->image->origin() - img2A->image->origin();
467  img2A->image->origin(translate2A + oriA);
468 
469 // img_find_shift(img2B, prj2B, NULL, res_max, res_min, max_radius, 0, 1); // hand B
470  img2B->find_shift(prj2B, NULL, res_max, res_min, max_radius, 0, 1); // hand B
471  translate2B = prj2B->image->origin() - img2B->image->origin();
472 // img2B->image->origin(translate2B + oriB);
473  img2B->origin(translate2B + oriB);
474 
475  delete prj2A;
476  delete prj2B;
477  } else if (origins2 == 2) { // Get image origins (second view) from Bsubimage structure
478  translate2A = img2A->image->origin() - oriA;
479  translate2B = img2B->image->origin() - oriB;
480  }
481 
482 
483  // Compute projections for 1A, 2A, and 2B orientations, origins put at respective image origin
484  prj1A = mapA->rotate_project(rot_matrix1A, translate1, max_radius);
485  prj2A = mapA->rotate_project(rot_matrix2A, translate2A, max_radius);
486  prj2B = mapB->rotate_project(rot_matrix2B, translate2B, max_radius);
487 
488 
489  // Write projections to disk, if desired
490  if ( outimg.length() ) {
491  hand_write_img(prj1A, "prj1a", outimg, fieldnum, particle1->id);
492  hand_write_img(prj2A, "prj2a", outimg, fieldnum, particle1->id);
493  hand_write_img(prj2B, "prj2b", outimg, fieldnum, particle1->id);
494  }
495 
496 
497  // Projections have same origin and pixel size as images
498 // prj1A->image->origin(img1->image->origin());
499 // prj2A->image->origin(img2A->image->origin());
500 // prj2B->image->origin(img2B->image->origin());
501  prj1A->origin(0, img1->image->origin());
502  prj2A->origin(0, img2A->image->origin());
503  prj2B->origin(0, img2B->image->origin());
504 
505  prj1A->sampling(img1->sampling(0));
506  prj2A->sampling(img2A->sampling(0));
507  prj2B->sampling(img2B->sampling(0));
508 
509 
510  // Prepare images for comparison test by setting statistics and applying a bandpass filter
511  hand_prepare_image(img1, res_min, res_max);
512  hand_prepare_image(img2A,res_min, res_max);
513  hand_prepare_image(img2B,res_min, res_max);
514  hand_prepare_image(prj1A,res_min, res_max);
515  hand_prepare_image(prj2A,res_min, res_max);
516  hand_prepare_image(prj2B,res_min, res_max);
517 
518 
519  // Debugging output
520  if ( outimg.length() && (verbose & VERB_DEBUG) ) {
521  hand_write_img(prj1A, "prj1a", outimg, fieldnum, particle1->id);
522  hand_write_img(prj2A, "prj2a", outimg, fieldnum, particle1->id);
523  hand_write_img(prj2B, "prj2b", outimg, fieldnum, particle1->id);
524  hand_write_img(img1, "img1", outimg, fieldnum, particle1->id);
525  hand_write_img(img2A, "img2a", outimg, fieldnum, particle1->id); // img2a and img2b will appear identical
526  hand_write_img(img2B, "img2b", outimg, fieldnum, particle1->id); // but their origins could be different
527  }
528  if ( verbose & VERB_DEBUG ) {
529  cout << "General parameters" << endl;
530  cout << " radius min,max: " << rad_min << " " << rad_max << endl;
531  cout << " resolution min,max: " << res_min << " " << res_max << endl;
532  cout << " micrograph 1,2: " << mg1->id << " " << mg2->id << endl;
533  cout << " particle 1,2: " << particle1->id << " " << particle2->id << endl;
534  cout << "Image 1 parameters" << endl;
535  cout << " background: " << img1->background(long(0)) << endl;
536  cout << " origin (x,y,z): " << img1->image->origin() << endl;
537  cout << " pixel size (x,y,z): " << img1->sampling(0) << endl;
538  cout << "Projection 1A parameters" << endl;
539  cout << " background: " << img2A->background(long(0)) << endl;
540  cout << " origin (x,y,z): " << prj1A->image->origin() << endl;
541  cout << " pixel size (x,y,z): " << prj1A->sampling(0) << endl;
542  cout << "Image 2A parameters" << endl;
543  cout << " background: " << img2B->background(long(0)) << endl;
544  cout << " origin (x,y,z): " << img2A->image->origin() << endl;
545  cout << " pixel size (x,y,z): " << img2A->sampling(0) << endl;
546  cout << "Projection 2A parameters" << endl;
547  cout << " background: " << prj1A->background(long(0)) << endl;
548  cout << " origin (x,y,z): " << prj2A->image->origin() << endl;
549  cout << " pixel size (x,y,z): " << prj2A->sampling(0) << endl;
550  cout << "Image 2B parameters" << endl;
551  cout << " background: " << prj2A->background(long(0)) << endl;
552  cout << " origin (x,y,z): " << img2B->image->origin() << endl;
553  cout << " pixel size (x,y,z): " << img2B->sampling(0) << endl;
554  cout << "Projection 2B parameters" << endl;
555  cout << " background: " << prj2B->background(long(0)) << endl;
556  cout << " origin (x,y,z): " << prj2B->image->origin() << endl;
557  cout << " pixel size (x,y,z): " << prj2B->sampling(0) << endl;
558  }
559 
560 
561  // Compare images to projections
562 // cc1A = img_correlation_coefficient_radial(img1, prj1A, rad_min, rad_max);
563 // cc2A = img_correlation_coefficient_radial(img2A, prj2A, rad_min, rad_max);
564 // cc2B = img_correlation_coefficient_radial(img2B, prj2B, rad_min, rad_max);
565  cc1A = img1->correlate(prj1A, rad_min, rad_max, NULL, 0);
566  cc2A = img2A->correlate(prj2A, rad_min, rad_max, NULL, 0);
567  cc2B = img2B->correlate(prj2B, rad_min, rad_max, NULL, 0);
568 
569  particle1->fom[1] = cc1A;
570  particle2->fom[1] = cc2A;
571  particle2->fom[2] = cc2B;
572 
573 
574  // Print CCs to screen, check thresholds, selection option:
575  // -If 1) |difference| of CC2A-CC2B or 2) largest CC (CC2A or CC2B)
576  // is not equal to or greater than their respective thresholds,
577  // discard this particle from statistics and deselected it
578  // -User may also set selection numbers for hand A (1) or B (2)
579  if (verbose) cout << setprecision(4) << particle1->id << tab << cc1A << tab << cc2A << tab << cc2B << tab << cc2A-cc2B;
580 
581  if ( fabs(cc2A-cc2B) >= AmB_min ) { // CC difference > difference threshold
582  if ( (cc2A < AB_min) && (cc2B < AB_min) ) { // both CCs less than CC threshold
583  ThresholdOK = 0;
584  } else { // at least one CC is >= CC threshold
585  if ( cc2A > cc2B ) { // Hand A
586  particle1->sel = 1;
587  particle2->sel = 1;
588  } else { // Hand B
589  particle1->sel = 2;
590  particle2->sel = 2;
591  }
592  if ( verbose && (diff_out > 0) ) { // No Deselections: print predicted orientations to screen
593  cout << setprecision(2) << tab << (180/M_PI)*angles2A.phi() << tab << (180/M_PI)*angles2A.theta() << tab << (180/M_PI)*angles2A.psi();
594  cout << tab << (180/M_PI)*angles2B.phi() << tab << (180/M_PI)*angles2B.theta() << tab << (180/M_PI)*angles2B.psi();
595  }
596  }
597  } else {
598  ThresholdOK = 0;
599  }
600 
601  if ( !ThresholdOK ) {
602  particle1->sel = 0;
603  particle2->sel = 0;
604 // if (verbose) cout << "\t|A - B| < threshold, deselected (0)";
605  }
606  if ( verbose && !diff_out ) cout << tab << ThresholdOK;
607  if (verbose) cout << endl;
608 
609 
610  // Compute difference between measured and predicted angles if desired and if |A-B| threshold is okay
611  // -absolute difference will be tallied for pair and global statistics
612  if ( (ThresholdOK == 1) && (diff_out > 0) ) {
613 
614  view2 = particle2->view;
615  euler2 = Euler(view2);
616 // euler2.check();
617 // angles2A.check();
618 // angles2B.check();
619 
620  diff2A_phi = angle_set_negPI_to_PI(euler2.phi() - angles2A.phi()); // use angle_set_negPI_to_PI to get min. difference
621  diff2A_the = euler2.theta() - angles2A.theta();
622  diff2A_psi = angle_set_negPI_to_PI(euler2.psi() - angles2A.psi());
623  diff2B_phi = angle_set_negPI_to_PI(euler2.phi() - angles2B.phi());
624  diff2B_the = euler2.theta() - angles2B.theta();
625  diff2B_psi = angle_set_negPI_to_PI(euler2.psi() - angles2B.psi());
626 
627  if ( verbose && (diff_out >= 2) ) {
628  cout << " Measured - Predicted =";
629  cout << " " << (180/M_PI)*diff2A_phi;
630  cout << " " << (180/M_PI)*diff2A_the;
631  cout << " " << (180/M_PI)*diff2A_psi;
632  cout << " " << (180/M_PI)*diff2B_phi;
633  cout << " " << (180/M_PI)*diff2B_the;
634  cout << " " << (180/M_PI)*diff2B_psi << endl << endl;
635  }
636  }
637 
638 
639  // Tabulate sums for pair statistics if |A-B| threshold is okay
640  if (ThresholdOK == 1) {
641  Pair->Sum_1A += cc1A;
642  Pair->Sum_2A += cc2A;
643  Pair->Sum_2B += cc2B;
644  Pair->Sum_1Asq += cc1A*cc1A;
645  Pair->Sum_2Asq += cc2A*cc2A;
646  Pair->Sum_2Bsq += cc2B*cc2B;
647  if (cc2A > cc2B) // Count to see which handedness wins the contest
648  Pair->CountA++;
649  else if (cc2B > cc2A)
650  Pair->CountB++;
651  else
652  Pair->Tie++;
653  if (diff_out > 0) {
654  Pair->Sum_AbsDiffPhi2A += fabs(diff2A_phi);
655  Pair->Sum_AbsDiffThe2A += fabs(diff2A_the);
656  Pair->Sum_AbsDiffPsi2A += fabs(diff2A_psi);
657  Pair->Sum_AbsDiffPhi2B += fabs(diff2B_phi);
658  Pair->Sum_AbsDiffThe2B += fabs(diff2B_the);
659  Pair->Sum_AbsDiffPsi2B += fabs(diff2B_psi);
660  Pair->Sum_AbsDiffPhi2Asq += diff2A_phi*diff2A_phi;
661  Pair->Sum_AbsDiffThe2Asq += diff2A_the*diff2A_the;
662  Pair->Sum_AbsDiffPsi2Asq += diff2A_psi*diff2A_psi;
663  Pair->Sum_AbsDiffPhi2Bsq += diff2B_phi*diff2B_phi;
664  Pair->Sum_AbsDiffThe2Bsq += diff2B_the*diff2B_the;
665  Pair->Sum_AbsDiffPsi2Bsq += diff2B_psi*diff2B_psi;
666  }
667  }
668 
669 
670  // Memory cleanup
671  delete img1;
672  delete img2A;
673  delete img2B;
674  delete prj1A;
675  delete prj2A;
676  delete prj2B;
677 
678  return 0;
679 
680 
681 } // End of function get_handedness_from_tilt_pair
682 
683 
684 
685 /*
686 @brief Computes statistics from data collected in Hand_Stats structure.
687 @param *stats Handedness statistical parameters
688 @param diff_out Switch for measured-predicted angle output
689 @return int 0.
690 
691  Computes average and standard deviation for view1 projection vs.
692  image1, handA-view2 projection vs. image2, and handB-view2 projection
693  vs. image2 correlation coefficients. Also computes these parameters
694  for differences between measured and predicted angles, if user
695  desires.
696 **/
697 int hand_compute_stats(Hand_Stats* stats, int diff_out)
698 {
699  int N; // Number of data points
700  double d;
701 
702  N = stats->CountA + stats->CountB + stats->Tie; // total number of selected particles
703  if (N == 0) return -1; // no data = no statistics
704 
705  // Averages
706  stats->Avg1A = stats->Sum_1A/N;
707  stats->Avg2A = stats->Sum_2A/N;
708  stats->Avg2B = stats->Sum_2B/N;
709 
710  if (diff_out > 0) { // Absolute differences: measured angles - predicted angles
711  stats->AvgAbsDiff_2Aphi = stats->Sum_AbsDiffPhi2A/N;
712  stats->AvgAbsDiff_2Athe = stats->Sum_AbsDiffThe2A/N;
713  stats->AvgAbsDiff_2Apsi = stats->Sum_AbsDiffPsi2A/N;
714  stats->AvgAbsDiff_2Bphi = stats->Sum_AbsDiffPhi2B/N;
715  stats->AvgAbsDiff_2Bthe = stats->Sum_AbsDiffThe2B/N;
716  stats->AvgAbsDiff_2Bpsi = stats->Sum_AbsDiffPsi2B/N;
717  }
718 
719  // Standard deviations
720  if (N < 2) { // prevents divide-by-zero errors if only one data point
721  stats->Std1A = 0; stats->Std2A = 0; stats->Std2B = 0;
722  stats->StdAbsDiff_2Aphi = 0; stats->StdAbsDiff_2Athe = 0; stats->StdAbsDiff_2Apsi = 0;
723  stats->StdAbsDiff_2Bphi = 0; stats->StdAbsDiff_2Bthe = 0; stats->StdAbsDiff_2Bpsi = 0;
724  } else {
725  stats->Std1A = sqrt( (stats->Sum_1Asq - (stats->Sum_1A*stats->Sum_1A)/N) / (N - 1) );
726  stats->Std2A = sqrt( (stats->Sum_2Asq - (stats->Sum_2A*stats->Sum_2A)/N) / (N - 1) );
727  stats->Std2B = sqrt( (stats->Sum_2Bsq - (stats->Sum_2B*stats->Sum_2B)/N) / (N - 1) );
728  if (diff_out > 0) {
729  d = stats->Sum_AbsDiffPhi2Asq - (stats->Sum_AbsDiffPhi2A*stats->Sum_AbsDiffPhi2A)/N;
730  if ( d > 0 ) stats->StdAbsDiff_2Aphi = sqrt( d / (N-1) );
731  else stats->StdAbsDiff_2Aphi = 0;
732  d = stats->Sum_AbsDiffPhi2Asq - (stats->Sum_AbsDiffThe2Asq*stats->Sum_AbsDiffThe2A)/N;
733  if ( d > 0 ) stats->StdAbsDiff_2Athe = sqrt( d / (N-1) );
734  else stats->StdAbsDiff_2Athe = 0;
735  d = stats->Sum_AbsDiffPsi2Asq - (stats->Sum_AbsDiffPsi2A*stats->Sum_AbsDiffPsi2A)/N;
736  if ( d > 0 ) stats->StdAbsDiff_2Apsi = sqrt( d / (N-1) );
737  else stats->StdAbsDiff_2Apsi = 0;
738  d = stats->Sum_AbsDiffPhi2Bsq - (stats->Sum_AbsDiffPhi2B*stats->Sum_AbsDiffPhi2B)/N;
739  if ( d > 0 ) stats->StdAbsDiff_2Bphi = sqrt( d / (N-1) );
740  else stats->StdAbsDiff_2Bphi = 0;
741  d = stats->Sum_AbsDiffThe2Bsq - (stats->Sum_AbsDiffThe2B*stats->Sum_AbsDiffThe2B)/N;
742  if ( d > 0 ) stats->StdAbsDiff_2Bthe = sqrt( d / (N-1) );
743  else stats->StdAbsDiff_2Bthe = 0;
744  d = stats->Sum_AbsDiffPsi2Bsq - (stats->Sum_AbsDiffPsi2B*stats->Sum_AbsDiffPsi2B)/N;
745  if ( d > 0 ) stats->StdAbsDiff_2Bpsi = sqrt( d / (N-1) );
746  else stats->StdAbsDiff_2Bpsi = 0;
747  }
748  }
749 
750  return 0;
751 }
752 
753 
754 
755 /*
756 @brief Prepares image for comparison with another image
757 @param *p image.
758 @param resmin Lower resolution cut-off value.
759 @param resmax Higher resolution cut-off value.
760 @return int 0.
761 
762  Updates image background and statistics, and applies a bandpass
763  filter to the image.
764 **/
765 int hand_prepare_image(Bimage* p, double resmin, double resmax)
766 {
767 
768  p->statistics();
769  p->fspace_bandpass(resmax, resmin, 0);
770  p->correct_background();
771  p->subtract_background();
772 
773  return 0;
774 
775 }
776 
777 
778 
779 /*
780 @brief Prints the output header to the screen.
781 @param which_one switch for Pair or Global header
782 @param diff_out switch for measured-predicted angle output
783 @return int 0.
784 
785  Two headers: pair and global
786 **/
787 int hand_print_outheader(int which_one, int diff_out)
788 {
789  cout << "Particle images vs. projections at predicted orientations" << endl << endl;
790  cout << "\tCorrelation Coefficients";
791  if (which_one == 0) { /* for Pair statistics */
792  if (diff_out>0) cout << "\tPredicted Orientations";
793  cout << endl << endl;
794  cout << "\tprj.\tprj.\tprj." << endl;
795  cout << "\tview1\tview2\tview2\tprjs" << endl;
796  cout << "\thandA\thandA\thandB\tvs." << endl;
797  cout << "Part.\tvs.\tvs.\tvs.\timage2";
798  if (diff_out>0) cout << "\tview2, handA\tview2, handB";
799  cout << endl;
800  cout << "Id\timage1\timage2\timage2\tA - B";
801  if (diff_out>0) cout << "\tPhi\tTheta\tPsi\tPhi\tTheta\tPsi";
802  else cout << "\tselected";
803  cout << endl;
804  cout << "================================================";
805  if (diff_out>0) cout << "======================================";
806  cout << endl;
807  }
808  else { /* for Global statistics */
809  if (diff_out>0) cout << "\t|Measured Orientation -";
810  if (diff_out>0) cout << endl << "\tPredicted Orientation|" << endl;
811  else cout << endl << endl;
812  cout << "\tprj.\t prj.\tprj." << endl;
813  cout << "\tview1\tview2\tview2" << endl;
814  cout << "\thandA\thandA\thandB" << endl;
815  cout << "\tvs.\tvs.\tvs.";
816  if (diff_out>0) cout << "\tview2, handA\tview2, handB";
817  cout << endl;
818  cout << "Global\timage1\timage2\timage2";
819  if (diff_out>0) cout << "\tPhi\tTheta\tPsi\tPhi\tTheta\tPsi";
820  cout << endl;
821  cout << "====================================";
822  if (diff_out>0) cout << "============================================";
823  cout << endl;
824  }
825  return 0;
826 }
827 
828 
829 
830 /*
831 @brief Prints statistics to the screen.
832 @param *stats Handedness statistical parameters
833 @param which_one Switch for Pair or Global statistics
834 @param diff_out Switch for measured-predicted angle output
835 @return int 0.
836 **/
837 int hand_print_stats(Hand_Stats* stats, int which_one, int diff_out)
838 {
839  double ToDeg = 180/M_PI;
840 
841  cout << setprecision(4);
842 
843  if (which_one == 0) { /* for Pair statistics */
844  if (diff_out > 0) {
845  cout << "*Average\t" << stats->Avg1A << tab << stats->Avg2A << " " <<stats->Avg2B << tab << stats->Avg2A-stats->Avg2B;
846  cout << tab << ToDeg*stats->AvgAbsDiff_2Aphi << tab << ToDeg*stats->AvgAbsDiff_2Athe << tab << ToDeg*stats->AvgAbsDiff_2Apsi;
847  cout << tab << ToDeg*stats->AvgAbsDiff_2Bphi << tab << ToDeg*stats->AvgAbsDiff_2Bthe << tab << ToDeg*stats->AvgAbsDiff_2Bpsi << endl;
848  cout << "Std dev\t" << stats->Std1A << tab << stats->Std2A << tab << stats->Std2B;
849  cout << tab << ToDeg*stats->StdAbsDiff_2Aphi << tab << ToDeg*stats->StdAbsDiff_2Athe << tab << ToDeg*stats->StdAbsDiff_2Apsi;
850  cout << tab << ToDeg*stats->StdAbsDiff_2Bphi << tab << ToDeg*stats->StdAbsDiff_2Bthe << tab << ToDeg*stats->StdAbsDiff_2Bpsi << endl;
851  } else {
852  cout << "Average\t" << stats->Avg1A << tab << stats->Avg2A << tab << stats->Avg2B << tab << stats->Avg2A-stats->Avg2B << endl;
853  cout << "Std dev\t" << stats->Std1A << tab << stats->Std2A << tab << stats->Std2B << endl;
854  }
855  cout << "Count\t\t" << stats->CountA << tab << stats->CountB << endl;
856  if (stats->Tie > 0) cout << "NOTE: " << stats->Tie << " particles in this pair did not favor either hand A or hand B" << endl;
857  if (diff_out > 0) cout << "*Average for pred. orientations is average of |measured angle - predicted angle|" << endl;
858  } else { /* for Global statistics */
859  hand_print_outheader(which_one, diff_out); // Header for screen output
860  if (diff_out > 0) {
861  cout << "Average " << stats->Avg1A << tab << stats->Avg2A << tab << stats->Avg2B;
862  cout << tab << ToDeg*stats->AvgAbsDiff_2Aphi << tab << ToDeg*stats->AvgAbsDiff_2Athe << tab << ToDeg*stats->AvgAbsDiff_2Apsi;
863  cout << tab << ToDeg*stats->AvgAbsDiff_2Bphi << tab << ToDeg*stats->AvgAbsDiff_2Bthe << tab << ToDeg*stats->AvgAbsDiff_2Bpsi << endl;
864  cout << "Std dev " << stats->Std1A << tab << stats->Std2A << tab << stats->Std2B;
865  cout << tab << ToDeg*stats->StdAbsDiff_2Aphi << tab << ToDeg*stats->StdAbsDiff_2Athe << tab << ToDeg*stats->StdAbsDiff_2Apsi;
866  cout << tab << ToDeg*stats->StdAbsDiff_2Bphi << tab << ToDeg*stats->StdAbsDiff_2Bthe << tab << ToDeg*stats->StdAbsDiff_2Bpsi << endl;
867  } else {
868  cout << "Average\t" << stats->Avg1A << tab << stats->Avg2A << tab << stats->Avg2B << endl;
869  cout << "Std dev\t" << stats->Std1A << tab << stats->Std2A << tab << stats->Std2B << endl;
870  }
871  cout << "Count\t\t" << stats->CountA << tab << stats->CountB << endl;
872  if (stats->Tie > 0) cout << "NOTE: " << stats->Tie << " particles in this analysis did not favor either hand A or hand B" << endl;
873  cout << endl << "NOTE: Hand A is handedness of input map. Mirror of input map is hand B." << endl;
874  }
875 
876  return 0;
877 }
878 
897 int hand_select_consist(Bproject* project, double* mg_ang, int* mg_index, int* mg_select, int sel_consist)
898 {
899  Bfield* field=NULL; // Placeholder for loop over the fields-of-view in project
900  int pcount1, pcount2; // count of particles in micrographs
901  int i; // counter
902  int index; // index for standard view
903  Bmicrograph* mg=NULL; // Micrograph to be reset
904  Bmicrograph* mgstd=NULL; // Standard view (1 or 2) of a micrograph tilt pair
905  Bparticle* particle=NULL; // Particles from micrograph to be reset
906  Bparticle* particlestd=NULL; // Particles from "standard" view (1 or 2), selection values copied from here
907 
908  if ( sel_consist < 1 || sel_consist > 2 ) {
909  cerr << "Error: " << sel_consist << " is a wrong value for setting consistent selection values." << endl << "Set to 1 or 2." << endl;
910  bexit(-1);
911  }
912 
913  index = sel_consist - 1;
914 
915  if ( verbose )
916  cout << endl << "Selection values in all micrographs set to those of micrograph view "
917  << sel_consist << " (standard)." << endl << "standard micrograph reset micrograph (field-of-view):" << endl;
918  for ( field=project->field; field; field=field->next ) { // loop through fields-of-view
919  mgstd = field_find_micrograph(field, mg_select[index], mg_index[index], mg_ang[index]); // select sel_consist view
920  pcount1 = micrograph_count_particles(mgstd);
921  for ( mg=field->mg; mg; mg=mg->next ) { // if micrograph not sel_consist view, then reset selection values
922  if ( mg != mgstd ) {
923  if ( verbose ) cout << mgstd->id << " " << mg->id << " (" << field->id << ")" << endl;
924  pcount2 = micrograph_count_particles(mg);
925  if ( pcount2 == pcount1 ) // number of particles in each micrograph (mg and mgstd) is equivalent
926  for ( particlestd=mgstd->part, particle=mg->part; particlestd && particle; particlestd=particlestd->next, particle=particle->next )
927  particle->sel = particlestd->sel;
928  else { // number of particles in mg and mgstd differ
929  i = 0;
930  for ( particlestd=mgstd->part; particlestd; particlestd=particlestd->next )
931  for ( particle=mg->part; particle; particle=particle->next )
932  if ( particle->id == particlestd->id ) {
933  particle->sel = particlestd->sel;
934  i++;
935  }
936  if ( verbose ) {
937  cout << "Micrograph " << mgstd->id << " has " << pcount1 << " particles. Micrograph " << mg->id << " has " << pcount2 << " particles." << endl;
938  cout << "Only " << i << " particle select values in micrograph " << mg->id << " were changed." << endl;
939  }
940  }
941  }
942  }
943  }
944 
945  return 0;
946 }
947 
948 
958 int hand_write_img(Bimage* img, Bstring imgname, Bstring outimg, int fieldnum, int num)
959 {
960  outimg = outimg.pre_rev('.') + Bstring(fieldnum, "_%04d") + Bstring(num, "_%04d_") + imgname + "." + outimg.post_rev('.');
961  write_img(outimg, img, 0);
962 
963  return 0;
964 }
965 
qsort_functions.h
Header file for utility functions for use in qsort calls.
Hand_Stats::StdAbsDiff_2Aphi
double StdAbsDiff_2Aphi
Definition: mg_hand.cpp:44
Bmicrograph::id
Bstring id
Definition: mg_processing.h:203
Bmicrograph
Definition: mg_processing.h:201
Hand_Stats::Sum_1A
double Sum_1A
Definition: mg_hand.cpp:50
Hand_Stats::Std2A
double Std2A
Definition: mg_hand.cpp:36
field_find_micrograph
Bmicrograph * field_find_micrograph(Bfield *field, int mg_select, int mg_index, double mg_ang)
Returns a pointer to a specific micrograph in a field-of-view structure based on a unique characteris...
Definition: mg_select.cpp:64
field_get_handedness
int field_get_handedness(Bimage *mapA, Bimage *mapB, Bmicrograph *mg1, Bmicrograph *mg2, Hand_Stats *Global, double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min, int diff_out, int origins2, Bstring outimg, int fieldnum)
Definition: mg_hand.cpp:230
FOM_HAND_A
@ FOM_HAND_A
Definition: mg_processing.h:46
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
verbose
int verbose
Hand_Stats::StdAbsDiff_2Apsi
double StdAbsDiff_2Apsi
Definition: mg_hand.cpp:46
Bparticle::view
View view
Definition: mg_processing.h:102
Hand_Stats::StdAbsDiff_2Bpsi
double StdAbsDiff_2Bpsi
Definition: mg_hand.cpp:49
Bstring
Definition: Bstring.h:29
Hand_Stats::CountB
int CountB
Definition: mg_hand.cpp:30
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
Hand_Stats::StdAbsDiff_2Athe
double StdAbsDiff_2Athe
Definition: mg_hand.cpp:45
Hand_Stats::Sum_AbsDiffThe2Bsq
double Sum_AbsDiffThe2Bsq
Definition: mg_hand.cpp:66
Euler::theta
double theta()
Definition: Euler.h:57
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2702
Hand_Stats::Sum_2A
double Sum_2A
Definition: mg_hand.cpp:51
Bmicrograph::tilt_angle
double tilt_angle
Definition: mg_processing.h:220
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
Matrix3.h
3x3 Matrix manipulation functions
Hand_Stats::Sum_AbsDiffPhi2Asq
double Sum_AbsDiffPhi2Asq
Definition: mg_hand.cpp:62
Euler::psi
double psi()
Definition: Euler.h:56
FOM_HAND_B
@ FOM_HAND_B
Definition: mg_processing.h:47
micrograph_count_particles
long micrograph_count_particles(Bmicrograph *mg)
Counts all the particles in the micrograph structure.
Definition: mg_select.cpp:736
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
Bparticle::fom
double fom[NFOM]
Definition: mg_processing.h:103
Bimage::background
double background(long nn)
Definition: Bimage.h:549
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:242
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bfield::id
Bstring id
Definition: mg_processing.h:262
Bimage::rotate_project
Bimage * rotate_project(Matrix3 mat, Vector3< double > translate, double radial_cutoff, int norm_flag=1)
Rotates a 3D map and projects it along the z-axis.
Definition: Bimage_project.cpp:118
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
View
Definition: View.h:26
Hand_Stats::Avg2B
double Avg2B
Definition: mg_hand.cpp:34
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:208
hand_select_consist
int hand_select_consist(Bproject *project, double *mg_ang, int *mg_index, int *mg_select, int sel_consist)
Sets consistent selection values in all (including unused) micrographs.
Definition: mg_hand.cpp:897
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
Bimage::correct_background
int correct_background(long nn, int flag)
Corrects the background for one sub-image.
Definition: Bimage_background.cpp:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:558
Hand_Stats
Definition: mg_hand.cpp:28
Hand_Stats::AvgAbsDiff_2Athe
double AvgAbsDiff_2Athe
Definition: mg_hand.cpp:39
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
mg_hand.h
Author: David Belnap.
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Hand_Stats::Std1A
double Std1A
Definition: mg_hand.cpp:35
Hand_Stats::Avg2A
double Avg2A
Definition: mg_hand.cpp:33
Bimage::correlate
double correlate(Bimage *p)
Calculates correlation coefficient between two images.
Definition: Bimage_correlate.cpp:36
Hand_Stats::Sum_AbsDiffThe2Asq
double Sum_AbsDiffThe2Asq
Definition: mg_hand.cpp:63
Hand_Stats::Sum_1Asq
double Sum_1Asq
Definition: mg_hand.cpp:53
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:421
Bmicrograph::tilt_axis
double tilt_axis
Definition: mg_processing.h:219
Hand_Stats::Sum_AbsDiffPsi2A
double Sum_AbsDiffPsi2A
Definition: mg_hand.cpp:58
Bimage
General image parameter class.
Definition: Bimage.h:177
Bproject
Definition: mg_processing.h:336
hand_print_stats
int hand_print_stats(Hand_Stats *stats, int which_one, int diff_out)
Definition: mg_hand.cpp:837
Bparticle::sel
long sel
Definition: mg_processing.h:104
Hand_Stats::Sum_AbsDiffPsi2B
double Sum_AbsDiffPsi2B
Definition: mg_hand.cpp:61
Hand_Stats::Sum_AbsDiffPsi2Asq
double Sum_AbsDiffPsi2Asq
Definition: mg_hand.cpp:64
Euler::phi
double phi()
Definition: Euler.h:58
hand_prepare_image
int hand_prepare_image(Bimage *p, double resmin, double resmax)
Definition: mg_hand.cpp:765
Bimage::fspace_bandpass
int fspace_bandpass(double res_hi, double res_lo=0, double width=0)
Applies a bandpass filter to an image.
Definition: Bimage_fspace.cpp:496
M_PI
#define M_PI
Definition: utilities.h:63
Hand_Stats::Tie
int Tie
Definition: mg_hand.cpp:31
utilities.h
Header file for general utilities.
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
project_get_handedness
int project_get_handedness(Bimage *mapA, Bproject *project, double *mg_ang, int *mg_index, int *mg_select, double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min, int diff_out, int origins2, Bstring outimg)
Determines handedness for all selected particles (sel > 0) in a project.
Definition: mg_hand.cpp:114
Hand_Stats::Avg1A
double Avg1A
Definition: mg_hand.cpp:32
hand_print_outheader
int hand_print_outheader(int which_one, int diff_out)
Definition: mg_hand.cpp:787
Bstring::length
long length() const
Definition: Bstring.cpp:263
Hand_Stats::AvgAbsDiff_2Apsi
double AvgAbsDiff_2Apsi
Definition: mg_hand.cpp:40
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
Hand_Stats::Sum_2Bsq
double Sum_2Bsq
Definition: mg_hand.cpp:55
Bfield::next
Bfield * next
Definition: mg_processing.h:261
hand_write_img
int hand_write_img(Bimage *img, Bstring imgname, Bstring outimg, int fieldnum, int num)
Appends micrograph number, image number, and a string tag to a file name. Then it writes out an image...
Definition: mg_hand.cpp:958
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:101
Hand_Stats::Sum_AbsDiffThe2B
double Sum_AbsDiffThe2B
Definition: mg_hand.cpp:60
Hand_Stats::CountA
int CountA
Definition: mg_hand.cpp:29
Bparticle::next
Bparticle * next
Definition: mg_processing.h:91
Hand_Stats::Sum_AbsDiffThe2A
double Sum_AbsDiffThe2A
Definition: mg_hand.cpp:57
Hand_Stats::Sum_2Asq
double Sum_2Asq
Definition: mg_hand.cpp:54
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Hand_Stats::AvgAbsDiff_2Aphi
double AvgAbsDiff_2Aphi
Definition: mg_hand.cpp:38
Bmicrograph::pixel_size
Vector3< double > pixel_size
Definition: mg_processing.h:215
Hand_Stats::AvgAbsDiff_2Bthe
double AvgAbsDiff_2Bthe
Definition: mg_hand.cpp:42
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
Bimage::subtract_background
int subtract_background()
Subtracts the background for each sub-image.
Definition: Bimage_background.cpp:337
get_handedness_from_tilt_pair
int get_handedness_from_tilt_pair(Bimage *mapA, Bimage *mapB, Bmicrograph *mg1, Bmicrograph *mg2, Bparticle *particle1, Bparticle *particle2, Hand_Stats *Pair, double rad_min, double rad_max, double res_min, double res_max, double AmB_min, double AB_min, int diff_out, int origins2, Bstring outimg, int fieldnum)
Definition: mg_hand.cpp:352
View::matrix
Matrix3 matrix()
Definition: View.h:153
Hand_Stats::AvgAbsDiff_2Bphi
double AvgAbsDiff_2Bphi
Definition: mg_hand.cpp:41
Float
@ Float
Definition: utilities.h:161
Hand_Stats::StdAbsDiff_2Bthe
double StdAbsDiff_2Bthe
Definition: mg_hand.cpp:48
Hand_Stats::Std2B
double Std2B
Definition: mg_hand.cpp:37
Bimage::maximum_included_radius
double maximum_included_radius()
Returns the radius of the enclosed sphere or circle.
Definition: Bimage.cpp:2058
Hand_Stats::Sum_2B
double Sum_2B
Definition: mg_hand.cpp:52
View::angle
double angle()
Definition: View.h:98
Euler
Definition: Euler.h:28
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:202
hand_compute_stats
int hand_compute_stats(Hand_Stats *stats, int diff_out)
Definition: mg_hand.cpp:697
Hand_Stats::Sum_AbsDiffPhi2A
double Sum_AbsDiffPhi2A
Definition: mg_hand.cpp:56
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:267
Bparticle::id
int id
Definition: mg_processing.h:93
Hand_Stats::StdAbsDiff_2Bphi
double StdAbsDiff_2Bphi
Definition: mg_hand.cpp:47
Hand_Stats::AvgAbsDiff_2Bpsi
double AvgAbsDiff_2Bpsi
Definition: mg_hand.cpp:43
Hand_Stats::Sum_AbsDiffPsi2Bsq
double Sum_AbsDiffPsi2Bsq
Definition: mg_hand.cpp:67
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Hand_Stats::Sum_AbsDiffPhi2B
double Sum_AbsDiffPhi2B
Definition: mg_hand.cpp:59
Hand_Stats::Sum_AbsDiffPhi2Bsq
double Sum_AbsDiffPhi2Bsq
Definition: mg_hand.cpp:65
Bproject::fom_tag
FOMType fom_tag[NFOM]
Definition: mg_processing.h:345