IMP  2.1.0
The Integrative Modeling Platform
scores2D.h
Go to the documentation of this file.
1 /*!
2  * \file em2d/scores2D.h
3  * \brief Scoring functions for 2D
4  * Copyright 2007-2013 IMP Inventors. All rights reserved.
5 */
6 
7 #ifndef IMPEM2D_SCORES_2D_H
8 #define IMPEM2D_SCORES_2D_H
9 
10 #include "IMP/em2d/em2d_config.h"
11 #include "IMP/em2d/Image.h"
14 #include "IMP/base/Object.h"
15 #include "IMP/VersionInfo.h"
17 #include <functional>
18 
19 IMPEM2D_BEGIN_NAMESPACE
20 
21 //! angle in the axis-angle representation of the rotation
22 //! that takes first to second
23 IMPEM2DEXPORT double get_rotation_error(const RegistrationResult &rr1,
24  const RegistrationResult &rr2);
25 
26 
27 //! Distance between the two in-plane translations
28 IMPEM2DEXPORT double get_shift_error(const RegistrationResult &rr1,
29  const RegistrationResult &rr2);
30 
31 IMPEM2DEXPORT double get_average_rotation_error(
32  const RegistrationResults &correct_RRs,
33  const RegistrationResults &computed_RRs);
34 
35 IMPEM2DEXPORT double get_average_shift_error(
36  const RegistrationResults &correct_RRs,
37  const RegistrationResults &computed_RRs);
38 
39 //! Computes the cross-correlation coefficient between to matrices
40 IMPEM2DEXPORT double get_cross_correlation_coefficient(const cv::Mat &m1,
41  const cv::Mat &m2);
42 
43 //! Get the gloal score given a set of individual registration results
44 //! from images
45 /*!
46  \note The function checks what time of registration results are given.
47  - If the registration results correspond to a coarse registration,
48  the score is based on the cross-correlation (currently, the score
49  is a mean of the cross-correlation coefficients.
50  - If the registration results are obtained after a fine registration,
51  the score is the average of all the registration scores. This score
52 g depends on the function selected. Eg. EM2DScore.
53 */
54 IMPEM2DEXPORT double get_global_score(const RegistrationResults &RRs);
55 
56 
57 //! Base class for all scoring functions related to em2d
58 class IMPEM2DEXPORT ScoreFunction: public IMP::base::Object {
59 public:
60  ScoreFunction(): Object("ScoreFunction%1%") {}
61 
62  //! Given an image and a projection, returns the appropiate score
63  double get_score(Image *image, Image *projection) const {
64  // trying to use the non-virtual interface (Alexandrescu, 39)
65  return get_private_score(image, projection);
66  }
67 
68  void set_variance_image(Image *var) {
69  set_variance_image_private(var);
70  }
71 
73 
74 protected:
75  // Number of particle images used to get the class average
76  unsigned int n_members_;
77 
78 private:
79  virtual double get_private_score(Image *image, Image *projection) const = 0;
80  virtual void set_variance_image_private(Image *image) {IMP_UNUSED(image);};
81 
82 
83 };
85 
86 //! Score based on Chi^2 = ((pixels_iamge - pixels_projection)/stddev_image)^2
87 class IMPEM2DEXPORT ChiSquaredScore: public ScoreFunction {
88 public:
90 
91 private:
92  mutable base::Pointer<Image> variance_;
93  double get_private_score(Image *, Image *) const;
94  void set_variance_imag_private(Image *var) {variance_ = var;}
95 };
97 
98 
99 //! EM2DScore, based on squared differences
100 //! (pixels_iamge - pixels_projection)**2
101 class IMPEM2DEXPORT EM2DScore: public ScoreFunction {
102 public:
103  EM2DScore(): ScoreFunction() {}
104 private:
105  double get_private_score(Image *image, Image *projection) const {
106  return 1 - get_cross_correlation_coefficient(image->get_data(),
107  projection->get_data());
108  }
109 };
111 
112 //! Score based on the mean of the absolute difference.
113 class IMPEM2DEXPORT MeanAbsoluteDifference: public ScoreFunction {
114 public:
116 private:
117  double get_private_score(Image *image, Image *projection) const;
118 };
120 
121 
122 //! Comparison by value of the ccc
123 template<class T>
125 #ifndef SWIG
126 :
127  public std::binary_function< T , T ,bool>
128 #endif
129  {
130 public:
131  bool operator()(const T &a, const T &b) const {
132  return a.get_ccc() >= b.get_ccc();
133  }
134  void show(std::ostream &) const {}
135 };
136 
137 
138 //! Comparison of pairs by checking the second element
139 template<class T>
141 #ifndef SWIG
142 :
143  public std::binary_function< T, T, bool>
144 #endif
145  {
146 public:
147  bool operator()(const T &a, const T &b) const {
148  return a.second < b.second;
149  }
150  void show(std::ostream &) const {}
151 };
152 
153 
154 
155 //! Compare two classes that return a score
156 template<class T>
158 #ifndef SWIG
159 :
160  public std::binary_function< T , T ,bool>
161 #endif
162  {
163 public:
164  bool operator()(const T &a,const T &b) const {
165  return a.get_score() < b.get_score();
166  }
167  void show(std::ostream &) const {}
168 };
169 
170 IMPEM2D_END_NAMESPACE
171 
172 #endif /* IMPEM2D_SCORES_2D_H */
double get_shift_error(const RegistrationResult &rr1, const RegistrationResult &rr2)
Distance between the two in-plane translations.
Score based on the mean of the absolute difference.
Definition: scores2D.h:113
#define IMP_UNUSED(variable)
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
inteface with OpenCV Copyright 2007-2013 IMP Inventors. All rights reserved.
double get_rotation_error(const RegistrationResult &rr1, const RegistrationResult &rr2)
double get_score(Image *image, Image *projection) const
Given an image and a projection, returns the appropiate score.
Definition: scores2D.h:63
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2013 IMP Inventors. All rights reserved.
cv::Mat & get_data()
Definition: Image.h:59
Compare two classes that return a score.
Definition: scores2D.h:157
IMP::base::Vector< RegistrationResult > RegistrationResults
Various general useful macros for IMP.
Base class for all scoring functions related to em2d.
Definition: scores2D.h:58
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Score based on Chi^2 = ((pixels_iamge - pixels_projection)/stddev_image)^2.
Definition: scores2D.h:87
Comparison by value of the ccc.
Definition: scores2D.h:124
double get_cross_correlation_coefficient(Image *im1, Image *im2)
Cross correlation between two images.
Common base class for heavy weight IMP objects.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
double get_global_score(const RegistrationResults &RRs)
A shared base class to help in debugging and things.
Import IMP/kernel/VersionInfo.h in the namespace.
Registration results class Copyright 2007-2013 IMP Inventors. All rights reserved.
Comparison of pairs by checking the second element.
Definition: scores2D.h:140
2D Electron Microscopy images in IMP
Definition: Image.h:32