FuzzyCorrespondence.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_FuzzyCorrespondence_H
21 #define MIRTK_FuzzyCorrespondence_H
22 
23 #include "mirtk/PointCorrespondence.h"
24 
25 #include "mirtk/Array.h"
26 #include "mirtk/PointSet.h"
27 #include "mirtk/SparseMatrix.h"
28 
29 
30 namespace mirtk {
31 
32 
33 /**
34  * Fuzzy point correspondences
35  *
36  * The point correspondences realized by this class are inspired by the
37  * softassign approach as in particular employed by the Robust Point Matching
38  * (RPM) algorithm proposed in
39  *
40  * Chui and Rangarajan, "A new point matching algorithm for non-rigid registration",
41  * Computer Vision and Image Understanding, 89(2-3), pp. 114–141, 2003.
42  *
43  * This class is the common base of the different variants of softassign
44  * point correspondences, two of which implementing those presented in the
45  * MATLAB Demo by the authors of aforementioned paper.
46  *
47  * \sa FiducialRegistrationError
48  */
50 {
51  mirtkAbstractMacro(FuzzyCorrespondence);
52 
53  // ---------------------------------------------------------------------------
54  // Types
55 public:
56 
57  /// Sparse matrix type used for fuzzy correspondence weights
59 
60  // ---------------------------------------------------------------------------
61  // Attributes
62 protected:
63 
64  /// Minimum correspondence weight (i.e., threshold used to truncate radial weight function)
65  mirtkPublicAttributeMacro(double, MinWeight);
66 
67  /// Weight matrix of fuzzy point correspondences
68  mirtkReadOnlyAttributeMacro(WeightMatrix, Weight);
69 
70  /// Untransformed target clusters corresponding to source points
71  mirtkAttributeMacro(PointSet, InputTargetClusters);
72 
73  /// Untransformed source clusters corresponding to target points
74  mirtkAttributeMacro(PointSet, InputSourceClusters);
75 
76  /// (Transformed) Target clusters corresponding to source points
77  mirtkAttributeMacro(PointSet, TargetClusters);
78 
79  /// (Transformed) Source clusters corresponding to target points
80  mirtkAttributeMacro(PointSet, SourceClusters);
81 
82  /// Whether a given target cluster is an outlier
83  mirtkAttributeMacro(Array<bool>, TargetOutlier);
84 
85  /// Whether a given source cluster is an outlier
86  mirtkAttributeMacro(Array<bool>, SourceOutlier);
87 
88  /// Standard deviation of normally distributed noise with zero mean
89  mirtkPublicAttributeMacro(double, GaussianNoise);
90 
91  // ---------------------------------------------------------------------------
92  // Construction/Destruction
93 protected:
94 
95  /// Default constructor
97 
98  /// Copy constructor
100 
101 public:
102 
103  /// Destructor
104  virtual ~FuzzyCorrespondence();
105 
106  // ---------------------------------------------------------------------------
107  // Parameters
108 
109  // Import other overloads
111 
112  /// Set parameter value from string
113  virtual bool Set(const char *, const char *);
114 
115  /// Get parameter key/value as string map
116  virtual ParameterList Parameter() const;
117 
118  // ---------------------------------------------------------------------------
119  // Correspondences
120 
121  /// Initialize correspondence map
122  virtual void Initialize();
123 
124  /// Reinitialize correspondence map after change of input topology
125  virtual void Reinitialize();
126 
127 protected:
128 
129  /// Common (re-)initialization steps of this class
130  /// \note Must be a non-virtual function!
131  void Init();
132 
133 public:
134 
135  /// Update correspondence map
136  virtual void Update();
137 
138  /// Update correspondence map after convergence
139  virtual bool Upgrade();
140 
141  /// Get untransformed target point corresponding to i-th source (sample) point
142  virtual bool GetInputTargetPoint(int, Point &) const;
143 
144  /// Get untransformed source point corresponding to i-th target (sample) point
145  virtual bool GetInputSourcePoint(int, Point &) const;
146 
147  /// Get (transformed) target point corresponding to i-th source (sample) point
148  virtual bool GetTargetPoint(int, Point &) const;
149 
150  /// Get (transformed) source point corresponding to i-th target (sample) point
151  virtual bool GetSourcePoint(int, Point &) const;
152 
153  // ---------------------------------------------------------------------------
154  // Internal
155 protected:
156 
157  /// (Re-)calculate correspondence weights with optional additional outlier row/column
158  virtual void CalculateWeights() = 0;
159 
160  /// Add normally distributed noise to correspondence weights
161  virtual void AddGaussianNoise();
162 
163  /// Normalize correspondence matrix using Sinkhorn-Knopp algorithm
164  virtual void NormalizeWeights();
165 
166  /// (Re-)calculate cluster centers from correspondence weights
167  virtual void CalculateClusters();
168 
169  // ---------------------------------------------------------------------------
170  // Debugging
171 
172  /// Write input of data fidelity term
173  virtual void WriteDataSets(const char *, const char *, bool = true) const;
174 
175 };
176 
177 
178 } // namespace mirtk
179 
180 #endif // MIRTK_FuzzyCorrespondence_H
virtual bool GetSourcePoint(int, Point &) const
Get (transformed) source point corresponding to i-th target (sample) point.
virtual void CalculateClusters()
(Re-)calculate cluster centers from correspondence weights
virtual void Initialize()
Initialize correspondence map.
mirtkReadOnlyAttributeMacro(WeightMatrix, Weight)
Weight matrix of fuzzy point correspondences.
virtual bool Upgrade()
Update correspondence map after convergence.
virtual bool GetInputTargetPoint(int, Point &) const
Get untransformed target point corresponding to i-th source (sample) point.
virtual ~FuzzyCorrespondence()
Destructor.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual void NormalizeWeights()
Normalize correspondence matrix using Sinkhorn-Knopp algorithm.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual bool Set(const char *, const char *)
Set parameter value from string.
virtual void WriteDataSets(const char *, const char *, bool=true) const
Write input of data fidelity term.
Definition: IOConfig.h:41
virtual bool GetTargetPoint(int, Point &) const
Get (transformed) target point corresponding to i-th source (sample) point.
GenericSparseMatrix< float > WeightMatrix
Sparse matrix type used for fuzzy correspondence weights.
mirtkAttributeMacro(PointSet, InputTargetClusters)
Untransformed target clusters corresponding to source points.
FuzzyCorrespondence()
Default constructor.
virtual void CalculateWeights()=0
(Re-)calculate correspondence weights with optional additional outlier row/column ...
virtual void Update()
Update correspondence map.
virtual void Reinitialize()
Reinitialize correspondence map after change of input topology.
mirtkPublicAttributeMacro(double, MinWeight)
Minimum correspondence weight (i.e., threshold used to truncate radial weight function) ...
virtual bool GetInputSourcePoint(int, Point &) const
Get untransformed source point corresponding to i-th target (sample) point.
virtual void AddGaussianNoise()
Add normally distributed noise to correspondence weights.