ClassifierMaxLikelihoodStrategy.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/rp/ClassifierMaxLikelihoodStrategy.h
22  \brief A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_CLASSIFIERMAXLIKELIHOODSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_CLASSIFIERMAXLIKELIHOODSTRATEGY_H
27 
28 #include "ClassifierStrategy.h"
30 #include "Matrix.h"
31 #include "Config.h"
32 #include "../classification/MaxLikelihood.h"
33 #include "../classification/Adaptors.h"
34 
35 #include <boost/shared_ptr.hpp>
36 
37 #include <map>
38 #include <vector>
39 
40 namespace te
41 {
42  namespace rp
43  {
44  /*!
45  \class ClassifierMaxLikelihoodStrategy
46 
47  \brief A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
48 
49  \ingroup rp_class
50 
51  \see te::cl::MaxLikelihood class docs
52  */
54  {
55  public:
56 
57  /*!
58  \class Parameters
59 
60  \brief Classifier Parameters
61  */
63  {
64  public:
65 
66  typedef unsigned int ClassIDT; //!< Class ID type definition (zero means invalid ID).
67 
68  typedef std::vector< double > ClassSampleT; //!< Class sample type definition.
69 
70  typedef std::vector< ClassSampleT > ClassSamplesContainerT; //!< Class samples container type definition.
71 
72  typedef std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT; //!< Multi-classes samples container type definition.
73 
74  typedef boost::shared_ptr<MClassesSamplesCT> MClassesSamplesCTPtr; //!< A shared pointer to a multi classes samples container type definition.
75 
76  MClassesSamplesCTPtr m_trainSamplesPtr; //!< A shared pointer to a always-valid structure where trainning samples are stored.
77 
78  bool m_applyICM; //!< Apply a Iterated conditional modes iteractive filtering (default:false);
79 
80  float m_icmChangesThreshold; //!< Minimum porcentage of number of pixel that changes from one iteration to the other [valid values range:1-100, default:10)].
81 
82  unsigned int m_icmMaxIterations; //!< Maximum number of ICM iterations to perform (default 10).
83 
85 
87 
88  //overload
89  const Parameters& operator=(const Parameters& params);
90 
91  //overload
92  void reset() throw( te::rp::Exception );
93 
94  //overload
95  AbstractParameters* clone() const;
96  };
97 
99 
101 
102  //overload
103  bool initialize(ClassifierStrategyParameters const* const strategyParams) throw(te::rp::Exception);
104 
105  //overload
106  bool execute() throw(te::rp::Exception);
107 
108  unsigned int getOutputNumberBands(void);
109 
110  protected :
111 
112  bool m_isInitialized; //!< Is this instance initialized?
113 
114  Parameters::ClassIDT m_highestTrainClassID; //!< The highest train sample lable.
115 
116  ClassifierMaxLikelihoodStrategy::Parameters m_initParams; //!< Initialization parameters.
117 
118  te::cl::MaxLikelihood m_genClassInstance; //!< A generir classifier instance.
119 
120  /*!
121  \brief Apply an ICM filter
122  \param inputRaster Input raster.
123  \param matrixPtr A pointer to a input/output classified matrix (the pointer may be reassigned if required).
124  \param classifiedMatrixNoDataValue Matrix no-data value.
125  \param errorMessage Error message.
126  \return true if OK, false on errors;
127  */
128  bool applyICM(
129  const te::rst::Raster& inputRaster,
130  std::unique_ptr< te::rp::Matrix< unsigned int > >& matrixPtr,
131  const unsigned int classifiedMatrixNoDataValue,
132  std::string& errorMessage ) const;
133 
134  /*!
135  \brief Iteration Beta value Calule.
136  \param matrix Current classified matrix.
137  \param matrixNoDataValue Matrix no-data value.
138  \param errorMessage Error message.
139  \return true if OK, false on errors;
140  */
141  bool getICMBeta( const te::rp::Matrix< unsigned int >& matrix,
142  const unsigned int matrixNoDataValue,
143  double& betaValue, std::string& errorMessage ) const;
144 
145  /*!
146  \brief Metodo da biseccao para achar os zeros de uma funcao de dupla precisao com
147  parametros. Numerical Recipes in C cap 9. Versao del 22 de agosto de 1990.
148  INPE. O vetor (double)param contem os seguintes valores: param[0] = o
149  minimo do intervalo de procura param[1] = o maximo do intervalo de procura
150  param[2] = a tolerancia param[3] ... param[n] = parametros da funcao
151 
152  \note Imported from SPRING
153  */
154  double rtbis(double (*func) (double x, double *param), double *param) const;
155 
156  static double plikehood_2(double , double * );
157 
158  static double plikehood_3(double , double * );
159 
160  static double plikehood_4(double , double * );
161 
162  static double sigmo( double a );
163 
164  /*! \brief Compute the common part in pseudo-likelihood equation.
165  \param img_box : image to process.
166  \param term : comom part
167  */
168  static void Estimacao_geral( double *term, const te::rp::Matrix< unsigned int >& matrix );
169 
170  static int compara_uchar_vesre(const void *x, const void *y);
171  };
172 
173  /*!
174  \class ClassifierMaxLikelihoodStrategyFactory
175 
176  \brief Maximum a posteriori probability strategy factory.
177 
178  \note Factory key: RegionGrowing
179  */
181  {
182  public:
183 
185 
187 
188  //overload
190  };
191 
192  } // end namespace rp
193 } // end namespace te
194 
195 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERMAXLIKELIHOODSTRATEGY_H
196 
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::Parameters
Parameters()
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::m_trainSamplesPtr
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
Definition: ClassifierMaxLikelihoodStrategy.h:76
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::ClassSamplesContainerT
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
Definition: ClassifierMaxLikelihoodStrategy.h:70
te::rp::Matrix
A generic template matrix.
Definition: Matrix.h:55
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::ClassIDT
unsigned int ClassIDT
Class ID type definition (zero means invalid ID).
Definition: ClassifierMaxLikelihoodStrategy.h:66
te::rp::ClassifierStrategyParameters
Classifier Strategy Parameters.
Definition: ClassifierStrategyParameters.h:42
Matrix.h
Generic template matrix.
te::rp::ClassifierMaxLikelihoodStrategyFactory
Maximum a posteriori probability strategy factory.
Definition: ClassifierMaxLikelihoodStrategy.h:181
te::rp::ClassifierMaxLikelihoodStrategyFactory::build
te::rp::ClassifierStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects.
ClassifierStrategy.h
Raster classifier strategy base class.
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::~Parameters
~Parameters()
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::MClassesSamplesCT
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
Definition: ClassifierMaxLikelihoodStrategy.h:72
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::reset
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rp::ClassifierMaxLikelihoodStrategy::Parameters
Classifier Parameters.
Definition: ClassifierMaxLikelihoodStrategy.h:63
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::ClassSampleT
std::vector< double > ClassSampleT
Class sample type definition.
Definition: ClassifierMaxLikelihoodStrategy.h:68
te::Exception
Base exception class for plugin module.
Definition: Exception.h:42
TERPEXPORT
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::m_applyICM
bool m_applyICM
Apply a Iterated conditional modes iteractive filtering (default:false);.
Definition: ClassifierMaxLikelihoodStrategy.h:78
te::rp::ClassifierMaxLikelihoodStrategy
A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
Definition: ClassifierMaxLikelihoodStrategy.h:54
te::rp::ClassifierMaxLikelihoodStrategyFactory::ClassifierMaxLikelihoodStrategyFactory
ClassifierMaxLikelihoodStrategyFactory()
te::rp::ClassifierStrategyFactory
Raster classifier strategy factory base class.
Definition: ClassifierStrategyFactory.h:47
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::operator=
const Parameters & operator=(const Parameters &params)
te::rp::ClassifierMaxLikelihoodStrategyFactory::~ClassifierMaxLikelihoodStrategyFactory
~ClassifierMaxLikelihoodStrategyFactory()
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::rp::ClassifierStrategy
Raster classifier strategy base class.
Definition: ClassifierStrategy.h:49
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::m_icmChangesThreshold
float m_icmChangesThreshold
Minimum porcentage of number of pixel that changes from one iteration to the other [valid values rang...
Definition: ClassifierMaxLikelihoodStrategy.h:80
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::m_icmMaxIterations
unsigned int m_icmMaxIterations
Maximum number of ICM iterations to perform (default 10).
Definition: ClassifierMaxLikelihoodStrategy.h:82
ClassifierStrategyFactory.h
Raster classifier strategy factory base class.
te::rp::ClassifierMaxLikelihoodStrategy::Parameters::MClassesSamplesCTPtr
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
Definition: ClassifierMaxLikelihoodStrategy.h:74