OTB  9.0.0
Orfeo Toolbox
otbMDMDNMFImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbMDMDNMFImageFilter_h
22 #define otbMDMDNMFImageFilter_h
23 
24 #include "itkImageToImageFilter.h"
26 
27 #include "vnl/vnl_matrix.h"
28 #include "vnl/vnl_vector.h"
29 
30 namespace otb
31 {
127 template <class TInputImage, class TOutputImage>
128 class ITK_EXPORT MDMDNMFImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>
129 {
130 public:
133  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
134  typedef itk::SmartPointer<Self> Pointer;
135  typedef itk::SmartPointer<const Self> ConstPointer;
136 
138  itkNewMacro(Self);
139 
141  itkTypeMacro(MDMDNMFImageFilter, ImageToImageFilter);
142 
144  typedef TInputImage InputImageType;
145  typedef typename InputImageType::Pointer InputPointerType;
146  typedef typename InputImageType::ConstPointer InputConstPointerType;
147  typedef typename InputImageType::IndexType InputIndexType;
148  typedef typename InputImageType::SizeType InputSizeType;
149  typedef typename InputImageType::PixelType InputPixelType;
150 
151  typedef TOutputImage OutputImageType;
152  typedef typename OutputImageType::Pointer OutputPointerType;
153  typedef typename OutputImageType::IndexType OutputIndexType;
154  typedef typename OutputImageType::OffsetType OutputOffsetType;
155  typedef typename OutputImageType::SizeType OutputSizeType;
156  typedef typename OutputImageType::RegionType OutputImageRegionType;
157  typedef typename OutputImageType::PixelType OutputPixelType;
158 
159  /* Matrix type */
160  typedef double PrecisionType;
161  typedef vnl_matrix<PrecisionType> MatrixType;
163 
164  /* vector type */
165  typedef vnl_vector<double> VectorType;
166 
168  {
169  return m_Endmembers;
170  }
172  {
173  m_Endmembers = m;
174  }
175 
177  itkSetMacro(MaxIter, unsigned int);
178  itkGetMacro(MaxIter, unsigned int);
180 
181  itkSetMacro(CritStopValue, double);
182  itkGetMacro(CritStopValue, double);
183 
184  itkSetMacro(Delt, double);
185  itkGetMacro(Delt, double);
186 
187  itkSetMacro(LambdD, double);
188  itkGetMacro(LambdD, double);
189 
190  itkSetMacro(LambdS, double);
191  itkGetMacro(LambdS, double);
192 
193 protected:
196  {
197  }
198  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
199 
200  void GenerateInputRequestedRegion() override;
201 
205  void GenerateOutputInformation() override;
206 
208  void GenerateData() override;
209 
210 
211 private:
212  MDMDNMFImageFilter(const Self&) = delete;
213  void operator=(const Self&) = delete;
214 
215  static void AddOneRowOfOnes(const MatrixType& m, MatrixType& M);
216 
217  static double Criterion(const MatrixType& X, const MatrixType& A, const MatrixType& S, const double& delt, const double& lambdS, const double& lambdD);
218 
219  static void EvalGradS(const MatrixType& X, const MatrixType& A, const MatrixType& S, const double& delt, const double& lambdS, MatrixType& gradS);
220 
221  static void EvalGradA(const MatrixType& X, const MatrixType& A, const MatrixType& S, const double& delt, const double& lambdD, MatrixType& gradA);
222 
223  static double Call(const MatrixType& variMat, const MatrixType& fixedMat, const MatrixType& X, const double& delt, const double& lambdS, const double& lambdD,
224  const bool isDirectEvalDirection);
225 
226  static void ProjGradOneStep(const MatrixType& X, const MatrixType& fixedMat, const MatrixType& gradVariMat, const double& sig, const double& betinit,
227  const double& delt, const double& lambdS, const double& lambdD, MatrixType& variMat, double& alph,
228  const bool isDirectEvalDirection);
229 
230  static void SetNegativeCoefficientsToZero(MatrixType& M);
231 
232  static MatrixType TermByTermMatrixProduct(const MatrixType& M1, const MatrixType& M2);
233 
234  static double SumMatrixElements(const MatrixType& M);
235 
236  static bool ArmijoTest(const double& sig, const MatrixType variMat, const MatrixType& newVariMat, const double& evalf, const double& newEvalf,
237  const MatrixType& gradVariMat, const double& alph);
238 
239  // attributes
241  unsigned int m_MaxIter;
243 
244  // Optimized function parameters
245  double m_Delt;
246  double m_LambdD;
247  double m_LambdS;
248 };
249 
250 } // end namespace otb
251 
252 #ifndef OTB_MANUAL_INSTANTIATION
253 #include "otbMDMDNMFImageFilter.hxx"
254 #endif
255 
256 #endif
otb::MDMDNMFImageFilter::SetEndmembersMatrix
void SetEndmembersMatrix(const MatrixType &m)
Definition: otbMDMDNMFImageFilter.h:171
otb::MDMDNMFImageFilter::InputPixelType
InputImageType::PixelType InputPixelType
Definition: otbMDMDNMFImageFilter.h:149
otb::MDMDNMFImageFilter::m_MaxIter
unsigned int m_MaxIter
Definition: otbMDMDNMFImageFilter.h:241
otb::MDMDNMFImageFilter::PrecisionType
double PrecisionType
Definition: otbMDMDNMFImageFilter.h:160
otb::MDMDNMFImageFilter::OutputPointerType
OutputImageType::Pointer OutputPointerType
Definition: otbMDMDNMFImageFilter.h:152
otb::MDMDNMFImageFilter::m_Endmembers
MatrixType m_Endmembers
Definition: otbMDMDNMFImageFilter.h:240
otb::MDMDNMFImageFilter::OutputSizeType
OutputImageType::SizeType OutputSizeType
Definition: otbMDMDNMFImageFilter.h:155
otb::MDMDNMFImageFilter::GetEndmembersMatrix
MatrixType GetEndmembersMatrix() const
Definition: otbMDMDNMFImageFilter.h:167
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MDMDNMFImageFilter::~MDMDNMFImageFilter
~MDMDNMFImageFilter() override
Definition: otbMDMDNMFImageFilter.h:195
otb::MDMDNMFImageFilter::m_LambdS
double m_LambdS
Definition: otbMDMDNMFImageFilter.h:247
otb::MDMDNMFImageFilter::OutputPixelType
OutputImageType::PixelType OutputPixelType
Definition: otbMDMDNMFImageFilter.h:157
otb::MDMDNMFImageFilter::m_CritStopValue
double m_CritStopValue
Definition: otbMDMDNMFImageFilter.h:242
otb::MDMDNMFImageFilter::OutputOffsetType
OutputImageType::OffsetType OutputOffsetType
Definition: otbMDMDNMFImageFilter.h:154
otb::MDMDNMFImageFilter::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbMDMDNMFImageFilter.h:133
otb::MDMDNMFImageFilter::Self
MDMDNMFImageFilter Self
Definition: otbMDMDNMFImageFilter.h:132
otb::MDMDNMFImageFilter::InputConstPointerType
InputImageType::ConstPointer InputConstPointerType
Definition: otbMDMDNMFImageFilter.h:146
otb::MDMDNMFImageFilter::InputPointerType
InputImageType::Pointer InputPointerType
Definition: otbMDMDNMFImageFilter.h:145
otb::MDMDNMFImageFilter::OutputIndexType
OutputImageType::IndexType OutputIndexType
Definition: otbMDMDNMFImageFilter.h:153
otbVectorImageToMatrixImageFilter.h
otb::MDMDNMFImageFilter::VectorImageToMatrixImageFilterType
otb::VectorImageToMatrixImageFilter< InputImageType > VectorImageToMatrixImageFilterType
Definition: otbMDMDNMFImageFilter.h:162
otb::VectorImageToMatrixImageFilter
This class streams the whole input image through the PersistentStatisticsImageFilter.
Definition: otbVectorImageToMatrixImageFilter.h:152
otb::MDMDNMFImageFilter
Definition: otbMDMDNMFImageFilter.h:128
otb::MDMDNMFImageFilter::InputImageType
TInputImage InputImageType
Definition: otbMDMDNMFImageFilter.h:141
otb::MDMDNMFImageFilter::m_Delt
double m_Delt
Definition: otbMDMDNMFImageFilter.h:245
otbMDMDNMFImageFilter.hxx
otb::MDMDNMFImageFilter::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbMDMDNMFImageFilter.h:156
otb::MDMDNMFImageFilter::MatrixType
vnl_matrix< PrecisionType > MatrixType
Definition: otbMDMDNMFImageFilter.h:161
otb::MDMDNMFImageFilter::InputIndexType
InputImageType::IndexType InputIndexType
Definition: otbMDMDNMFImageFilter.h:147
otb::MDMDNMFImageFilter::m_LambdD
double m_LambdD
Definition: otbMDMDNMFImageFilter.h:246
otb::MDMDNMFImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbMDMDNMFImageFilter.h:135
otb::MDMDNMFImageFilter::InputSizeType
InputImageType::SizeType InputSizeType
Definition: otbMDMDNMFImageFilter.h:148
otb::MDMDNMFImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbMDMDNMFImageFilter.h:134
otb::MDMDNMFImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: otbMDMDNMFImageFilter.h:151
otb::MDMDNMFImageFilter::VectorType
vnl_vector< double > VectorType
Definition: otbMDMDNMFImageFilter.h:165