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 "mean";
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         private:
00204                 EMData *sigma_image;
00205                 int *nimg_n0;
00206                 int ignore0;
00207                 int nimg;
00208         };
00209 
00214         class MinMaxAverager:public Averager
00215         {
00216           public:
00217                 MinMaxAverager();
00218 
00219                 void add_image( EMData * image);
00220                 EMData * finish();
00221 
00222                 string get_name() const
00223                 {
00224                         return "minmax";
00225                 }
00226 
00227                 string get_desc() const
00228                 {
00229                         return "Finds the minimum or maximum value in each pixel";
00230                 }
00231 
00232                 static Averager *NEW()
00233                 {
00234                         return new MinMaxAverager();
00235                 }
00236 
00237                 TypeDict get_param_types() const
00238                 {
00239                         TypeDict d;
00240                         d.put("max", EMObject::INT, "If set, will find the max value, otherwise finds min");
00241                         return d;
00242                 }
00243 
00244                 virtual void mult(const float&) { }
00245 
00246         private:
00247                 int max;
00248                 int nimg;
00249         };
00250 
00253         class IterationAverager:public Averager
00254         {
00255           public:
00256                 IterationAverager();
00257                 void add_image( EMData * image);
00258                 EMData * finish();
00259 
00260                 string get_name() const
00261                 {
00262                         return "iteration";
00263                 }
00264 
00265                 string get_desc() const
00266                 {
00267                         return "Unknown";
00268                 }
00269 
00270                 static Averager *NEW()
00271                 {
00272                         return new IterationAverager();
00273                 }
00274         private:
00275                 EMData * sigma_image;
00276                 int nimg;
00277         };
00278 
00281         class CtfAverager:public Averager
00282         {
00283           public:
00284                 CtfAverager();
00285                 void add_image( EMData * image);
00286                 EMData * finish();
00287 
00288                 vector < float >get_snr() const
00289                 {
00290                         return snr;
00291                 }
00292 
00293           protected:
00294                 XYData *sf;
00295                 EMData *curves;
00296                 bool need_snr;
00297                 const char *outfile;
00298           private:
00299                 mutable vector < float >snr;
00300                 EMData * image0_fft;
00301                 EMData * image0_copy;
00302 
00303                 vector<vector<float> > ctf;
00304                 vector<vector<float> > ctfn;
00305 
00306                 float *snri;
00307                 float *snrn;
00308                 float *tdr;
00309                 float *tdi;
00310                 float *tn;
00311 
00312                 float filter;
00313                 int nimg;
00314                 int nx;
00315                 int ny;
00316                 int nz;
00317         };
00318 
00323         class WeightingAverager:public CtfAverager
00324         {
00325           public:
00326                 string get_name() const
00327                 {
00328                         return "snr_weight";
00329                 }
00330 
00331                 string get_desc() const
00332                 {
00333                         return "SNR Weighted average without CTF amplitude correction";
00334                 }
00335 
00336                 static Averager *NEW()
00337                 {
00338                         return new WeightingAverager();
00339                 }
00340 
00341                 void set_params(const Dict & new_params)
00342                 {
00343                         params = new_params;
00344                         curves = params["curves"];
00345                         sf = params["sf"];
00346                 }
00347 
00348                 TypeDict get_param_types() const
00349                 {
00350                         TypeDict d;
00351                         d.put("curves", EMObject::EMDATA);
00352                         d.put("sf", EMObject::XYDATA);
00353                         return d;
00354                 }
00355         };
00356 
00359         class CtfCAverager:public CtfAverager
00360         {
00361           public:
00362                 string get_name() const
00363                 {
00364                         return "ctfc";
00365                 }
00366 
00367                 string get_desc() const
00368                 {
00369                         return "CTF amplitude corrected average, including SNR weight, but result is unprocessed.";
00370                 }
00371 
00372                 static Averager *NEW()
00373                 {
00374                         return new CtfCAverager();
00375                 }
00376         };
00377 
00380         class CtfCWAverager:public CtfAverager
00381         {
00382           public:
00383                 string get_name() const
00384                 {
00385                         return "ctfcw";
00386                 }
00387 
00388                 string get_desc() const
00389                 {
00390                         return "CTF amplitude corrected average, including SNR weight and Wiener filtration";
00391                 }
00392 
00393                 static Averager *NEW()
00394                 {
00395                         return new CtfCWAverager();
00396                 }
00397 
00398                 void set_params(const Dict & new_params)
00399                 {
00400                         params = new_params;
00401                         if ((int) params["need_snr"]) {
00402                                 need_snr = true;
00403                         }
00404                         else {
00405                                 need_snr = false;
00406                         }
00407                 }
00408         };
00409 
00413         class CtfCWautoAverager:public Averager
00414         {
00415           public:
00416             CtfCWautoAverager();
00417 
00418                 void add_image( EMData * image);
00419                 EMData * finish();
00420 
00421                 string get_name() const
00422                 {
00423                         return "ctf.auto";
00424                 }
00425 
00426                 string get_desc() const
00427                 {
00428                         return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
00429                 }
00430 
00431                 static Averager *NEW()
00432                 {
00433                         return new CtfCWautoAverager();
00434                 }
00435 
00436                 void set_params(const Dict & new_params)
00437                 {
00438                         params = new_params;
00439 //                      outfile = params["outfile"];
00440                 }
00441           protected:
00442                 EMData *snrsum;   // contains the summed SNR for the average
00443                 int nimg;
00444         };
00445 
00446         template <> Factory < Averager >::Factory();
00447 
00448         void dump_averagers();
00449         map<string, vector<string> > dump_averagers_list();
00450 }
00451 
00452 
00453 #endif

Generated on Sat Nov 21 02:19:14 2009 for EMAN2 by  doxygen 1.5.6