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