SegmenterRegionGrowingBaatzStrategy.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 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/SegmenterRegionGrowingBaatzStrategy.h
22  \brief Raster region growing segmenter Baatz strategy.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_SEGMENTERREGIONGROWINGBAATZSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_SEGMENTERREGIONGROWINGBAATZSTRATEGY_H
27 
29 #include "SegmenterStrategy.h"
34 #include "SegmenterSegmentsBlock.h"
36 #include "Matrix.h"
37 #include "Config.h"
38 
39 #include <vector>
40 #include <list>
41 #include <set>
42 
43 namespace te
44 {
45  namespace rp
46  {
47  /*!
48  \class SegmenterRegionGrowingBaatzStrategy
49  \brief Raster region growing segmenter strategy.
50  \ingroup rp_seg
51  */
53  {
54  public :
55  /*!
56  \class Parameters
57  \brief Segmenter Parameters
58  */
60  {
61  public:
62  /**
63  * \name Global parameters
64  */
65  /**@{*/
66 
67  unsigned int m_minSegmentSize; //!< A positive minimum segment size (pixels number - default: 100).
68 
69  double m_segmentsSimilarityThreshold; //!< Segments similarity treshold - Use lower values to merge only those segments that are more similar - Higher values will allow more segments to be merged - valid values range: positive values - default: 0.03 ).
70 
71  unsigned int m_segmentsSimIncreaseSteps; //!< The maximum number of steps to increment the similarity threshold value for the cases where no segment merge occurred - zero will disable segment similarity threshold increments - defaul: 2.
72 
73  bool m_enableLocalMutualBestFitting; //!< If enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fulfilled mutually (default: false).
74 
75  bool m_enableSameIterationMerges; //!< If enabled, a merged segment could be merged with another within the same iteration (default:false).
76 
77  //@}
78 
79  /**
80  * \name Baatz specific parameters
81  */
82  /**@{*/
83 
84  std::vector< double > m_bandsWeights; //!< The weight given to each band, when applicable (note: the bands weights sum must always be 1) or an empty vector indicating that all bands have the same weight.
85 
86  double m_colorWeight; //!< The weight given to the color component, deafult:0.9, valid range: [0,1].
87 
88  double m_compactnessWeight; //!< The weight given to the compactness component, deafult:0.5, valid range: [0,1].
89 
90  //@}
91 
92  Parameters();
93 
94  ~Parameters();
95 
96  //overload
97  const Parameters& operator=( const Parameters& params );
98 
99  //overload
100  void reset() throw( te::rp::Exception );
101 
102  //overload
103  AbstractParameters* clone() const;
104  };
105 
107 
109 
110  //overload
111  bool initialize( SegmenterStrategyParameters const* const strategyParams )
112  throw( te::rp::Exception );
113 
114  //overload
115  void reset();
116 
117  //overload
118  bool execute(
119  SegmenterIdsManager& segmenterIdsManager,
120  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
121  const te::rst::Raster& inputRaster,
122  const std::vector< unsigned int >& inputRasterBands,
123  const std::vector< std::complex< double > >& inputRasterNoDataValues,
124  const std::vector< std::complex< double > >& inputRasterBandMinValues,
125  const std::vector< std::complex< double > >& inputRasterBandMaxValues,
126  te::rst::Raster& outputRaster,
127  const unsigned int outputRasterBand,
128  const bool enableProgressInterface ) throw( te::rp::Exception );
129 
130  //overload
131  double getMemUsageEstimation( const unsigned int bandsToProcess,
132  const unsigned int pixelsNumber ) const;
133 
134  //overload
135  unsigned int getOptimalBlocksOverlapSize() const;
136 
137  //overload
138  bool shouldComputeMinMaxValues() const;
139 
140  //overload
141  BlocksMergingMethod getBlocksMergingMethod() const;
142 
143  protected :
144  /*!
145  \brief Internal segments ids matrix type definition.
146  */
147  typedef Matrix< SegmenterSegmentsBlock::SegmentIdDataType >
149 
150  /*!
151  \brief true if this instance is initialized.
152  */
153  bool m_isInitialized;
154 
155  /*!
156  \brief Internal execution parameters.
157  */
159 
160  /*! \brief A pool of segments that can be reused on each strategy execution. */
162 
163  /*! \brief A internal segments IDs matrix that can be reused on each strategy execution. */
164  SegmentsIdsMatrixT m_segmentsIdsMatrix;
165 
166  /*!
167  \brief Initialize the segment objects container and the segment IDs container.
168  \param segmenterIdsManager A segments ids manager to acquire unique segments ids.
169  \param block2ProcessInfo Info about the block to process.
170  \param inputRaster The input raster.
171  \param inputRasterBands Input raster bands to use.
172  \param inputRasterNoDataValues A vector of values to be used as input raster no-data values.
173  \param inputRasterBandMinValues The minimum value present on each band.
174  \param inputRasterBandMinValues The maximum value present on each band.
175  \param actSegsListHeadPtr A pointer the the active segments list head.
176  \return true if OK, false on errors.
177  */
178  bool initializeSegments( SegmenterIdsManager& segmenterIdsManager,
179  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
180  const te::rst::Raster& inputRaster,
181  const std::vector< unsigned int >& inputRasterBands,
182  const std::vector< std::complex< double > >& inputRasterNoDataValues,
183  const std::vector< std::complex< double > >& inputRasterBandMinValues,
184  const std::vector< std::complex< double > >& inputRasterBandMaxValues,
185  SegmenterRegionGrowingSegment< rg::BaatzFeatureType >** actSegsListHeadPtr );
186  };
187 
188  /*!
189  \class SegmenterRegionGrowingBaatzStrategyFactory
190  \brief Raster region growing segmenter strategy factory.
191  \note Factory key: RegionGrowingBaatz
192  */
195  {
196  public:
197 
199 
201 
202  //overload
203  te::rp::SegmenterStrategy* build();
204 
205  };
206 
207  } // end namespace rp
208 } // end namespace te
209 
210 #endif // __TERRALIB_RP_INTERNAL_SEGMENTERREGIONGROWINGBAATZSTRATEGY_H
Segmenter segments IDs manager.
Raster segmenter strategy factory base class.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
Base exception class for plugin module.
Definition: Exception.h:42
std::vector< double > m_bandsWeights
The weight given to each band, when applicable (note: the bands weights sum must always be 1) or an e...
double m_compactnessWeight
The weight given to the compactness component, deafult:0.5, valid range: [0,1].
float BaatzFeatureType
Baatz Strategy feature type.
double m_colorWeight
The weight given to the color component, deafult:0.9, valid range: [0,1].
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
Segmenter merger used in region growing process.
bool m_enableSameIterationMerges
If enabled, a merged segment could be merged with another within the same iteration (default:false)...
Raster segmenter strategy factory base class.
Region Growing segment.
URI C++ Library.
Raster segmenter strategy base class.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
unsigned int m_segmentsSimIncreaseSteps
The maximum number of steps to increment the similarity threshold value for the cases where no segmen...
Generic template matrix.
Raster segmenter strategy base class.
Configuration flags for the Raster Processing module of TerraLib.
Segments block.
Raster segmenter strategy parameters base class.
A generic template matrix.
Definition: Matrix.h:54
BlocksMergingMethod
Blocks merging method.
Segmenter segments block description class.
bool m_enableLocalMutualBestFitting
If enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fu...
Raster region growing segmenter strategy factory.