Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

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 MinMaxAverager:public Averager
00217         {
00218           public:
00219                 MinMaxAverager();
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 "Finds the minimum or maximum value in each pixel";
00232                 }
00233 
00234                 static Averager *NEW()
00235                 {
00236                         return new MinMaxAverager();
00237                 }
00238 
00239                 TypeDict get_param_types() const
00240                 {
00241                         TypeDict d;
00242                         d.put("max", EMObject::INT, "If set, will find the max value, otherwise finds min");
00243                         return d;
00244                 }
00245 
00246                 virtual void mult(const float&) { }
00247                 
00248                 static const string NAME;
00249                 
00250         private:
00251                 int max;
00252                 int nimg;
00253         };
00254 
00257         class IterationAverager:public Averager
00258         {
00259           public:
00260                 IterationAverager();
00261                 void add_image( EMData * image);
00262                 EMData * finish();
00263 
00264                 string get_name() const
00265                 {
00266                         return NAME;
00267                 }
00268 
00269                 string get_desc() const
00270                 {
00271                         return "Unknown";
00272                 }
00273 
00274                 static Averager *NEW()
00275                 {
00276                         return new IterationAverager();
00277                 }
00278                 
00279                 static const string NAME;
00280                 
00281         private:
00282                 EMData * sigma_image;
00283                 int nimg;
00284         };
00285 
00288         class CtfAverager:public Averager
00289         {
00290           public:
00291                 CtfAverager();
00292                 void add_image( EMData * image);
00293                 EMData * finish();
00294 
00295                 vector < float >get_snr() const
00296                 {
00297                         return snr;
00298                 }
00299 
00300           protected:
00301                 XYData *sf;
00302                 EMData *curves;
00303                 bool need_snr;
00304                 const char *outfile;
00305           private:
00306                 mutable vector < float >snr;
00307                 EMData * image0_fft;
00308                 EMData * image0_copy;
00309 
00310                 vector<vector<float> > ctf;
00311                 vector<vector<float> > ctfn;
00312 
00313                 float *snri;
00314                 float *snrn;
00315                 float *tdr;
00316                 float *tdi;
00317                 float *tn;
00318 
00319                 float filter;
00320                 int nimg;
00321                 int nx;
00322                 int ny;
00323                 int nz;
00324         };
00325 
00330         class WeightingAverager:public CtfAverager
00331         {
00332           public:
00333                 string get_name() const
00334                 {
00335                         return NAME;
00336                 }
00337 
00338                 string get_desc() const
00339                 {
00340                         return "SNR Weighted average without CTF amplitude correction";
00341                 }
00342 
00343                 static Averager *NEW()
00344                 {
00345                         return new WeightingAverager();
00346                 }
00347 
00348                 void set_params(const Dict & new_params)
00349                 {
00350                         params = new_params;
00351                         curves = params["curves"];
00352                         sf = params["sf"];
00353                 }
00354 
00355                 TypeDict get_param_types() const
00356                 {
00357                         TypeDict d;
00358                         d.put("curves", EMObject::EMDATA);
00359                         d.put("sf", EMObject::XYDATA);
00360                         return d;
00361                 }
00362                 
00363                 static const string NAME;
00364         };
00365 
00368         class CtfCAverager:public CtfAverager
00369         {
00370           public:
00371                 string get_name() const
00372                 {
00373                         return NAME;
00374                 }
00375 
00376                 string get_desc() const
00377                 {
00378                         return "CTF amplitude corrected average, including SNR weight, but result is unprocessed.";
00379                 }
00380 
00381                 static Averager *NEW()
00382                 {
00383                         return new CtfCAverager();
00384                 }
00385                 
00386                 static const string NAME;
00387         };
00388 
00391         class CtfCWAverager:public CtfAverager
00392         {
00393           public:
00394                 string get_name() const
00395                 {
00396                         return NAME;
00397                 }
00398 
00399                 string get_desc() const
00400                 {
00401                         return "CTF amplitude corrected average, including SNR weight and Wiener filtration";
00402                 }
00403 
00404                 static Averager *NEW()
00405                 {
00406                         return new CtfCWAverager();
00407                 }
00408 
00409                 void set_params(const Dict & new_params)
00410                 {
00411                         params = new_params;
00412                         if ((int) params["need_snr"]) {
00413                                 need_snr = true;
00414                         }
00415                         else {
00416                                 need_snr = false;
00417                         }
00418                 }
00419                 
00420                 static const string NAME;
00421         };
00422 
00426         class CtfCAutoAverager:public Averager
00427         {
00428           public:
00429             CtfCAutoAverager();
00430 
00431                 void add_image( EMData * image);
00432                 EMData * finish();
00433 
00434                 string get_name() const
00435                 {
00436                         return NAME;
00437                 }
00438 
00439                 string get_desc() const
00440                 {
00441                         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";
00442                 }
00443 
00444                 static Averager *NEW()
00445                 {
00446                         return new CtfCAutoAverager();
00447                 }
00448 
00449                 void set_params(const Dict & new_params)
00450                 {
00451                         params = new_params;
00452 //                      outfile = params["outfile"];
00453                 }
00454                 
00455                 static const string NAME;
00456                 
00457           protected:
00458                 EMData *snrsum;   // contains the summed SNR for the average
00459                 int nimg;
00460         };
00461 
00465         class CtfCWautoAverager:public Averager
00466         {
00467           public:
00468             CtfCWautoAverager();
00469 
00470                 void add_image( EMData * image);
00471                 EMData * finish();
00472 
00473                 string get_name() const
00474                 {
00475                         return NAME;
00476                 }
00477 
00478                 string get_desc() const
00479                 {
00480                         return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
00481                 }
00482 
00483                 static Averager *NEW()
00484                 {
00485                         return new CtfCWautoAverager();
00486                 }
00487 
00488                 void set_params(const Dict & new_params)
00489                 {
00490                         params = new_params;
00491 //                      outfile = params["outfile"];
00492                 }
00493                 
00494                 static const string NAME;
00495                 
00496           protected:
00497                 EMData *snrsum;   // contains the summed SNR for the average
00498                 int nimg;
00499         };
00500 
00501         template <> Factory < Averager >::Factory();
00502 
00503         void dump_averagers();
00504         map<string, vector<string> > dump_averagers_list();
00505 }
00506 
00507 
00508 #endif

Generated on Mon Jul 19 13:03:42 2010 for EMAN2 by  doxygen 1.4.4