ClassifierISOSegStrategy.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/ClassifierISOSegStrategy.h
22  \brief ISOSeg strategy for segmentation-based classification.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_CLASSIFIERISOSEGSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_CLASSIFIERISOSEGSTRATEGY_H
27 
28 // TerraLib
29 #include "ClassifierStrategy.h"
31 #include "Config.h"
32 
33 // STL
34 #include <map>
35 #include <memory>
36 
37 // Boost
38 #include <boost/numeric/ublas/matrix.hpp>
39 
40 namespace te
41 {
42  namespace rp
43  {
44  /*!
45  \class ClassifierISOSegStrategy
46 
47  \brief ISOSeg strategy for OBIA classification. The algorithm orders regions by area (larger first),
48  and classify the largest region as Cluster 1. All regions similar to this cluster are inserted
49  in Cluster 1, otherwise new Clusters are created. After all regions belong to a cluster, the
50  algorithm merges similar clusters. The acceptance threshold is the only parameter given by
51  the user, and it indicates the maximum distance between two regions to be clustered togheter.
52 
53  \ingroup rp_class
54  */
56  {
57  public:
58 
59  /*!
60  \class Parameters
61 
62  \brief Classifier Parameters
63  */
65  {
66  public:
67 
68  /*!
69  \enum class DistanceType
70  \brief Used distance type.
71  */
73  {
74  InvalidDistanceType, //!< Invalid distance type.
75  MahalanobisDistanceType, //!< Mahalanobis Distance Type.
76  BhattacharyyaDistanceType //!< Bhattacharyya Distance Type.
77  };
78 
79  DistanceType m_distanceType; //!< Distance type.
80  double m_acceptanceThreshold; //!< The acceptance threshold (the closer to 100\%, few clusters are created).
81 
82  Parameters();
83 
84  ~Parameters();
85 
86  //overload
87  const Parameters& operator=(const Parameters& params);
88 
89  //overload
90  void reset() throw( te::rp::Exception );
91 
92  //overload
93  AbstractParameters* clone() const;
94  };
95 
96  /*!
97  \class Pattern
98 
99  \brief Describes a region or a cluster (group of regions with similar properties) to be used by ISOSeg method.
100  */
102  {
103  public:
104 
105  Pattern();
106 
107  /*!
108  \brief Constructor.
109 
110  \param i The id of the initial region.
111  \param a The area of the region.
112  \param mv The vector of mean values, 1 value per band.
113  \param cm The covariance matrix between bands.
114  */
115  Pattern(int i, double a, std::vector<double> mv, boost::numeric::ublas::matrix<double> cm);
116 
117  /*!
118  \brief Copy constructor.
119 
120  \param rhs The right-hand-side copy that would be used to copy from.
121  */
122  Pattern( const Pattern& rhs);
123 
124  ~Pattern();
125 
126  /*! \brief Returns the Mahalanobis distance between two patterns */
127  double getMahalanobisDistance(Pattern const * const p) const;
128 
129  /*!
130  \brief Returns the Bhattacharyya distance between two patterns
131  \note Returns std::numeric_limits< double >::max() on errors.
132  */
133  double getBhattacharyyaDistance(Pattern const * const p) const;
134 
135  /*! \brief Return true if two clusters are equal. */
136  bool operator==( const Pattern& rhs) const;
137 
138  // overload
139  Pattern& operator=( const Pattern& rhs );
140 
141  // overload (by m_area comparison)
142  bool operator<(const Pattern& rhs) const;
143 
144  /*!
145  \brief Reset to initial state.
146  */
147  void reset();
148 
149  int m_id; //!< The id of the region of the pattern.
150  Pattern* m_myCluster; //!< The associated cluster of this pattern (optional).
151  double m_area; //!< The area of all regions inside a pattern.
152  double m_covarianceMatrixDet; //!< The covariance matrix determinant.
153  std::vector<double> m_meanVector; //!< The vector of mean values, 1 value per band;
154  boost::numeric::ublas::matrix<double> m_covarianceMatrix; //!< The covariance matrix between bands.
155  boost::numeric::ublas::matrix<double> m_covarianceInversion; //!< The inversion of covariance matrix between bands.
156 
157  // Variables used by the getBhattacharyyaDistance method
158  mutable unsigned int m_getBhattacharyyaDistance_nBands;
162  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_meansDif;
163  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_covsMege;
164  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_covsMegeInv;
165  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_distanceTerm1;
166  };
167 
168  public:
169 
171 
173 
174  //overload
175  bool initialize(ClassifierStrategyParameters const* const strategyParams) throw(te::rp::Exception);
176 
177  //overload
178  bool execute() throw(te::rp::Exception);
179 
180  protected:
181 
182  bool m_isInitialized; //!< True if this instance is initialized.
183  ClassifierISOSegStrategy::Parameters m_parameters; //!< Internal execution parameters.
184 
185  };
186 
187  /*!
188  \class ClassifierISOSegStrategyFactory
189 
190  \brief Raster ISOSeg Classifier strategy factory.
191 
192  \note Factory key: RegionGrowing
193  */
195  {
196  public:
197 
199 
201 
202  //overload
204  };
205 
206  } // end namespace rp
207 } // end namespace te
208 
209 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERISOSEGSTRATEGY_H
TEDATAACCESSEXPORT te::da::Expression * operator<(const te::da::Expression &e1, const te::da::Expression &e2)
Raster ISOSeg Classifier strategy factory.
Base exception class for plugin module.
Definition: Exception.h:42
boost::numeric::ublas::matrix< double > m_getBhattacharyyaDistance_distanceTerm1
boost::numeric::ublas::matrix< double > m_covarianceInversion
The inversion of covariance matrix between bands.
boost::numeric::ublas::matrix< double > m_getBhattacharyyaDistance_meansDif
TEDATAACCESSEXPORT te::da::Expression * operator==(const te::da::Expression &e1, const te::da::Expression &e2)
boost::numeric::ublas::matrix< double > m_getBhattacharyyaDistance_covsMege
boost::numeric::ublas::matrix< double > m_getBhattacharyyaDistance_covsMegeInv
Raster classifier strategy factory base class.
ISOSeg strategy for OBIA classification. The algorithm orders regions by area (larger first)...
URI C++ Library.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Raster classifier strategy factory base class.
int m_id
The id of the region of the pattern.
Configuration flags for the Raster Processing module of TerraLib.
Describes a region or a cluster (group of regions with similar properties) to be used by ISOSeg metho...
Raster classifier strategy base class.
double m_area
The area of all regions inside a pattern.
std::vector< double > m_meanVector
The vector of mean values, 1 value per band;.
Raster classifier strategy base class.
double m_acceptanceThreshold
The acceptance threshold (the closer to 100%, few clusters are created).
Pattern * m_myCluster
The associated cluster of this pattern (optional).
double m_covarianceMatrixDet
The covariance matrix determinant.
boost::numeric::ublas::matrix< double > m_covarianceMatrix
The covariance matrix between bands.