00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef eman_averager_h__
00037 #define eman_averager_h__ 1
00038
00039 #include "emobject.h"
00040 #include "emdata.h"
00041
00042 #include <vector>
00043 using std::vector;
00044
00045 namespace EMAN
00046 {
00047 class EMData;
00048 class XYData;
00049
00096 class Averager
00097 {
00098 public:
00099 Averager() : result(0) {}
00100
00101 virtual ~ Averager()
00102 {
00103 }
00104
00109 virtual void add_image(EMData * image) = 0;
00110
00115 virtual void add_image_list(const vector<EMData*> & images);
00116
00121 virtual EMData * finish() = 0;
00122
00126 virtual string get_name() const = 0;
00127
00128 virtual string get_desc() const = 0;
00129
00133 virtual void set_params(const Dict & new_params)
00134 {
00135 params = new_params;
00136 }
00137
00146 virtual void mult(const float& s);
00147
00154 virtual TypeDict get_param_types() const
00155 {
00156 TypeDict d;
00157 return d;
00158 }
00159
00160 protected:
00161 mutable Dict params;
00162 EMData *result;
00163 };
00164
00170 class ImageAverager:public Averager
00171 {
00172 public:
00173 ImageAverager();
00174
00175 void add_image( EMData * image);
00176 EMData * finish();
00177
00178 string get_name() const
00179 {
00180 return NAME;
00181 }
00182
00183 string get_desc() const
00184 {
00185 return "Simple mean average of images";
00186 }
00187
00188 static Averager *NEW()
00189 {
00190 return new ImageAverager();
00191 }
00192
00193 TypeDict get_param_types() const
00194 {
00195 TypeDict d;
00196 d.put("sigma", EMObject::EMDATA, "sigma value");
00197 d.put("ignore0", EMObject::INT, "if set, ignore zero value pixels");
00198 return d;
00199 }
00200
00201 virtual void mult(const float&) { }
00202
00203 static const string NAME;
00204
00205 private:
00206 EMData *sigma_image;
00207 int *nimg_n0;
00208 int ignore0;
00209 int nimg;
00210 };
00211
00216 class TomoAverager:public Averager
00217 {
00218 public:
00219 TomoAverager();
00220
00221 void add_image( EMData * image);
00222 EMData * finish();
00223
00224 string get_name() const
00225 {
00226 return NAME;
00227 }
00228
00229 string get_desc() const
00230 {
00231 return "Average of volumes in Fourier space, excluding any pixels with near 0 intensity.";
00232 }
00233
00234 static Averager *NEW()
00235 {
00236 return new TomoAverager();
00237 }
00238
00239 TypeDict get_param_types() const
00240 {
00241 TypeDict d;
00242 d.put("thresh_sigma", EMObject::FLOAT, "multiplied by the standard deviation of the image, below-which values are considered zero. Default = .01");
00243 d.put("save_norm", EMObject::INT, "If set, will save the normalization volume as norm.hdf. Mainly for debugging purposes.");
00244 return d;
00245 }
00246
00247 virtual void mult(const float&) { }
00248
00249 static const string NAME;
00250
00251 private:
00252 EMData *norm_image;
00253 float thresh_sigma;
00254 };
00255
00256
00261 class MinMaxAverager:public Averager
00262 {
00263 public:
00264 MinMaxAverager();
00265
00266 void add_image( EMData * image);
00267 EMData * finish();
00268
00269 string get_name() const
00270 {
00271 return NAME;
00272 }
00273
00274 string get_desc() const
00275 {
00276 return "Finds the minimum or maximum value in each pixel";
00277 }
00278
00279 static Averager *NEW()
00280 {
00281 return new MinMaxAverager();
00282 }
00283
00284 TypeDict get_param_types() const
00285 {
00286 TypeDict d;
00287 d.put("max", EMObject::INT, "If set, will find the max value, otherwise finds min");
00288 return d;
00289 }
00290
00291 virtual void mult(const float&) { }
00292
00293 static const string NAME;
00294
00295 private:
00296 int max;
00297 int nimg;
00298 };
00299
00304 class AbsMaxMinAverager:public Averager
00305 {
00306 public:
00307 AbsMaxMinAverager();
00308
00309 void add_image( EMData * image);
00310 EMData * finish();
00311
00312 string get_name() const
00313 {
00314 return NAME;
00315 }
00316
00317 string get_desc() const
00318 {
00319 return "Average to maximum(or minimum if set parameter 'min' to non-zero) absolute value in each pixel";
00320 }
00321
00322 static Averager *NEW()
00323 {
00324 return new AbsMaxMinAverager();
00325 }
00326
00327 TypeDict get_param_types() const
00328 {
00329 TypeDict d;
00330 d.put("min", EMObject::INT, "If set, will average to minimum absolute value, by default average to max");
00331 return d;
00332 }
00333
00334 static const string NAME;
00335
00336 private:
00337 int min;
00338 int nimg;
00339 };
00340
00343 class IterationAverager:public Averager
00344 {
00345 public:
00346 IterationAverager();
00347 void add_image( EMData * image);
00348 EMData * finish();
00349
00350 string get_name() const
00351 {
00352 return NAME;
00353 }
00354
00355 string get_desc() const
00356 {
00357 return "Unknown";
00358 }
00359
00360 static Averager *NEW()
00361 {
00362 return new IterationAverager();
00363 }
00364
00365 static const string NAME;
00366
00367 private:
00368 EMData * sigma_image;
00369 int nimg;
00370 };
00371
00374 class CtfAverager:public Averager
00375 {
00376 public:
00377 CtfAverager();
00378 void add_image( EMData * image);
00379 EMData * finish();
00380
00381 vector < float >get_snr() const
00382 {
00383 return snr;
00384 }
00385
00386 protected:
00387 XYData *sf;
00388 EMData *curves;
00389 bool need_snr;
00390 const char *outfile;
00391 private:
00392 mutable vector < float >snr;
00393 EMData * image0_fft;
00394 EMData * image0_copy;
00395
00396 vector<vector<float> > ctf;
00397 vector<vector<float> > ctfn;
00398
00399 float *snri;
00400 float *snrn;
00401 float *tdr;
00402 float *tdi;
00403 float *tn;
00404
00405 float filter;
00406 int nimg;
00407 int nx;
00408 int ny;
00409 int nz;
00410 };
00411
00416 class WeightingAverager:public CtfAverager
00417 {
00418 public:
00419 string get_name() const
00420 {
00421 return NAME;
00422 }
00423
00424 string get_desc() const
00425 {
00426 return "SNR Weighted average without CTF amplitude correction";
00427 }
00428
00429 static Averager *NEW()
00430 {
00431 return new WeightingAverager();
00432 }
00433
00434 void set_params(const Dict & new_params)
00435 {
00436 params = new_params;
00437 curves = params["curves"];
00438 sf = params["sf"];
00439 }
00440
00441 TypeDict get_param_types() const
00442 {
00443 TypeDict d;
00444 d.put("curves", EMObject::EMDATA);
00445 d.put("sf", EMObject::XYDATA);
00446 return d;
00447 }
00448
00449 static const string NAME;
00450 };
00451
00454 class CtfCAverager:public CtfAverager
00455 {
00456 public:
00457 string get_name() const
00458 {
00459 return NAME;
00460 }
00461
00462 string get_desc() const
00463 {
00464 return "CTF amplitude corrected average, including SNR weight, but result is unprocessed.";
00465 }
00466
00467 static Averager *NEW()
00468 {
00469 return new CtfCAverager();
00470 }
00471
00472 static const string NAME;
00473 };
00474
00477 class CtfCWAverager:public CtfAverager
00478 {
00479 public:
00480 string get_name() const
00481 {
00482 return NAME;
00483 }
00484
00485 string get_desc() const
00486 {
00487 return "CTF amplitude corrected average, including SNR weight and Wiener filtration";
00488 }
00489
00490 static Averager *NEW()
00491 {
00492 return new CtfCWAverager();
00493 }
00494
00495 void set_params(const Dict & new_params)
00496 {
00497 params = new_params;
00498 if ((int) params["need_snr"]) {
00499 need_snr = true;
00500 }
00501 else {
00502 need_snr = false;
00503 }
00504 }
00505
00506 static const string NAME;
00507 };
00508
00512 class CtfCAutoAverager:public Averager
00513 {
00514 public:
00515 CtfCAutoAverager();
00516
00517 void add_image( EMData * image);
00518 EMData * finish();
00519
00520 string get_name() const
00521 {
00522 return NAME;
00523 }
00524
00525 string get_desc() const
00526 {
00527 return "Averaging with automatic CTF correction and SNR weight. No B-factor correction (as this is best done in 3-D). Does not require a structure factor, but only works with EMAN2's CTF model";
00528 }
00529
00530 static Averager *NEW()
00531 {
00532 return new CtfCAutoAverager();
00533 }
00534
00535 void set_params(const Dict & new_params)
00536 {
00537 params = new_params;
00538
00539 }
00540
00541 static const string NAME;
00542
00543 protected:
00544 EMData *snrsum;
00545 int nimg;
00546 };
00547
00551 class CtfCWautoAverager:public Averager
00552 {
00553 public:
00554 CtfCWautoAverager();
00555
00556 void add_image( EMData * image);
00557 EMData * finish();
00558
00559 string get_name() const
00560 {
00561 return NAME;
00562 }
00563
00564 string get_desc() const
00565 {
00566 return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
00567 }
00568
00569 static Averager *NEW()
00570 {
00571 return new CtfCWautoAverager();
00572 }
00573
00574 void set_params(const Dict & new_params)
00575 {
00576 params = new_params;
00577
00578 }
00579
00580 static const string NAME;
00581
00582 protected:
00583 EMData *snrsum;
00584 int nimg;
00585 };
00586
00587 template <> Factory < Averager >::Factory();
00588
00589 void dump_averagers();
00590 map<string, vector<string> > dump_averagers_list();
00591 }
00592
00593
00594 #endif