IMP logo
IMP Reference Guide  2.6.2
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-2016 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/Object.h"
15 #include <IMP/warning_macros.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 global 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::Object {
56  public:
57  ScoreFunction() : Object("ScoreFunction%1%") {}
58 
59  //! Given an image and a projection, returns the appropriate 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_image - pixels_projection)/stddev_image)^2
82 class IMPEM2DEXPORT ChiSquaredScore : public ScoreFunction {
83  public:
85 
86  private:
87  mutable 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_image - 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.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Score based on the mean of the absolute difference.
Definition: scores2D.h:108
Interface with OpenCV Copyright 2007-2016 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 appropriate score.
Definition: scores2D.h:60
IMP images for Electron Microscopy using openCV matrices Copyright 2007-2016 IMP Inventors. All rights reserved.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
cv::Mat & get_data()
Definition: Image.h:51
Common base class for heavy weight IMP objects.
Definition: Object.h:106
Various general useful macros for IMP.
#define IMP_UNUSED(variable)
Compare two classes that return a score.
Definition: scores2D.h:145
Base class for all scoring functions related to em2d.
Definition: scores2D.h:55
Score based on Chi^2 = ((pixels_image - 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.
IMP::Vector< RegistrationResult > RegistrationResults
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
A shared base class to help in debugging and things.
Object(std::string name)
Construct an object with the given name.
double get_global_score(const RegistrationResults &RRs)
Registration results class Copyright 2007-2016 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