OTB  9.0.0
Orfeo Toolbox
otbQuadraticallyConstrainedSimpleSolver.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  * Copyright (C) 2016-2019 IRSTEA
5  *
6  * This file is part of Orfeo Toolbox
7  *
8  * https://www.orfeo-toolbox.org/
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #ifndef QuadraticallyConstrainedSimpleSolver_H_
23 #define QuadraticallyConstrainedSimpleSolver_H_
24 
25 #include "itkObjectFactory.h"
26 #include "itkLightObject.h"
27 #include "itkNumericTraits.h"
28 #include <vnl/vnl_matrix.h>
29 #include "vnl/algo/vnl_solve_qp.h"
30 
31 namespace otb
32 {
33 
65 template <class ValueType>
66 class ITK_EXPORT QuadraticallyConstrainedSimpleSolver : public itk::LightObject
67 {
68 public:
71  typedef itk::LightObject Superclass;
72  typedef itk::SmartPointer<Self> Pointer;
73  typedef itk::SmartPointer<const Self> ConstPointer;
74 
76  itkTypeMacro(QuadraticallyConstrainedSimpleSolver, LightObject);
77 
79  itkNewMacro(Self);
80 
82  typedef vnl_matrix<ValueType> RealMatrixType;
83  typedef vnl_vector<ValueType> RealVectorType;
84  typedef vnl_matrix<double> DoubleMatrixType;
85  typedef vnl_vector<double> DoubleVectorType;
86  typedef std::vector<unsigned int> ListIndexType;
87 
90  {
91  Cost_Function_rmse, // Root mean square error based
92  Cost_Function_musig, // Mean and standard deviation based
93  Cost_Function_mu, // Mean based
94  Cost_Function_weighted_musig // Mean and weighted standard deviation based
95  };
96 
98  void SetMeanInOverlaps(const RealMatrixType& matrix)
99  {
100  m_MeanInOverlaps = RealMatrixType(matrix);
101  }
103  {
104  return m_MeanInOverlaps;
105  }
107 
110  {
111  m_StandardDeviationInOverlaps = RealMatrixType(matrix);
112  }
114  {
115  return m_StandardDeviationInOverlaps;
116  }
118 
120  void SetAreaInOverlaps(const RealMatrixType& matrix)
121  {
122  m_AreaInOverlaps = RealMatrixType(matrix);
123  }
125  {
126  return m_AreaInOverlaps;
127  }
129 
132  {
133  m_MeanOfProductsInOverlaps = RealMatrixType(matrix);
134  }
136  {
137  return m_MeanOfProductsInOverlaps;
138  }
140 
143  {
144  return m_OutputCorrectionModel;
145  }
146 
153  void SetWeightOfStandardDeviationTerm(ValueType weight)
154  {
155  m_WeightOfStandardDeviationTerm = weight;
156  }
158  {
159  return m_WeightOfStandardDeviationTerm;
160  }
162 
164  void Solve();
165 
168  {
169  oft = Cost_Function_mu;
170  }
172  {
173  oft = Cost_Function_musig;
174  }
176  {
177  oft = Cost_Function_rmse;
178  }
180  {
181  oft = Cost_Function_weighted_musig;
182  }
184 
185 protected:
188 
189 private:
190  // Check inputs
191  void CheckInputs(void) const;
192 
193  // Deep First Search
194  void DFS(std::vector<bool>& marked, unsigned int s) const;
195 
196  // Compute the objective matrix
197  const DoubleMatrixType GetQuadraticObjectiveMatrix(const DoubleMatrixType& areas, const DoubleMatrixType& means, const DoubleMatrixType& stds,
198  const DoubleMatrixType& mops);
199 
200  // Extract a sub matrix from indices list
201  const DoubleMatrixType ExtractMatrix(const RealMatrixType& mat, const ListIndexType& idx);
202 
203  // Input
208 
209  // Params
210  ValueType m_WeightOfStandardDeviationTerm; // could be manually tuned for different results
211 
212  // Output correction models
214 
215  // objective function type (enum)
217 };
218 
219 } /* namespace otb */
220 #ifndef OTB_MANUAL_INSTANTIATION
222 #endif
223 #endif /* QuadraticallyConstrainedSimpleSolver_H_ */
otb::QuadraticallyConstrainedSimpleSolver::RealVectorType
vnl_vector< ValueType > RealVectorType
Definition: otbQuadraticallyConstrainedSimpleSolver.h:83
otb::QuadraticallyConstrainedSimpleSolver::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbQuadraticallyConstrainedSimpleSolver.h:73
otb::QuadraticallyConstrainedSimpleSolver::Cost_Function_musig
@ Cost_Function_musig
Definition: otbQuadraticallyConstrainedSimpleSolver.h:92
otb::QuadraticallyConstrainedSimpleSolver::Superclass
itk::LightObject Superclass
Definition: otbQuadraticallyConstrainedSimpleSolver.h:71
otb::QuadraticallyConstrainedSimpleSolver::Cost_Function_rmse
@ Cost_Function_rmse
Definition: otbQuadraticallyConstrainedSimpleSolver.h:91
otb::QuadraticallyConstrainedSimpleSolver::Cost_Function_mu
@ Cost_Function_mu
Definition: otbQuadraticallyConstrainedSimpleSolver.h:93
otb::QuadraticallyConstrainedSimpleSolver::SetMeanAndStandardDeviationBased
void SetMeanAndStandardDeviationBased()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:171
otb::QuadraticallyConstrainedSimpleSolver::DoubleMatrixType
vnl_matrix< double > DoubleMatrixType
Definition: otbQuadraticallyConstrainedSimpleSolver.h:84
otb::QuadraticallyConstrainedSimpleSolver::GetMeanOfProductsInOverlaps
const RealMatrixType GetMeanOfProductsInOverlaps()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:135
otb::QuadraticallyConstrainedSimpleSolver::m_MeanOfProductsInOverlaps
RealMatrixType m_MeanOfProductsInOverlaps
Definition: otbQuadraticallyConstrainedSimpleSolver.h:207
otb::QuadraticallyConstrainedSimpleSolver::SetStandardDeviationInOverlaps
void SetStandardDeviationInOverlaps(const RealMatrixType &matrix)
Definition: otbQuadraticallyConstrainedSimpleSolver.h:109
otb::QuadraticallyConstrainedSimpleSolver::SetMeanBased
void SetMeanBased()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:167
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::QuadraticallyConstrainedSimpleSolver::GetStandardDeviationInOverlaps
const RealMatrixType GetStandardDeviationInOverlaps()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:113
otb::QuadraticallyConstrainedSimpleSolver::ObjectiveFunctionType
ObjectiveFunctionType
Definition: otbQuadraticallyConstrainedSimpleSolver.h:89
otb::QuadraticallyConstrainedSimpleSolver::GetOutputCorrectionModel
const RealVectorType GetOutputCorrectionModel()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:142
otb::QuadraticallyConstrainedSimpleSolver::DoubleVectorType
vnl_vector< double > DoubleVectorType
Definition: otbQuadraticallyConstrainedSimpleSolver.h:85
otb::QuadraticallyConstrainedSimpleSolver::SetMeanInOverlaps
void SetMeanInOverlaps(const RealMatrixType &matrix)
Definition: otbQuadraticallyConstrainedSimpleSolver.h:98
otb::QuadraticallyConstrainedSimpleSolver
Solves the optimisation problem for radiometric harmonisation of multiple overlapping images.
Definition: otbQuadraticallyConstrainedSimpleSolver.h:66
otb::QuadraticallyConstrainedSimpleSolver::oft
ObjectiveFunctionType oft
Definition: otbQuadraticallyConstrainedSimpleSolver.h:216
otb::QuadraticallyConstrainedSimpleSolver::SetWeightedMeanAndStandardDeviationBased
void SetWeightedMeanAndStandardDeviationBased()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:179
otb::QuadraticallyConstrainedSimpleSolver::GetAreaInOverlaps
const RealMatrixType GetAreaInOverlaps()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:124
otb::QuadraticallyConstrainedSimpleSolver::ListIndexType
std::vector< unsigned int > ListIndexType
Definition: otbQuadraticallyConstrainedSimpleSolver.h:86
otb::QuadraticallyConstrainedSimpleSolver::SetMeanOfProductsInOverlaps
void SetMeanOfProductsInOverlaps(const RealMatrixType &matrix)
Definition: otbQuadraticallyConstrainedSimpleSolver.h:131
otb::QuadraticallyConstrainedSimpleSolver::m_OutputCorrectionModel
RealVectorType m_OutputCorrectionModel
Definition: otbQuadraticallyConstrainedSimpleSolver.h:213
otbQuadraticallyConstrainedSimpleSolver.hxx
otb::QuadraticallyConstrainedSimpleSolver::GetWeightOfStandardDeviationTerm
ValueType GetWeightOfStandardDeviationTerm()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:157
otb::QuadraticallyConstrainedSimpleSolver::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbQuadraticallyConstrainedSimpleSolver.h:72
otb::QuadraticallyConstrainedSimpleSolver::GetMeanInOverlaps
const RealMatrixType GetMeanInOverlaps()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:102
otb::QuadraticallyConstrainedSimpleSolver::SetAreaInOverlaps
void SetAreaInOverlaps(const RealMatrixType &matrix)
Definition: otbQuadraticallyConstrainedSimpleSolver.h:120
otb::QuadraticallyConstrainedSimpleSolver::SetWeightOfStandardDeviationTerm
void SetWeightOfStandardDeviationTerm(ValueType weight)
Definition: otbQuadraticallyConstrainedSimpleSolver.h:153
otb::QuadraticallyConstrainedSimpleSolver::m_MeanInOverlaps
RealMatrixType m_MeanInOverlaps
Definition: otbQuadraticallyConstrainedSimpleSolver.h:204
otb::QuadraticallyConstrainedSimpleSolver::m_WeightOfStandardDeviationTerm
ValueType m_WeightOfStandardDeviationTerm
Definition: otbQuadraticallyConstrainedSimpleSolver.h:210
otb::QuadraticallyConstrainedSimpleSolver::m_StandardDeviationInOverlaps
RealMatrixType m_StandardDeviationInOverlaps
Definition: otbQuadraticallyConstrainedSimpleSolver.h:205
otb::QuadraticallyConstrainedSimpleSolver::m_AreaInOverlaps
RealMatrixType m_AreaInOverlaps
Definition: otbQuadraticallyConstrainedSimpleSolver.h:206
otb::QuadraticallyConstrainedSimpleSolver::SetRMSEBased
void SetRMSEBased()
Definition: otbQuadraticallyConstrainedSimpleSolver.h:175
otb::RPCSolver::Solve
void Solve(const GCPsContainerType &gcpContainer, double &rmsError, Projection::RPCParam &outputParams)
otb::QuadraticallyConstrainedSimpleSolver::RealMatrixType
vnl_matrix< ValueType > RealMatrixType
Definition: otbQuadraticallyConstrainedSimpleSolver.h:79
otb::QuadraticallyConstrainedSimpleSolver::Self
QuadraticallyConstrainedSimpleSolver Self
Definition: otbQuadraticallyConstrainedSimpleSolver.h:70