averager.h

Go to the documentation of this file.
00001 
00005 /*
00006  * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 
00302         class IterationAverager:public Averager
00303         {
00304           public:
00305                 IterationAverager();
00306                 void add_image( EMData * image);
00307                 EMData * finish();
00308 
00309                 string get_name() const
00310                 {
00311                         return NAME;
00312                 }
00313 
00314                 string get_desc() const
00315                 {
00316                         return "Unknown";
00317                 }
00318 
00319                 static Averager *NEW()
00320                 {
00321                         return new IterationAverager();
00322                 }
00323                 
00324                 static const string NAME;
00325                 
00326         private:
00327                 EMData * sigma_image;
00328                 int nimg;
00329         };
00330 
00333         class CtfAverager:public Averager
00334         {
00335           public:
00336                 CtfAverager();
00337                 void add_image( EMData * image);
00338                 EMData * finish();
00339 
00340                 vector < float >get_snr() const
00341                 {
00342                         return snr;
00343                 }
00344 
00345           protected:
00346                 XYData *sf;
00347                 EMData *curves;
00348                 bool need_snr;
00349                 const char *outfile;
00350           private:
00351                 mutable vector < float >snr;
00352                 EMData * image0_fft;
00353                 EMData * image0_copy;
00354 
00355                 vector<vector<float> > ctf;
00356                 vector<vector<float> > ctfn;
00357 
00358                 float *snri;
00359                 float *snrn;
00360                 float *tdr;
00361                 float *tdi;
00362                 float *tn;
00363 
00364                 float filter;
00365                 int nimg;
00366                 int nx;
00367                 int ny;
00368                 int nz;
00369         };
00370 
00375         class WeightingAverager:public CtfAverager
00376         {
00377           public:
00378                 string get_name() const
00379                 {
00380                         return NAME;
00381                 }
00382 
00383                 string get_desc() const
00384                 {
00385                         return "SNR Weighted average without CTF amplitude correction";
00386                 }
00387 
00388                 static Averager *NEW()
00389                 {
00390                         return new WeightingAverager();
00391                 }
00392 
00393                 void set_params(const Dict & new_params)
00394                 {
00395                         params = new_params;
00396                         curves = params["curves"];
00397                         sf = params["sf"];
00398                 }
00399 
00400                 TypeDict get_param_types() const
00401                 {
00402                         TypeDict d;
00403                         d.put("curves", EMObject::EMDATA);
00404                         d.put("sf", EMObject::XYDATA);
00405                         return d;
00406                 }
00407                 
00408                 static const string NAME;
00409         };
00410 
00413         class CtfCAverager:public CtfAverager
00414         {
00415           public:
00416                 string get_name() const
00417                 {
00418                         return NAME;
00419                 }
00420 
00421                 string get_desc() const
00422                 {
00423                         return "CTF amplitude corrected average, including SNR weight, but result is unprocessed.";
00424                 }
00425 
00426                 static Averager *NEW()
00427                 {
00428                         return new CtfCAverager();
00429                 }
00430                 
00431                 static const string NAME;
00432         };
00433 
00436         class CtfCWAverager:public CtfAverager
00437         {
00438           public:
00439                 string get_name() const
00440                 {
00441                         return NAME;
00442                 }
00443 
00444                 string get_desc() const
00445                 {
00446                         return "CTF amplitude corrected average, including SNR weight and Wiener filtration";
00447                 }
00448 
00449                 static Averager *NEW()
00450                 {
00451                         return new CtfCWAverager();
00452                 }
00453 
00454                 void set_params(const Dict & new_params)
00455                 {
00456                         params = new_params;
00457                         if ((int) params["need_snr"]) {
00458                                 need_snr = true;
00459                         }
00460                         else {
00461                                 need_snr = false;
00462                         }
00463                 }
00464                 
00465                 static const string NAME;
00466         };
00467 
00471         class CtfCAutoAverager:public Averager
00472         {
00473           public:
00474             CtfCAutoAverager();
00475 
00476                 void add_image( EMData * image);
00477                 EMData * finish();
00478 
00479                 string get_name() const
00480                 {
00481                         return NAME;
00482                 }
00483 
00484                 string get_desc() const
00485                 {
00486                         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";
00487                 }
00488 
00489                 static Averager *NEW()
00490                 {
00491                         return new CtfCAutoAverager();
00492                 }
00493 
00494                 void set_params(const Dict & new_params)
00495                 {
00496                         params = new_params;
00497 //                      outfile = params["outfile"];
00498                 }
00499                 
00500                 static const string NAME;
00501                 
00502           protected:
00503                 EMData *snrsum;   // contains the summed SNR for the average
00504                 int nimg;
00505         };
00506 
00510         class CtfCWautoAverager:public Averager
00511         {
00512           public:
00513             CtfCWautoAverager();
00514 
00515                 void add_image( EMData * image);
00516                 EMData * finish();
00517 
00518                 string get_name() const
00519                 {
00520                         return NAME;
00521                 }
00522 
00523                 string get_desc() const
00524                 {
00525                         return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
00526                 }
00527 
00528                 static Averager *NEW()
00529                 {
00530                         return new CtfCWautoAverager();
00531                 }
00532 
00533                 void set_params(const Dict & new_params)
00534                 {
00535                         params = new_params;
00536 //                      outfile = params["outfile"];
00537                 }
00538                 
00539                 static const string NAME;
00540                 
00541           protected:
00542                 EMData *snrsum;   // contains the summed SNR for the average
00543                 int nimg;
00544         };
00545 
00546         template <> Factory < Averager >::Factory();
00547 
00548         void dump_averagers();
00549         map<string, vector<string> > dump_averagers_list();
00550 }
00551 
00552 
00553 #endif

Generated on Tue Jul 12 13:45:46 2011 for EMAN2 by  doxygen 1.4.7