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  double m_acceptanceThreshold; //!< The acceptance threshold (the closer to 100\%, few clusters are created).
68 
69  Parameters();
70 
71  ~Parameters();
72 
73  //overload
74  const Parameters& operator=(const Parameters& params);
75 
76  //overload
77  void reset() throw( te::rp::Exception );
78 
79  //overload
80  AbstractParameters* clone() const;
81  };
82 
83  /*!
84  \class Pattern
85 
86  \brief Describes a region or a cluster (group of regions with similar properties) to be used by ISOSeg method.
87  */
89  {
90  public:
91 
92  Pattern();
93 
94  /*!
95  \brief Constructor.
96 
97  \param i The id of the initial region.
98  \param a The area of the region.
99  \param mv The vector of mean values, 1 value per band.
100  \param cm The covariance matrix between bands.
101  */
102  Pattern(int i, double a, std::vector<double> mv, boost::numeric::ublas::matrix<double> cm);
103 
104  /*!
105  \brief Copy constructor.
106 
107  \param rhs The right-hand-side copy that would be used to copy from.
108  */
109  Pattern(Pattern& rhs);
110 
111  ~Pattern();
112 
113  /*!
114  \brief Add a region inside a cluster.
115 
116  \param p The region to be added.
117  */
118  void add(Pattern* p);
119 
120  /*! \brief Returns the Mahalanobis distance between two patterns */
121  double getDistance(Pattern* p);
122 
123  /*! \brief Return true if two clusters are equal. */
124  bool operator=(Pattern& rhs);
125 
126  int m_id; //!< The id of the region of the pattern.
127  Pattern* m_myCluster; //!< The associated cluster of this pattern (optional).
128  double m_area; //!< The area of all regions inside a pattern.
129  std::vector<double> m_meanVector; //!< The vector of mean values, 1 value per band;
130  boost::numeric::ublas::matrix<double> m_covarianceMatrix; //!< The covariance matrix between bands.
131  boost::numeric::ublas::matrix<double> m_covarianceInversion; //!< The inversion of covariance matrix between bands.
132  };
133 
134  public:
135 
137 
139 
140  //overload
141  bool initialize(ClassifierStrategyParameters const* const strategyParams) throw(te::rp::Exception);
142 
143  //overload
144  bool execute(const te::rst::Raster& inputRaster, const std::vector<unsigned int>& inputRasterBands,
145  const std::vector<te::gm::Polygon*>& inputPolygons, te::rst::Raster& outputRaster,
146  const unsigned int outputRasterBand, const bool enableProgressInterface) throw(te::rp::Exception);
147 
148  // overload
149  std::vector< int > getOutputDataTypes() const;
150 
151  protected:
152 
153  bool m_isInitialized; //!< True if this instance is initialized.
154  ClassifierISOSegStrategy::Parameters m_parameters; //!< Internal execution parameters.
155  std::multimap<double, Pattern*, std::greater<double> > m_regions; //!< A descriptive set of regions (area, features).
156  };
157 
158  /*!
159  \class ClassifierISOSegStrategyFactory
160 
161  \brief Raster ISOSeg Classifier strategy factory.
162 
163  \note Factory key: RegionGrowing
164  */
166  {
167  public:
168 
170 
172 
173  //overload
175  };
176 
177  } // end namespace rp
178 } // end namespace te
179 
180 #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_covarianceInversion
The inversion of covariance matrix between bands.
Defines the exact sequence of characters that are acceptable.
Definition: Enums.h:102
std::multimap< double, Pattern *, std::greater< double > > m_regions
A descriptive set of regions (area, features).
bool m_isInitialized
True if this instance is initialized.
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).
boost::numeric::ublas::matrix< double > m_covarianceMatrix
The covariance matrix between bands.