All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClassifierISOSegStrategy.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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  */
53  {
54  public:
55 
56  /*!
57  \class Parameters
58 
59  \brief Classifier Parameters
60  */
62  {
63  public:
64 
65  double m_acceptanceThreshold; //!< The acceptance threshold (the closer to 100\%, few clusters are created).
66 
67  Parameters();
68 
69  ~Parameters();
70 
71  //overload
72  const Parameters& operator=(const Parameters& params);
73 
74  //overload
75  void reset() throw( te::rp::Exception );
76 
77  //overload
78  AbstractParameters* clone() const;
79  };
80 
81  /*!
82  \class Pattern
83 
84  \brief Describes a region or a cluster (group of regions with similar properties) to be used by ISOSeg method.
85  */
87  {
88  public:
89 
90  Pattern();
91 
92  /*!
93  \brief Constructor.
94 
95  \param i The id of the initial region.
96  \param a The area of the region.
97  \param mv The vector of mean values, 1 value per band.
98  \param cm The covariance matrix between bands.
99  */
100  Pattern(int i, double a, std::vector<std::complex<double> > mv, boost::numeric::ublas::matrix<double> cm);
101 
102  /*!
103  \brief Copy constructor.
104 
105  \param rhs The right-hand-side copy that would be used to copy from.
106  */
107  Pattern(Pattern& rhs);
108 
109  ~Pattern();
110 
111  /*!
112  \brief Add a region inside a cluster.
113 
114  \param p The region to be added.
115  */
116  void add(Pattern* p);
117 
118  /*! \brief Returns the Mahalanobis distance between two patterns */
119  double getDistance(Pattern* p);
120 
121  /*! \brief Return true if two clusters are equal. */
122  bool operator=(Pattern& rhs);
123 
124  int m_id; //!< The id of the region of the pattern.
125  Pattern* m_myCluster; //!< The associated cluster of this pattern (optional).
126  double m_area; //!< The area of all regions inside a pattern.
127  std::vector<std::complex<double> > m_meanVector; //!< The vector of mean values, 1 value per band;
128  boost::numeric::ublas::matrix<double> m_covarianceMatrix; //!< The covariance matrix between bands.
129  boost::numeric::ublas::matrix<double> m_covarianceInversion; //!< The inversion of covariance matrix between bands.
130  };
131 
132  public:
133 
135 
137 
138  //overload
139  bool initialize(StrategyParameters const* const strategyParams) throw(te::rp::Exception);
140 
141  //overload
142  bool execute(const te::rst::Raster& inputRaster, const std::vector<unsigned int>& inputRasterBands,
143  const std::vector<te::gm::Polygon*>& inputPolygons, te::rst::Raster& outputRaster,
144  const unsigned int outputRasterBand, const bool enableProgressInterface) throw(te::rp::Exception);
145 
146  protected:
147 
148  bool m_isInitialized; //!< True if this instance is initialized.
149  ClassifierISOSegStrategy::Parameters m_parameters; //!< Internal execution parameters.
150  std::multimap<double, Pattern*, std::greater<double> > m_regions; //!< A descriptive set of regions (area, features).
151  };
152 
153  /*!
154  \class ClassifierISOSegStrategyFactory
155 
156  \brief Raster ISOSeg Classifier strategy factory.
157 
158  \note Factory key: RegionGrowing
159  */
161  {
162  public:
163 
165 
167 
168  //overload
170  };
171 
172  } // end namespace rp
173 } // end namespace te
174 
175 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERISOSEGSTRATEGY_H
double m_acceptanceThreshold
The acceptance threshold (the closer to 100%, few clusters are created).
double m_area
The area of all regions inside a pattern.
Raster strategy parameters base class.
Describes a region or a cluster (group of regions with similar properties) to be used by ISOSeg metho...
boost::numeric::ublas::matrix< double > m_covarianceMatrix
The covariance matrix between bands.
std::vector< std::complex< double > > m_meanVector
The vector of mean values, 1 value per band;.
Defines the exact sequence of characters that are acceptable.
Definition: Enums.h:102
Pattern * m_myCluster
The associated cluster of this pattern (optional).
Raster classifier strategy base class.
boost::numeric::ublas::matrix< double > m_covarianceInversion
The inversion of covariance matrix between bands.
Raster classifier strategy factory base class.
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.
int m_id
The id of the region of the pattern.
Configuration flags for the Raster Processing module of TerraLib.
ClassifierISOSegStrategy::Parameters m_parameters
Internal execution parameters.
An abstract class for raster data strucutures.
Definition: Raster.h:70
Raster ISOSeg Classifier strategy factory.
Raster classifier strategy base class.
Raster classifier strategy factory base class.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:91
ISOSeg strategy for OBIA classification. The algorithm orders regions by area (larger first)...