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 
36 // Boost
37 #include <boost/numeric/ublas/matrix.hpp>
38 
39 namespace te
40 {
41  namespace rp
42  {
43  /*!
44  \class ClassifierISOSegStrategy
45 
46  \brief ISOSeg strategy for OBIA classification. The algorithm orders regions by area (larger first),
47  and classify the largest region as Cluster 1. All regions similar to this cluster are inserted
48  in Cluster 1, otherwise new Clusters are created. After all regions belong to a cluster, the
49  algorithm merges similar clusters. The acceptance threshold is the only parameter given by
50  the user, and it indicates the maximum distance between two regions to be clustered togheter.
51 
52  \ingroup rp_class
53  */
55  {
56  public:
57 
58  /*!
59  \class Parameters
60 
61  \brief Classifier Parameters
62  */
64  {
65  public:
66 
67  /*!
68  \enum class DistanceType
69  \brief Used distance type.
70  */
72  {
73  InvalidDistanceType, //!< Invalid distance type.
74  MahalanobisDistanceType, //!< Mahalanobis Distance Type.
75  BhattacharyyaDistanceType //!< Bhattacharyya Distance Type.
76  };
77 
78  DistanceType m_distanceType; //!< Distance type.
79  double m_acceptanceThreshold; //!< The acceptance threshold (the closer to 100\%, few clusters are created).
80 
81  Parameters();
82 
83  ~Parameters();
84 
85  //overload
86  const Parameters& operator=(const Parameters& params);
87 
88  //overload
89  void reset() throw( te::rp::Exception );
90 
91  //overload
92  AbstractParameters* clone() const;
93  };
94 
95  /*!
96  \class Pattern
97 
98  \brief Describes a region or a cluster (group of regions with similar properties) to be used by ISOSeg method.
99  */
101  {
102  public:
103 
104  Pattern();
105 
106  /*!
107  \brief Constructor.
108 
109  \param i The id of the initial region.
110  \param a The area of the region.
111  \param mv The vector of mean values, 1 value per band.
112  \param cm The covariance matrix between bands.
113  */
114  Pattern(int i, double a, std::vector<double> mv, boost::numeric::ublas::matrix<double> cm);
115 
116  /*!
117  \brief Copy constructor.
118 
119  \param rhs The right-hand-side copy that would be used to copy from.
120  */
121  Pattern(Pattern& rhs);
122 
123  ~Pattern();
124 
125  /*! \brief Returns the Mahalanobis distance between two patterns */
126  double getMahalanobisDistance(Pattern const * const p) const;
127 
128  /*!
129  \brief Returns the Bhattacharyya distance between two patterns
130  \note Returns std::numeric_limits< double >::max() on errors.
131  */
132  double getBhattacharyyaDistance(Pattern const * const p) const;
133 
134  /*! \brief Return true if two clusters are equal. */
135  bool operator=(Pattern& rhs);
136 
137  int m_id; //!< The id of the region of the pattern.
138  Pattern* m_myCluster; //!< The associated cluster of this pattern (optional).
139  double m_area; //!< The area of all regions inside a pattern.
140  double m_covarianceMatrixDet; //!< The covariance matrix determinant.
141  std::vector<double> m_meanVector; //!< The vector of mean values, 1 value per band;
142  boost::numeric::ublas::matrix<double> m_covarianceMatrix; //!< The covariance matrix between bands.
143  boost::numeric::ublas::matrix<double> m_covarianceInversion; //!< The inversion of covariance matrix between bands.
144 
145  // Variables used by the getBhattacharyyaDistance method
146  mutable unsigned int m_getBhattacharyyaDistance_nBands;
150  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_meansDif;
151  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_covsMege;
152  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_covsMegeInv;
153  mutable boost::numeric::ublas::matrix<double> m_getBhattacharyyaDistance_distanceTerm1;
154  };
155 
156  public:
157 
159 
161 
162  //overload
163  bool initialize(ClassifierStrategyParameters const* const strategyParams) throw(te::rp::Exception);
164 
165  //overload
166  bool execute(const te::rst::Raster& inputRaster, const std::vector<unsigned int>& inputRasterBands,
167  const std::vector<te::gm::Polygon*>& inputPolygons, te::rst::Raster& outputRaster,
168  const unsigned int outputRasterBand, const bool enableProgressInterface) throw(te::rp::Exception);
169 
170  // overload
171  std::vector< int > getOutputDataTypes() const;
172 
173  protected:
174 
175  bool m_isInitialized; //!< True if this instance is initialized.
176  ClassifierISOSegStrategy::Parameters m_parameters; //!< Internal execution parameters.
177  std::multimap<double, Pattern*, std::greater<double> > m_regions; //!< A descriptive set of regions (area, features).
178  };
179 
180  /*!
181  \class ClassifierISOSegStrategyFactory
182 
183  \brief Raster ISOSeg Classifier strategy factory.
184 
185  \note Factory key: RegionGrowing
186  */
188  {
189  public:
190 
192 
194 
195  //overload
197  };
198 
199  } // end namespace rp
200 } // end namespace te
201 
202 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERISOSEGSTRATEGY_H
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
std::multimap< double, Pattern *, std::greater< double > > m_regions
A descriptive set of regions (area, features).
boost::numeric::ublas::matrix< double > m_getBhattacharyyaDistance_covsMege
bool m_isInitialized
True if this instance is initialized.
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)...
An abstract class for raster data strucutures.
Definition: Raster.h:71
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.
ClassifierISOSegStrategy::Parameters m_parameters
Internal execution parameters.
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.