EMAN2
averager.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman_averager_h__
33#define eman_averager_h__ 1
34
35#include "emobject.h"
36#include "emdata.h"
37
38#include <vector>
39using std::vector;
40
41namespace EMAN
42{
43 class EMData;
44 class XYData;
45
93 {
94 public:
95 Averager() : result(0) {}
96
97 virtual ~ Averager()
98 {
99 }
100
105 virtual void add_image(EMData * image);
106
111 virtual void add_image_list(const vector<EMData*> & images);
112
117 virtual EMData * finish() = 0;
118
122 virtual string get_name() const = 0;
123
124 virtual string get_desc() const = 0;
125
129 virtual void set_params(const Dict & new_params)
130 {
131 params = new_params;
132 }
133
142 virtual void mult(const float& s);
143
150 virtual TypeDict get_param_types() const
151 {
152 TypeDict d;
153 return d;
154 }
155
156 protected:
157 mutable Dict params;
159 };
160
167 {
168 public:
170
171 void add_image( EMData * image);
172 EMData * finish();
173
174 string get_name() const
175 {
176 return NAME;
177 }
178
179 string get_desc() const
180 {
181 return "Simple mean average of images";
182 }
183
184 static Averager *NEW()
185 {
186 return new ImageAverager();
187 }
188
190 {
191 TypeDict d;
192 d.put("sigma", EMObject::EMDATA, "sigma value");
193 d.put("normimage", EMObject::EMDATA, "In conjunction with ignore0, the number of non zero values for each pixel will be stored in this image.");
194 d.put("ignore0", EMObject::INT, "if set, ignore zero value pixels");
195 return d;
196 }
197
198 virtual void mult(const float&) { }
199
200 static const string NAME;
201
202 private:
205 int nimg;
207 };
208
215 {
216 public:
218
219 void add_image( EMData * image);
220 EMData * finish();
221
222 string get_name() const
223 {
224 return NAME;
225 }
226
227 string get_desc() const
228 {
229 return "Average of images weighted by local similarity to unweighted average";
230 }
231
232 static Averager *NEW()
233 {
234 return new LocalWeightAverager();
235 }
236
238 {
239 TypeDict d;
240// d.put("weight", EMObject::XYDATA, "Radial weight. X: 0 - 0.5*sqrt(2). Y contains weights.");
241 d.put("normimage", EMObject::EMDATA, "After finish() will contain the sum of the weights in real-space");
242 d.put("dampnoise", EMObject::FLOAT, "Will set a minimum mean*x for the norm image, damping regions with poor information. Default = 0.5, 0 disables. ");
243 d.put("fourier", EMObject::INT, "If set does local weighting in Fourier rather than real space ");
244 return d;
245 }
246
247 static const string NAME;
248
249 private:
250 std::vector<EMData*> images;
253 int nimg;
255 };
256
261 {
262 public:
263 IterAverager();
264
265 void add_image( EMData * image);
266 EMData * finish();
267
268 string get_name() const
269 {
270 return NAME;
271 }
272
273 string get_desc() const
274 {
275 return "EXPERIMENTAL! Not suggested for normal use. An iterative averager making use of local correlations for noise reduction";
276 }
277
278 static Averager *NEW()
279 {
280 return new IterAverager();
281 }
282
284 {
285 TypeDict d;
286 return d;
287 }
288
289 static const string NAME;
290
291 private:
292 std::vector<EMData*> images;
293 };
294
295
302 {
303 public:
305
306 void add_image( EMData * image);
307 EMData * finish();
308
309 string get_name() const
310 {
311 return NAME;
312 }
313
314 string get_desc() const
315 {
316 return "Weighted mean of images in Fourier space. Each image must have weighting curve in its header, an XYData object called 'avg_weight'.";
317 }
318
319 static Averager *NEW()
320 {
321 return new FourierWeightAverager();
322 }
323
325 {
326 TypeDict d;
327// d.put("weight", EMObject::XYDATA, "Radial weight. X: 0 - 0.5*sqrt(2). Y contains weights.");
328 d.put("normimage", EMObject::EMDATA, "After finish() will contain the sum of the weights in each Fourier location. Size must be ((nx+1)/2,y)");
329 return d;
330 }
331
332 static const string NAME;
333
334 private:
337 int nimg;
338 };
339
340
346 {
347 public:
348 TomoAverager();
350 {
351 if (norm_image!=0) delete norm_image;
352 if (result!=0) delete result;
353 }
354
355 void add_image( EMData * image);
356 EMData * finish();
357
358 string get_name() const
359 {
360 return NAME;
361 }
362
363 string get_desc() const
364 {
365 return "Average of volumes in Fourier space, excluding any pixels with near 0 intensity.";
366 }
367
368 static Averager *NEW()
369 {
370 return new TomoAverager();
371 }
372
374 {
375 TypeDict d;
376 d.put("thresh_sigma", EMObject::FLOAT, "multiplied by the standard deviation of the image, below-which values are considered zero. Default = .01");
377 d.put("save_norm", EMObject::INT, "If set, will save the normalization volume as norm.hdf. Mainly for debugging purposes.");
378 d.put("normout", EMObject::EMDATA, "If set, will save the normalization volume in the given EMData object.");
379 d.put("doift", EMObject::INT, "IFT the resulting volume. Default is 1.");
380
381 return d;
382 }
383
384 virtual void mult(const float&) { }
385
386 static const string NAME;
387
388 private:
391 float overlap;
392 int nimg;
393 };
394
395
401 {
402 public:
404
405 void add_image( EMData * image);
406 EMData * finish();
407
408 string get_name() const
409 {
410 return NAME;
411 }
412
413 string get_desc() const
414 {
415 return "Finds the minimum or maximum value in each pixel";
416 }
417
418 static Averager *NEW()
419 {
420 return new MinMaxAverager();
421 }
422
424 {
425 TypeDict d;
426 d.put("max", EMObject::INT, "If set, will find the max value, otherwise finds min");
427 d.put("abs", EMObject::INT, "If set, will find the value with the min or max absolute value. The actual value is preserved.");
428 d.put("owner", EMObject::EMDATA, "Contains the number of the input image which 'owns' the max/min value. Value will be insertion sequence number unless 'ortid' is set in each image being averaged.");
429 return d;
430 }
431
432 virtual void mult(const float&) { }
433
434 static const string NAME;
435
436 private:
437 int ismax;
438 int isabs;
439 int nimg;
440 };
441
447 {
448 public:
450
451 void add_image( EMData * image);
452 EMData * finish();
453
454 string get_name() const
455 {
456 return NAME;
457 }
458
459 string get_desc() const
460 {
461 return "Computes the median value instead of the mean. If even number of images, averages the middle two.";
462 }
463
464 static Averager *NEW()
465 {
466 return new MedianAverager();
467 }
468
470 {
471 TypeDict d;
472 //d.put("min", EMObject::INT, "If set, will average to minimum absolute value, by default average to max");
473 return d;
474 }
475
476 static const string NAME;
477
478 private:
479 std::vector<EMData*> imgs;
480
481 };
482
483
487 {
488 public:
490
491 void add_image( EMData * image);
492 EMData * finish();
493
494 string get_name() const
495 {
496 return NAME;
497 }
498
499 string get_desc() const
500 {
501 return "Average without CTF correction but with CTF weighting. Smoothed SNR can still have large uncertainty, so weighting by envelope-free CTF may provide more uniform results.";
502 }
503
504 static Averager *NEW()
505 {
506 return new CtfWtAverager();
507 }
508
509 void set_params(const Dict & new_params)
510 {
511 params = new_params;
512// outfile = params["outfile"];
513 }
514
515 static const string NAME;
516
517 protected:
518 EMData *ctfsum; // contains the summed SNR for the average
519 int nimg;
520 };
521
525 {
526 public:
528
529 void add_image( EMData * image);
530 EMData * finish();
531
532 string get_name() const
533 {
534 return NAME;
535 }
536
537 string get_desc() const
538 {
539 return "Average without CTF correction but with CTF weighting and automatic filter estimated from the data. Smoothed SNR can still have large uncertainty, so weighting by envelope-free CTF may provide more uniform results.";
540 }
541
542 static Averager *NEW()
543 {
544 return new CtfWtFiltAverager();
545 }
546
547 void set_params(const Dict & new_params)
548 {
549 params = new_params;
550// outfile = params["outfile"];
551 }
552
553 static const string NAME;
554
555 protected:
556 EMData *results[2]; // even/odd split for filter estimate
557 EMData *ctfsum[2]; // contains the summed SNR for the average
558 int nimg[2],eo;
559 };
560
561
566 {
567 public:
569
570 void add_image( EMData * image);
571 EMData * finish();
572
573 string get_name() const
574 {
575 return NAME;
576 }
577
578 string get_desc() const
579 {
580 return "Averaging with automatic CTF correction and SNR weight. No B-factor correction (as this is best done in 3-D). Bases estimated SSNR on CTF parameters, so requires EMAN2 CTF parameters.";
581 }
582
583 static Averager *NEW()
584 {
585 return new CtfCAutoAverager();
586 }
587
588 void set_params(const Dict & new_params)
589 {
590 params = new_params;
591// outfile = params["outfile"];
592 }
593
594 static const string NAME;
595
596 protected:
597 EMData *snrsum; // contains the summed SNR for the average
598 int nimg;
599 };
600
605 {
606 public:
608
609 void add_image( EMData * image);
610 EMData * finish();
611
612 string get_name() const
613 {
614 return NAME;
615 }
616
617 string get_desc() const
618 {
619 return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
620 }
621
622 static Averager *NEW()
623 {
624 return new CtfCWautoAverager();
625 }
626
627 void set_params(const Dict & new_params)
628 {
629 params = new_params;
630// outfile = params["outfile"];
631 }
632
633 static const string NAME;
634
635 protected:
636 EMData *snrsum; // contains the summed SNR for the average
637 int nimg;
638 };
639
640
647 {
648 public:
650
651 void add_image( EMData * image);
652 EMData * finish();
653
654 string get_name() const
655 {
656 return NAME;
657 }
658
659 string get_desc() const
660 {
661 return "Computes the standard deviation of images";
662 }
663
664 static Averager *NEW()
665 {
666 return new SigmaAverager();
667 }
668
670 {
671 TypeDict d;
672 //d.put("sigma", EMObject::EMDATA, "sigma value");
673 d.put("normimage", EMObject::EMDATA, "In conjunction with ignore0, the number of non zero values for each pixel will be stored in this image.");
674 d.put("ignore0", EMObject::INT, "if set, ignore zero value pixels");
675 return d;
676 }
677
678 virtual void mult(const float&) { }
679
680 static const string NAME;
681
682 private:
685 int nimg;
687 };
688
689
690 // /**
691 // * VarianceAverager computes the pixel-wise variance of a list of images.
692 // */
693 // class VarianceAverager:public Averager
694 // {
695 // public:
696 // VarianceAverager();
697
698 // void add_image( EMData * image);
699 // EMData * finish();
700
701 // string get_name() const
702 // {
703 // return NAME;
704 // }
705
706 // string get_desc() const
707 // {
708 // return "Pixel-wise variance of images";
709 // }
710
711 // static Averager *NEW()
712 // {
713 // return new VarianceAverager();
714 // }
715
716 // TypeDict get_param_types() const
717 // {
718 // TypeDict d;
719 // return d;
720 // }
721
722 // virtual void mult(const float&) { }
723
724 // static const string NAME;
725
726 // private:
727 // EMData *mean;
728 // int nimg;
729 // };
730
732
733 void dump_averagers();
734 map<string, vector<string> > dump_averagers_list();
735}
736
737
738
739
740
741#endif
Averager class defines a way to do averaging on a set of images.
Definition: averager.h:93
virtual EMData * finish()=0
Finish up the averaging and return the result.
virtual void add_image_list(const vector< EMData * > &images)
To add multiple images to the Averager.
Definition: averager.cpp:86
virtual string get_name() const =0
Get the Averager's name.
virtual string get_desc() const =0
EMData * result
Definition: averager.h:158
virtual TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:150
virtual void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:81
virtual void mult(const float &s)
Multiply the result image by some floating point constant This is useful when weighting the input ima...
Definition: averager.cpp:71
virtual void set_params(const Dict &new_params)
Set the Averager parameters using a key/value dictionary.
Definition: averager.h:129
CtfCWautoAverager averages the images with CTF correction with a Wiener filter.
Definition: averager.h:566
string get_desc() const
Definition: averager.h:578
string get_name() const
Get the Averager's name.
Definition: averager.h:573
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:1207
void set_params(const Dict &new_params)
Set the Averager parameters using a key/value dictionary.
Definition: averager.h:588
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:1138
static Averager * NEW()
Definition: averager.h:583
static const string NAME
Definition: averager.h:594
CtfCWautoAverager averages the images with CTF correction with a Wiener filter.
Definition: averager.h:605
string get_desc() const
Definition: averager.h:617
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:1092
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:1019
string get_name() const
Get the Averager's name.
Definition: averager.h:612
static Averager * NEW()
Definition: averager.h:622
void set_params(const Dict &new_params)
Set the Averager parameters using a key/value dictionary.
Definition: averager.h:627
static const string NAME
Definition: averager.h:633
CtfWtAverager.
Definition: averager.h:487
void set_params(const Dict &new_params)
Set the Averager parameters using a key/value dictionary.
Definition: averager.h:509
static const string NAME
Definition: averager.h:515
string get_name() const
Get the Averager's name.
Definition: averager.h:494
string get_desc() const
Definition: averager.h:499
static Averager * NEW()
Definition: averager.h:504
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:1314
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:1262
CtfWtAverager.
Definition: averager.h:525
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:1351
string get_desc() const
Definition: averager.h:537
void set_params(const Dict &new_params)
Set the Averager parameters using a key/value dictionary.
Definition: averager.h:547
static const string NAME
Definition: averager.h:553
static Averager * NEW()
Definition: averager.h:542
EMData * ctfsum[2]
Definition: averager.h:557
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:1415
string get_name() const
Get the Averager's name.
Definition: averager.h:532
EMData * results[2]
Definition: averager.h:556
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
EMData stores an image's data and defines core image processing routines.
Definition: emdata.h:82
Factory is used to store objects to create new instances.
Definition: emobject.h:725
FourierWeightAverager makes an average of a set of images in Fourier space using a per-image radial w...
Definition: averager.h:302
static const string NAME
Definition: averager.h:332
static Averager * NEW()
Definition: averager.h:319
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:324
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:516
string get_desc() const
Definition: averager.h:314
string get_name() const
Get the Averager's name.
Definition: averager.h:309
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:468
ImageAverager averages a list of images.
Definition: averager.h:167
virtual void mult(const float &)
Multiply the result image by some floating point constant This is useful when weighting the input ima...
Definition: averager.h:198
EMData * sigma_image
Definition: averager.h:203
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:289
EMData * normimage
Definition: averager.h:203
static Averager * NEW()
Definition: averager.h:184
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:227
static const string NAME
Definition: averager.h:200
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:189
string get_desc() const
Definition: averager.h:179
string get_name() const
Get the Averager's name.
Definition: averager.h:174
IterAverager performs iterative averaging of 3x3 pixel zones around each pixel, computing the mean of...
Definition: averager.h:261
string get_desc() const
Definition: averager.h:273
std::vector< EMData * > images
Definition: averager.h:292
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:697
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:283
string get_name() const
Get the Averager's name.
Definition: averager.h:268
static Averager * NEW()
Definition: averager.h:278
static const string NAME
Definition: averager.h:289
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:690
LocalWeightAverager makes an average of a set of images in Fourier space using a per-image radial wei...
Definition: averager.h:215
static const string NAME
Definition: averager.h:247
string get_name() const
Get the Averager's name.
Definition: averager.h:222
static Averager * NEW()
Definition: averager.h:232
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:555
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:583
string get_desc() const
Definition: averager.h:227
std::vector< EMData * > images
Definition: averager.h:250
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:237
MedianAverager averages a list of images to the maximum(or minimum of the absolute pixel value) It op...
Definition: averager.h:447
string get_name() const
Get the Averager's name.
Definition: averager.h:454
static const string NAME
Definition: averager.h:476
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:914
std::vector< EMData * > imgs
Definition: averager.h:479
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:928
string get_desc() const
Definition: averager.h:459
static Averager * NEW()
Definition: averager.h:464
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:469
ImageAverager averages a list of images.
Definition: averager.h:401
static const string NAME
Definition: averager.h:434
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:899
virtual void mult(const float &)
Multiply the result image by some floating point constant This is useful when weighting the input ima...
Definition: averager.h:432
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:855
static Averager * NEW()
Definition: averager.h:418
string get_name() const
Get the Averager's name.
Definition: averager.h:408
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:423
string get_desc() const
Definition: averager.h:413
SigmaAverager averages a list of images.
Definition: averager.h:647
string get_desc() const
Definition: averager.h:659
static const string NAME
Definition: averager.h:680
virtual void mult(const float &)
Multiply the result image by some floating point constant This is useful when weighting the input ima...
Definition: averager.h:678
static Averager * NEW()
Definition: averager.h:664
EMData * normimage
Definition: averager.h:683
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:352
string get_name() const
Get the Averager's name.
Definition: averager.h:654
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:411
EMData * mean_image
Definition: averager.h:683
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:669
TomoAverager averages a list of volumes in Fourier space.
Definition: averager.h:346
virtual void mult(const float &)
Multiply the result image by some floating point constant This is useful when weighting the input ima...
Definition: averager.h:384
EMData * finish()
Finish up the averaging and return the result.
Definition: averager.cpp:173
static Averager * NEW()
Definition: averager.h:368
string get_name() const
Get the Averager's name.
Definition: averager.h:358
string get_desc() const
Definition: averager.h:363
static const string NAME
Definition: averager.h:386
void add_image(EMData *image)
To add an image to the Averager.
Definition: averager.cpp:99
EMData * norm_image
Definition: averager.h:389
TypeDict get_param_types() const
Get Averager parameter information in a dictionary.
Definition: averager.h:373
TypeDict is a dictionary to store <string, EMObject::ObjectType> pair.
Definition: emobject.h:305
void put(const string &key, EMObject::ObjectType o, const string &desc="")
Definition: emobject.h:330
E2Exception class.
Definition: aligner.h:40
map< string, vector< string > > dump_averagers_list()
Definition: averager.cpp:1602
void dump_averagers()
Definition: averager.cpp:1597
#define images(i, j, k)
Definition: projector.cpp:1897