EMAN2
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("normimage", EMObject::EMDATA, "In conjunction with ignore0, the number of non zero values for each pixel will be stored in this image.");
00198                         d.put("ignore0", EMObject::INT, "if set, ignore zero value pixels");
00199                         return d;
00200                 }
00201 
00202                 virtual void mult(const float&) { }
00203 
00204                 static const string NAME;
00205                 
00206         private:
00207                 EMData *sigma_image,*normimage;
00208                 int ignore0;
00209                 int nimg;
00210                 int freenorm;
00211         };
00212 
00218         class FourierWeightAverager:public Averager
00219         {
00220           public:
00221                 FourierWeightAverager();
00222 
00223                 void add_image( EMData * image);
00224                 EMData * finish();
00225 
00226                 string get_name() const
00227                 {
00228                         return NAME;
00229                 }
00230 
00231                 string get_desc() const
00232                 {
00233                         return "Weighted mean of images in Fourier space. Each image must have weighting curve in its header, an XYData object called 'avg_weight'.";
00234                 }
00235 
00236                 static Averager *NEW()
00237                 {
00238                         return new FourierWeightAverager();
00239                 }
00240 
00241                 TypeDict get_param_types() const
00242                 {
00243                         TypeDict d;
00244 //                      d.put("weight", EMObject::XYDATA, "Radial weight. X: 0 - 0.5*sqrt(2). Y contains weights.");
00245                         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)");
00246                         return d;
00247                 }
00248 
00249                 static const string NAME;
00250                 
00251         private:
00252                 EMData *normimage;
00253                 int freenorm;
00254                 int nimg;
00255         };
00256 
00257         
00262         class TomoAverager:public Averager
00263         {
00264           public:
00265                 TomoAverager();
00266 
00267                 void add_image( EMData * image);
00268                 EMData * finish();
00269 
00270                 string get_name() const
00271                 {
00272                         return NAME;
00273                 }
00274 
00275                 string get_desc() const
00276                 {
00277                         return "Average of volumes in Fourier space, excluding any pixels with near 0 intensity.";
00278                 }
00279 
00280                 static Averager *NEW()
00281                 {
00282                         return new TomoAverager();
00283                 }
00284 
00285                 TypeDict get_param_types() const
00286                 {
00287                         TypeDict d;
00288                         d.put("thresh_sigma", EMObject::FLOAT, "multiplied by the standard deviation of the image, below-which values are considered zero. Default = .01");
00289                         d.put("save_norm", EMObject::INT, "If set, will save the normalization volume as norm.hdf. Mainly for debugging purposes.");
00290                         return d;
00291                 }
00292 
00293                 virtual void mult(const float&) { }
00294 
00295                 static const string NAME;
00296                 
00297         private:
00298                 EMData *norm_image;
00299                 float thresh_sigma;
00300         };
00301 
00302         
00307         class MinMaxAverager:public Averager
00308         {
00309           public:
00310                 MinMaxAverager();
00311 
00312                 void add_image( EMData * image);
00313                 EMData * finish();
00314 
00315                 string get_name() const
00316                 {
00317                         return NAME;
00318                 }
00319 
00320                 string get_desc() const
00321                 {
00322                         return "Finds the minimum or maximum value in each pixel";
00323                 }
00324 
00325                 static Averager *NEW()
00326                 {
00327                         return new MinMaxAverager();
00328                 }
00329 
00330                 TypeDict get_param_types() const
00331                 {
00332                         TypeDict d;
00333                         d.put("max", EMObject::INT, "If set, will find the max value, otherwise finds min");
00334                         return d;
00335                 }
00336 
00337                 virtual void mult(const float&) { }
00338                 
00339                 static const string NAME;
00340                 
00341         private:
00342                 int max;
00343                 int nimg;
00344         };
00345 
00350         class AbsMaxMinAverager:public Averager
00351         {
00352         public:
00353                 AbsMaxMinAverager();
00354 
00355                 void add_image( EMData * image);
00356                 EMData * finish();
00357 
00358                 string get_name() const
00359                 {
00360                         return NAME;
00361                 }
00362 
00363                 string get_desc() const
00364                 {
00365                         return "Average to maximum(or minimum if set parameter 'min' to non-zero) absolute value in each pixel";
00366                 }
00367 
00368                 static Averager *NEW()
00369                 {
00370                         return new AbsMaxMinAverager();
00371                 }
00372 
00373                 TypeDict get_param_types() const
00374                 {
00375                         TypeDict d;
00376                         d.put("min", EMObject::INT, "If set, will average to minimum absolute value, by default average to max");
00377                         return d;
00378                 }
00379 
00380                 static const string NAME;
00381 
00382         private:
00383                 int min;
00384                 int nimg;
00385         };
00386 
00389         class IterationAverager:public Averager
00390         {
00391           public:
00392                 IterationAverager();
00393                 void add_image( EMData * image);
00394                 EMData * finish();
00395 
00396                 string get_name() const
00397                 {
00398                         return NAME;
00399                 }
00400 
00401                 string get_desc() const
00402                 {
00403                         return "Unknown";
00404                 }
00405 
00406                 static Averager *NEW()
00407                 {
00408                         return new IterationAverager();
00409                 }
00410                 
00411                 static const string NAME;
00412                 
00413         private:
00414                 EMData * sigma_image;
00415                 int nimg;
00416         };
00417 
00418 
00422         class CtfCAutoAverager:public Averager
00423         {
00424           public:
00425             CtfCAutoAverager();
00426 
00427                 void add_image( EMData * image);
00428                 EMData * finish();
00429 
00430                 string get_name() const
00431                 {
00432                         return NAME;
00433                 }
00434 
00435                 string get_desc() const
00436                 {
00437                         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";
00438                 }
00439 
00440                 static Averager *NEW()
00441                 {
00442                         return new CtfCAutoAverager();
00443                 }
00444 
00445                 void set_params(const Dict & new_params)
00446                 {
00447                         params = new_params;
00448 //                      outfile = params["outfile"];
00449                 }
00450                 
00451                 static const string NAME;
00452                 
00453           protected:
00454                 EMData *snrsum;   // contains the summed SNR for the average
00455                 int nimg;
00456         };
00457 
00461         class CtfCWautoAverager:public Averager
00462         {
00463           public:
00464             CtfCWautoAverager();
00465 
00466                 void add_image( EMData * image);
00467                 EMData * finish();
00468 
00469                 string get_name() const
00470                 {
00471                         return NAME;
00472                 }
00473 
00474                 string get_desc() const
00475                 {
00476                         return "Averaging with autmatic CTF correction. Does not require a structure factor, but only works with EMAN2's CTF model";
00477                 }
00478 
00479                 static Averager *NEW()
00480                 {
00481                         return new CtfCWautoAverager();
00482                 }
00483 
00484                 void set_params(const Dict & new_params)
00485                 {
00486                         params = new_params;
00487 //                      outfile = params["outfile"];
00488                 }
00489                 
00490                 static const string NAME;
00491                 
00492           protected:
00493                 EMData *snrsum;   // contains the summed SNR for the average
00494                 int nimg;
00495         };
00496 
00497         template <> Factory < Averager >::Factory();
00498 
00499         void dump_averagers();
00500         map<string, vector<string> > dump_averagers_list();
00501 }
00502 
00503 
00504 #endif