Loading...
Searching...
No Matches
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
40namespace te
41{
42 namespace rp
43 {
44 class AlgorithmParametersSerializer;
45
46 /*!
47 \class ClassifierMaxLikelihoodStrategy
48
49 \brief A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
50
51 \ingroup rp_class
52
53 \see te::cl::MaxLikelihood class docs
54 */
56 {
57 public:
58
59 /*!
60 \class Parameters
61
62 \brief Classifier Parameters
63 */
65 {
66 public:
67
68 typedef unsigned int ClassIDT; //!< Class ID type definition (zero means invalid ID).
69
70 typedef std::vector< double > ClassSampleT; //!< Class sample type definition.
71
72 typedef std::vector< ClassSampleT > ClassSamplesContainerT; //!< Class samples container type definition.
73
74 typedef std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT; //!< Multi-classes samples container type definition.
75
76 typedef boost::shared_ptr<MClassesSamplesCT> MClassesSamplesCTPtr; //!< A shared pointer to a multi classes samples container type definition.
77
78 MClassesSamplesCTPtr m_trainSamplesPtr; //!< A shared pointer to a always-valid structure where trainning samples are stored.
79
80 bool m_applyICM; //!< Apply a Iterated conditional modes iteractive filtering (default:false);
81
82 float m_icmChangesThreshold; //!< Minimum porcentage of number of pixel that changes from one iteration to the other [valid values range:1-100, default:10)].
83
84 unsigned int m_icmMaxIterations; //!< Maximum number of ICM iterations to perform (default 10).
85
87
89
90 //overload
91 const Parameters& operator=(const Parameters& params);
92
93 //overload
94 void reset() ;
95
96 //overload
97 AbstractParameters* clone() const;
98
99 //overload
100 bool serialize ( AlgorithmParametersSerializer& serializer ) const;
101 };
102
104
106
107 //overload
108 bool initialize(ClassifierStrategyParameters const* const strategyParams) ;
109
110 //overload
111 bool execute() ;
112
113 unsigned int getOutputNumberBands(void);
114
115 protected :
116
117 bool m_isInitialized; //!< Is this instance initialized?
118
119 Parameters::ClassIDT m_highestTrainClassID; //!< The highest train sample lable.
120
122
123 te::cl::MaxLikelihood m_genClassInstance; //!< A generir classifier instance.
124
125 /*!
126 \brief Apply an ICM filter
127 \param inputRaster Input raster.
128 \param matrixPtr A pointer to a input/output classified matrix (the pointer may be reassigned if required).
129 \param classifiedMatrixNoDataValue Matrix no-data value.
130 \param errorMessage Error message.
131 \return true if OK, false on errors;
132 */
134 const te::rst::Raster& inputRaster,
135 std::unique_ptr< te::rp::Matrix< unsigned int > >& matrixPtr,
136 const unsigned int classifiedMatrixNoDataValue,
137 std::string& errorMessage ) const;
138
139 /*!
140 \brief Iteration Beta value Calule.
141 \param matrix Current classified matrix.
142 \param matrixNoDataValue Matrix no-data value.
143 \param errorMessage Error message.
144 \return true if OK, false on errors;
145 */
147 const unsigned int matrixNoDataValue,
148 double& betaValue, std::string& errorMessage ) const;
149
150 /*!
151 \brief Metodo da biseccao para achar os zeros de uma funcao de dupla precisao com
152 parametros. Numerical Recipes in C cap 9. Versao del 22 de agosto de 1990.
153 INPE. O vetor (double)param contem os seguintes valores: param[0] = o
154 minimo do intervalo de procura param[1] = o maximo do intervalo de procura
155 param[2] = a tolerancia param[3] ... param[n] = parametros da funcao
156
157 \note Imported from SPRING
158 */
159 double rtbis(double (*func) (double x, double *param), double *param) const;
160
161 static double plikehood_2(double , double * );
162
163 static double plikehood_3(double , double * );
164
165 static double plikehood_4(double , double * );
166
167 static double sigmo( double a );
168
169 /*! \brief Compute the common part in pseudo-likelihood equation.
170 \param img_box : image to process.
171 \param term : comom part
172 */
173 static void Estimacao_geral( double *term, const te::rp::Matrix< unsigned int >& matrix );
174
175 static int compara_uchar_vesre(const void *x, const void *y);
176 };
177
178 /*!
179 \class ClassifierMaxLikelihoodStrategyFactory
180
181 \brief Maximum a posteriori probability strategy factory.
182
183 \note Factory key: RegionGrowing
184 */
186 {
187 public:
188
190
192
193 //overload
195 };
196
197 } // end namespace rp
198} // end namespace te
199
200#endif // __TERRALIB_RP_INTERNAL_CLASSIFIERMAXLIKELIHOODSTRATEGY_H
201
Raster classifier strategy factory base class.
Raster classifier strategy base class.
Generic template matrix.
A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
Definition: MaxLikelihood.h:56
A class to standardize algorithm parameters serialization.
Maximum a posteriori probability strategy factory.
te::rp::ClassifierStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
float m_icmChangesThreshold
Minimum porcentage of number of pixel that changes from one iteration to the other [valid values rang...
unsigned int ClassIDT
Class ID type definition (zero means invalid ID).
const Parameters & operator=(const Parameters &params)
bool serialize(AlgorithmParametersSerializer &serializer) const
Returns a parameter serialization object.
std::vector< double > ClassSampleT
Class sample type definition.
unsigned int m_icmMaxIterations
Maximum number of ICM iterations to perform (default 10).
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
AbstractParameters * clone() const
Create a clone copy of this instance.
bool m_applyICM
Apply a Iterated conditional modes iteractive filtering (default:false);.
A maximum likelihood estimation strategy for classification (a.k.a. MaxVer in portuguese).
static double plikehood_3(double, double *)
bool getICMBeta(const te::rp::Matrix< unsigned int > &matrix, const unsigned int matrixNoDataValue, double &betaValue, std::string &errorMessage) const
Iteration Beta value Calule.
Parameters::ClassIDT m_highestTrainClassID
The highest train sample lable.
static double plikehood_4(double, double *)
static int compara_uchar_vesre(const void *x, const void *y)
static void Estimacao_geral(double *term, const te::rp::Matrix< unsigned int > &matrix)
Compute the common part in pseudo-likelihood equation.
te::cl::MaxLikelihood m_genClassInstance
A generir classifier instance.
double rtbis(double(*func)(double x, double *param), double *param) const
Metodo da biseccao para achar os zeros de uma funcao de dupla precisao com parametros....
bool initialize(ClassifierStrategyParameters const *const strategyParams)
Initialize the classification strategy.
bool applyICM(const te::rst::Raster &inputRaster, std::unique_ptr< te::rp::Matrix< unsigned int > > &matrixPtr, const unsigned int classifiedMatrixNoDataValue, std::string &errorMessage) const
Apply an ICM filter.
bool execute()
Executes the classification strategy.
static double plikehood_2(double, double *)
ClassifierMaxLikelihoodStrategy::Parameters m_initParams
Initialization parameters.
Raster classifier strategy factory base class.
Raster classifier strategy base class.
A generic template matrix.
Definition: Matrix.h:55
An abstract class for raster data strucutures.
Definition: Raster.h:72
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Proxy configuration file for TerraView (see terraview_config.h).