00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
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
00155 class CccCmp:public Cmp
00156 {
00157 public:
00158 float cmp(EMData * image, EMData * with) const;
00159
00160 string get_name() const
00161 {
00162 return "ccc";
00163 }
00164
00165 string get_desc() const
00166 {
00167 return "Cross-correlation coefficient (default -1 * ccc)";
00168 }
00169
00170 static Cmp *NEW()
00171 {
00172 return new CccCmp();
00173 }
00174
00175
00176 TypeDict get_param_types() const
00177 {
00178 TypeDict d;
00179 d.put("negative", EMObject::INT, "If set, returns -1 * ccc product. Set by default so smaller is better");
00180 d.put("mask", EMObject::EMDATA, "image mask");
00181 return d;
00182 }
00183
00184 };
00185
00187
00188
00189
00190
00191 class SqEuclideanCmp:public Cmp
00192 {
00193 public:
00194 SqEuclideanCmp() {}
00195
00196 float cmp(EMData * image, EMData * with) const;
00197
00198 string get_name() const
00199 {
00200 return "sqeuclidean";
00201 }
00202
00203 string get_desc() const
00204 {
00205 return "Squared Euclidean distance (sum(a - b)^2)/n.";
00206 }
00207
00208 static Cmp *NEW()
00209 {
00210 return new SqEuclideanCmp();
00211 }
00212
00213 TypeDict get_param_types() const
00214 {
00215 TypeDict d;
00216 d.put("mask", EMObject::EMDATA, "image mask");
00217 d.put("keepzero", EMObject::INT, "If set, zero pixels will not be adjusted in the linear density optimization");
00218 return d;
00219 }
00220
00221 };
00222
00223
00231 class DotCmp:public Cmp
00232 {
00233 public:
00234 float cmp(EMData * image, EMData * with) const;
00235
00236 string get_name() const
00237 {
00238 return "dot";
00239 }
00240
00241 string get_desc() const
00242 {
00243 return "Dot product (default -1 * dot product)";
00244 }
00245
00246 static Cmp *NEW()
00247 {
00248 return new DotCmp();
00249 }
00250
00251 TypeDict get_param_types() const
00252 {
00253 TypeDict d;
00254 d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Set by default so smaller is better");
00255 d.put("normalize", EMObject::INT, "If set, returns normalized dot product (cosine of the angle) -1.0 - 1.0.");
00256 d.put("mask", EMObject::EMDATA, "image mask");
00257 return d;
00258 }
00259 };
00260
00266 class TomoDotCmp:public Cmp
00267 {
00268 public:
00269 virtual float cmp(EMData * image, EMData * with) const;
00270
00271 virtual string get_name() const
00272 {
00273 return "dot.tomo";
00274 }
00275
00276 virtual string get_desc() const
00277 {
00278 return "straight dot product with consideration given for the missing wedge - normalization is applied by detecting significantly large Fourier amplitudes in the cross correlation image";
00279 }
00280
00281 static Cmp *NEW()
00282 {
00283 return new TomoDotCmp();
00284 }
00285
00286 TypeDict get_param_types() const
00287 {
00288 TypeDict d;
00289 d.put("threshold", EMObject::FLOAT,"Threshold applied to the Fourier amplitudes of the ccf image - helps to correct for the missing wedge.");
00290 d.put("norm", EMObject::BOOL,"Whether the cross correlation image should be normalized. Default is false.");
00291 d.put("ccf", EMObject::EMDATA,"The ccf image, can be provided if it already exists to avoid recalculating it");
00292 d.put("tx", EMObject::INT, "The x location of the maximum in the ccf image. May be negative. Useful thing to supply if you know the maximum is not at the phase origin");
00293 d.put("ty", EMObject::INT, "The y location of the maximum in the ccf image. May be negative. Useful thing to supply if you know the maximum is not at the phase origin");
00294 d.put("tz", EMObject::INT, "The z location of the maximum in the ccf image. May be negative. Useful thing to supply if you know the maximum is not at the phase origin");
00295
00296 return d;
00297 }
00298
00299 };
00300
00308 class QuadMinDotCmp:public Cmp
00309 {
00310 public:
00311 float cmp(EMData * image, EMData * with) const;
00312
00313 string get_name() const
00314 {
00315 return "quadmindot";
00316 }
00317
00318 string get_desc() const
00319 {
00320 return "Caclultes dot product for each quadrant and returns worst value (default -1 * dot product)";
00321 }
00322
00323 static Cmp *NEW()
00324 {
00325 return new QuadMinDotCmp();
00326 }
00327
00328 TypeDict get_param_types() const
00329 {
00330 TypeDict d;
00331 d.put("negative", EMObject::INT, "If set, returns -1 * dot product. Default = true (smaller is better)");
00332 d.put("normalize", EMObject::INT, "If set, returns normalized dot product -1.0 - 1.0.");
00333 return d;
00334 }
00335
00336 };
00337
00338
00351 class OptVarianceCmp:public Cmp
00352 {
00353 public:
00354 OptVarianceCmp() : scale(0), shift(0) {}
00355
00356 float cmp(EMData * image, EMData * with) const;
00357
00358 string get_name() const
00359 {
00360 return "optvariance";
00361 }
00362
00363 string get_desc() const
00364 {
00365 return "Real-space variance after density optimization, self should be noisy and target less noisy. Linear transform applied to density to minimize variance.";
00366 }
00367
00368 static Cmp *NEW()
00369 {
00370 return new OptVarianceCmp();
00371 }
00372
00373 TypeDict get_param_types() const
00374 {
00375 TypeDict d;
00376 d.put("invert", EMObject::INT, "If set, 'with' is rescaled rather than 'this'. 'this' should still be the noisier image. (default=0)");
00377 d.put("keepzero", EMObject::INT, "If set, zero pixels will not be adjusted in the linear density optimization. (default=1)");
00378 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)");
00379 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)");
00380 d.put("radweight", EMObject::INT, "Upweight variances closer to the edge of the image. (default=0)");
00381 d.put("debug", EMObject::INT, "Performs various debugging actions if set.");
00382 return d;
00383 }
00384
00385 float get_scale() const
00386 {
00387 return scale;
00388 }
00389
00390 float get_shift() const
00391 {
00392 return shift;
00393 }
00394
00395 private:
00396 mutable float scale;
00397 mutable float shift;
00398 };
00409 class PhaseCmp:public Cmp
00410 {
00411 public:
00412 float cmp(EMData * image, EMData * with) const;
00413
00414 string get_name() const
00415 {
00416 return "phase";
00417 }
00418
00419 string get_desc() const
00420 {
00421 return "Mean phase difference";
00422 }
00423
00424 static Cmp *NEW()
00425 {
00426 return new PhaseCmp();
00427 }
00428
00429 TypeDict get_param_types() const
00430 {
00431 TypeDict d;
00432 return d;
00433 }
00434
00435 #ifdef EMAN2_USING_CUDA
00436 float cuda_cmp(EMData * image, EMData *with) const;
00437 #endif //EMAN2_USING_CUDA
00438 };
00439
00446 class FRCCmp:public Cmp
00447 {
00448 public:
00449 float cmp(EMData * image, EMData * with) const;
00450
00451 string get_name() const
00452 {
00453 return "frc";
00454 }
00455
00456 string get_desc() const
00457 {
00458 return "Computes the mean Fourier Ring Correlation between the image and reference (with optional weighting factors).";
00459 }
00460
00461 static Cmp *NEW()
00462 {
00463 return new FRCCmp();
00464 }
00465
00466 TypeDict get_param_types() const
00467 {
00468 TypeDict d;
00469 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)");
00470 d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)");
00471 d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)");
00472 d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)");
00473 d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask");
00474 return d;
00475 }
00476 };
00477
00478 template <> Factory < Cmp >::Factory();
00479
00480 void dump_cmps();
00481 map<string, vector<string> > dump_cmps_list();
00482 }
00483
00484
00485 #endif
00486
00487