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

cmp.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_cmp__h__
00037 #define eman_cmp__h__ 1
00038 
00039 
00040 #include "emobject.h"
00041 
00042 namespace EMAN
00043 {
00044 
00045         class EMData;
00085         class Cmp
00086         {
00087           public:
00088                 virtual ~ Cmp()
00089                 {
00090                 }
00091 
00100                 virtual float cmp(EMData * image, EMData * with) const = 0;
00101 
00105                 virtual string get_name() const = 0;
00106 
00107                 virtual string get_desc() const = 0;
00108 
00112                 virtual Dict get_params() const
00113                 {
00114                         return params;
00115                 }
00116 
00120                 virtual void set_params(const Dict & new_params)
00121                 {
00122                         params = new_params;
00123                 }
00124 
00131                 virtual TypeDict get_param_types() const = 0;
00132 
00133         protected:
00134                 void validate_input_args(const EMData * image, const EMData *with) const;
00135 
00136                 mutable Dict params;
00137         };
00138 
00156         class CccCmp:public Cmp
00157         {
00158           public:
00159                 float cmp(EMData * image, EMData * with) const;
00160 
00161                 string get_name() const
00162                 {
00163                         return NAME;
00164                 }
00165 
00166                 string get_desc() const
00167                 {
00168                         return "Cross-correlation coefficient (default -1 * ccc)";
00169                 }
00170 
00171                 static Cmp *NEW()
00172                 {
00173                         return new CccCmp();
00174                 }
00175 
00176                 //param mask Image mask
00177                 TypeDict get_param_types() const
00178                 {
00179                         TypeDict d;
00180                         d.put("negative", EMObject::INT, "If set, returns -1 * ccc product. Set by default so smaller is better");
00181                         d.put("mask", EMObject::EMDATA, "image mask");
00182                         return d;
00183                 }
00184 
00185                 static const string NAME;
00186         };
00187 
00188 
00189         /* Compues the L^1 difference, after normalization.*/
00190         class LodCmp:public Cmp
00191         {
00192           public:
00193                 float cmp(EMData * image, EMData * with) const;
00194 
00195                 string get_name() const
00196                 {
00197                         return NAME;
00198                 }
00199 
00200                 string get_desc() const
00201                 {
00202                         return "L^1 normalized difference (positive by default)";
00203                 }
00204 
00205                 static Cmp *NEW()
00206                 {
00207                         return new LodCmp();
00208                 }
00209 
00210                 //param mask Image mask
00211                 TypeDict get_param_types() const
00212                 {
00213                         TypeDict d;
00214                         d.put("negative", EMObject::INT, "If set (which is the default), returns Lod. (The smaller the better)");
00215                         d.put("normalize", EMObject::INT, "If set, normalizes maps prior to computing the difference. Default=0 (no normalization)");
00216                         d.put("mask", EMObject::EMDATA, "image mask");
00217                         return d;
00218                 }
00219 
00220                 static const string NAME;
00221         };
00222 
00223 
00225         //  I corrected this as there is no such thing as "variance between two images"
00226         //  I corrected naive coding to avoid square
00227         //  Also, the equation in return statement was incorrect, grrrr!!!
00228         //  Finally, I added mask option  PAP 04/23/06
00229         class SqEuclideanCmp:public Cmp
00230         {
00231           public:
00232                 SqEuclideanCmp() {}
00233 
00234                 float cmp(EMData * image, EMData * with) const;
00235 
00236                 string get_name() const
00237                 {
00238                         return NAME;
00239                 }
00240 
00241                 string get_desc() const
00242                 {
00243                         return "Squared Euclidean distance (sum(a - b)^2)/n.";
00244                 }
00245 
00246                 static Cmp *NEW()
00247                 {
00248                         return new SqEuclideanCmp();
00249                 }
00250 
00251                 TypeDict get_param_types() const
00252                 {
00253                         TypeDict d;
00254                         d.put("mask", EMObject::EMDATA, "image mask");
00255                         d.put("zeromask", EMObject::INT, "If set, zero pixels in either image will be excluded from the statistics");
00256                         d.put("normto",EMObject::INT,"If set, 'with' is normalized to 'this' before computing the distance");
00257                         return d;
00258                 }
00259 
00260                 static const string NAME;
00261         };
00262 
00263 
00272         class DotCmp:public Cmp
00273         {
00274           public:
00275                 float cmp(EMData * image, EMData * with) const;
00276 
00277                 string get_name() const
00278                 {
00279                         return NAME;
00280                 }
00281 
00282                 string get_desc() const
00283                 {
00284                         return "Dot product (default -1 * dot product)";
00285                 }
00286 
00287                 static Cmp *NEW()
00288                 {
00289                         return new DotCmp();
00290                 }
00291 
00292                 TypeDict get_param_types() const
00293                 {
00294                         TypeDict d;
00295                         d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Set by default so smaller is better");
00296                         d.put("normalize", EMObject::INT, "If set, returns normalized dot product (cosine of the angle) -1.0 - 1.0.");
00297                         d.put("mask", EMObject::EMDATA, "image mask");
00298                         return d;
00299                 }
00300                 
00301                 static const string NAME;
00302         };
00303 
00317         class TomoCccCmp:public Cmp
00318         {
00319           public:
00320                 virtual float cmp(EMData * image, EMData * with) const;
00321 
00322                 virtual string get_name() const 
00323                 {
00324                         return NAME;
00325                 }
00326 
00327                 virtual string get_desc() const
00328                 {
00329                         return "Ccc with consideration given for the missing wedge";
00330                 }
00331 
00332                 static Cmp *NEW()
00333                 {
00334                         return new TomoCccCmp();
00335                 }
00336 
00337                 TypeDict get_param_types() const
00338                 {
00339                         TypeDict d;
00340                         d.put("norm", EMObject::BOOL,"Whether the cross correlation image should be normalized (should be for normalized images). Default is true.");
00341                         d.put("ccf", EMObject::EMDATA,"The ccf image, can be provided if it already exists to avoid recalculating it");
00342                         d.put("normalize", EMObject::EMDATA,"Return the negative value (which is EMAN2 convention), Defalut is true(1)");
00343                         d.put("searchx", EMObject::INT, "The maximum range of the peak location in the x direction. Default is sizex/4");
00344                         d.put("searchy", EMObject::INT, "The maximum range of the peak location in the y direction. Default is sizey/4");
00345                         d.put("searchz", EMObject::INT, "The maximum range of the peak location in the z direction. Default is sizez/4");
00346                         return d;
00347                 }
00348                 
00349                 static const string NAME;
00350         };
00351 
00359         class QuadMinDotCmp:public Cmp
00360         {
00361           public:
00362                 float cmp(EMData * image, EMData * with) const;
00363 
00364                 string get_name() const
00365                 {
00366                         return NAME;
00367                 }
00368 
00369                 string get_desc() const
00370                 {
00371                         return "Caclultes dot product for each quadrant and returns worst value (default -1 * dot product)";
00372                 }
00373 
00374                 static Cmp *NEW()
00375                 {
00376                         return new QuadMinDotCmp();
00377                 }
00378 
00379                 TypeDict get_param_types() const
00380                 {
00381                         TypeDict d;
00382                         d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Default = true (smaller is better)");
00383                         d.put("normalize", EMObject::INT, "If set, returns normalized dot product -1.0 - 1.0.");
00384                         return d;
00385                 }
00386                 
00387                 static const string NAME;
00388         };
00389 
00390 
00403         class OptVarianceCmp:public Cmp
00404         {
00405           public:
00406                 OptVarianceCmp() : scale(0), shift(0) {}
00407 
00408                 float cmp(EMData * image, EMData * with) const;
00409 
00410                 string get_name() const
00411                 {
00412                         return NAME;
00413                 }
00414 
00415                 string get_desc() const
00416                 {
00417                         return "Real-space variance after density optimization, self should be noisy and target less noisy. Linear transform applied to density to minimize variance.";
00418                 }
00419 
00420                 static Cmp *NEW()
00421                 {
00422                         return new OptVarianceCmp();
00423                 }
00424 
00425                 TypeDict get_param_types() const
00426                 {
00427                         TypeDict d;
00428                         d.put("invert", EMObject::INT, "If set, 'with' is rescaled rather than 'this'. 'this' should still be the noisier image. (default=0)");
00429                         d.put("keepzero", EMObject::INT, "If set, zero pixels will not be adjusted in the linear density optimization. (default=1)");
00430                         d.put("matchfilt", EMObject::INT, "If set, with will be filtered so its radial power spectrum matches 'this' before density optimization of this. (default=1)");
00431                         d.put("matchamp", EMObject::INT, "Takes per-pixel Fourier amplitudes from self and imposes them on the target, but leaves the phases alone. (default=0)");
00432                         d.put("radweight", EMObject::INT, "Upweight variances closer to the edge of the image. (default=0)");
00433                         d.put("debug", EMObject::INT, "Performs various debugging actions if set.");
00434                         return d;
00435                 }
00436 
00437                 float get_scale() const
00438                 {
00439                         return scale;
00440                 }
00441 
00442                 float get_shift() const
00443                 {
00444                         return shift;
00445                 }
00446                 
00447                 static const string NAME;
00448 
00449         private:
00450                 mutable float scale;
00451                 mutable float shift;
00452         };
00463         class PhaseCmp:public Cmp
00464         {
00465           public:
00466                 float cmp(EMData * image, EMData * with) const;
00467 
00468                 string get_name() const
00469                 {
00470                         return NAME;
00471                 }
00472 
00473                 string get_desc() const
00474                 {
00475                         return "Mean phase difference";
00476                 }
00477 
00478                 static Cmp *NEW()
00479                 {
00480                         return new PhaseCmp();
00481                 }
00482 
00483                 TypeDict get_param_types() const
00484                 {
00485                         TypeDict d;
00486                         d.put("snrweight", EMObject::INT, "If set, the SNR of 'this' will be used to weight the result. If 'this' lacks CTF info, it will check 'with'. (default=0)");
00487                         d.put("snrfn", EMObject::INT, "If nonzero, an empirical function will be used as a radial weight rather than the true SNR. (1 - exp decay)'. (default=0)");
00488                         d.put("ampweight", EMObject::INT, "If set, the amplitude of 'with' will be used as a weight in the averaging'. (default=0)");
00489                         d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask");
00490                         d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=500");
00491                         d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables.  Default=10");
00492                         return d;
00493                 }
00494                 
00495                 static const string NAME;
00496 
00497 //#ifdef EMAN2_USING_CUDA
00498 //               float cuda_cmp(EMData * image, EMData *with) const;
00499 //#endif //EMAN2_USING_CUDA
00500         };
00501 
00508         class FRCCmp:public Cmp
00509         {
00510           public:
00511                 float cmp(EMData * image, EMData * with) const;
00512 
00513                 string get_name() const
00514                 {
00515                         return NAME;
00516                 }
00517 
00518                 string get_desc() const
00519                 {
00520                         return "Computes the mean Fourier Ring Correlation between the image and reference (with optional weighting factors).";
00521                 }
00522 
00523                 static Cmp *NEW()
00524                 {
00525                         return new FRCCmp();
00526                 }
00527 
00528                 TypeDict get_param_types() const
00529                 {
00530                         TypeDict d;
00531                         d.put("snrweight", EMObject::INT, "If set, the SNR of 'this' will be used to weight the result. If 'this' lacks CTF info, it will check 'with'. (default=0)");
00532                         d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)");
00533                         d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)");
00534                         d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)");
00535                         d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask");
00536                         d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=500");
00537                         d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables.  Default=10");
00538                         return d;
00539                 }
00540                 
00541                 static const string NAME;
00542         };
00543 
00544         template <> Factory < Cmp >::Factory();
00545 
00546         void dump_cmps();
00547         map<string, vector<string> > dump_cmps_list();
00548 }
00549 
00550 
00551 #endif
00552 
00553 /* vim: set ts=4 noet: */

Generated on Tue Jul 12 13:49:24 2011 for EMAN2 by  doxygen 1.3.9.1