Loading...
Searching...
No Matches
Segmenter.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/Segmenter.h
22 \brief Raster segmentation.
23 */
24
25#ifndef __TERRALIB_RP_INTERNAL_SEGMENTER_H
26#define __TERRALIB_RP_INTERNAL_SEGMENTER_H
27
29#include "SegmenterStrategy.h"
31#include "SegmenterIdsManager.h"
32#include "Algorithm.h"
33#include "Matrix.h"
34#include "Config.h"
35#include "../raster/RasterSynchronizer.h"
36#include "../common/progress/TaskProgress.h"
37
38#include <vector>
39#include <string>
40#include <map>
41#include <memory>
42
43namespace te
44{
45 namespace da
46 {
47 class DataSource;
48 }
49
50 namespace rst
51 {
52 class Raster;
53 class Band;
54 }
55
56 namespace rp
57 {
58 /*!
59 \class Segmenter
60 \brief Raster segmentation.
61 \details Raster segmentation following the choosed segmentation
62 strategy.
63 \note The created label image will be written to the raster instance
64 pointed by m_outRasterPtr (in this case the output band must also be
65 passed by m_outRasterBand ); or written to a new raster instance created
66 inside the given data source pointed by m_outDataSourcePtr (in this case
67 the data set name must be supplied - m_outDataSetName ).
68 \sa te::rp::Segmenter::Parameters For detailed parameters description.
69 \sa te::rp::SegmenterStrategy For detailed parameters description.
70
71 \ingroup rp_seg
72 */
74 {
75 public:
76
77 /*!
78 \class InputParameters
79 \brief Segmenter Input Parameters
80 */
82 {
83 public:
84
85 te::rst::Raster const* m_inputRasterPtr; //!< Input raster.
86
87 std::vector< unsigned int > m_inputRasterBands; //!< Bands to be processed from the input raster.
88
89 std::vector< std::complex< double > > m_inputRasterNoDataValues; //!< A vector of values to be used as input raster no-data values or an empty vector indicating to use the default values from the input raster..
90
91 bool m_enableThreadedProcessing; //!< If true, threaded processing will be performed (best with multi-core or multi-processor systems (default:true).
92
93 unsigned int m_maxSegThreads; //!< The maximum number of concurrent segmenter threads (default:0 - automatically found).
94
95 bool m_enableBlockProcessing; //!< If true, the original raster will be splitted into small blocks, each one will be segmented independently and the result will be merged (if possible) at the end (default:true).
96
97 unsigned int m_maxBlockSize; //!< The input image will be split into blocks with this width for processing, this parameter tells the maximum block lateral size (width or height), the default: 0 - the size will be defined following the current system resources and physical processors number).
98
99 unsigned char m_blocksOverlapPercent; //!< The percentage of blocks overlapped area (valid range:0-25, defaul:5).
100
101 std::string m_strategyName; //!< The segmenter strategy name see each te::rp::SegmenterStrategyFactory inherited classes documentation for reference (default:RegionGrowingMean).
102
103 bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
104
105 bool m_enableRasterCache; //!< Enable/Disable the use of raster data cache (default:true).
106
108
110
112
113 /*!
114 \brief Set specific segmenter strategy parameters.
115 \param params The specific segmenter strategy parameters.
116 */
118 const SegmenterStrategyParameters& segStratParams );
119
120 /*!
121 \brief Returns a pointer to the internal specific segmenter strategy parameters.
122 \return A pointer to the internal specific segmenter strategy parameters, or
123 null if no parameters are present.
124 */
126
127 //overload
128 void reset() ;
129
130 //overload
132
133 //overload
134 AbstractParameters* clone() const;
135
136 //overload
137 bool serialize ( AlgorithmParametersSerializer& serializer ) const;
138
139 protected :
140
141 /*!
142 \brief A pointer to the internal specific segmenter strategy parameters or
143 NULL if no parameters are present.
144 */
145 std::unique_ptr< SegmenterStrategyParameters > m_segStratParamsPtr;
146 };
147
148 /*!
149 \class OutputParameters
150 \brief Segmenter Output Parameters
151 */
153 {
154 public:
155
156 std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
157
158 std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the raster (as described in te::raster::RasterFactory).
159
160 std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< A pointer the ge generated output raster (label image).
161
163
165
167
168 //overload
169 void reset() ;
170
171 //overload
173
174 //overload
175 AbstractParameters* clone() const;
176 };
177
179
181
182 //overload
183 bool execute( AlgorithmOutputParameters& outputParams ) ;
184
185 //overload
186 void reset() ;
187
188 //overload
189 bool initialize( const AlgorithmInputParameters& inputParams ) ;
190
191 bool isInitialized() const;
192
193 protected :
194
195 /*! Segments blocks matrix type definition */
197
198 /*!
199 \brief The parameters passed to the Segmenter::segmenterthreadEntry method.
200 */
202 {
203 public :
204 //! The global segmenter input execution parameters.
206
207 //! A pointer to the global segmenter input execution parameters (default:0).
209
210 //! Pointer to the segments blocks matrix (default:0).
212
213 //! Pointer to a general global mutex (default:0).
214 boost::mutex* m_generalMutexPtr;
215
216 //! Pointer to the input raster synchronizer (default:0).
218
219 //! Pointer to the output raster synchronizer (default:0).
221
222 //! Pointer to the mutex used by the block processed signal (default:0).
224
225 //! Pointer to the abort segmentation flag (default:0).
227
228 //! Pointer to the segments Ids manager - (default 0).
230
231 //! Pointer to a signal to be emited when a segments block was processed (default:0).
232 boost::condition_variable* m_blockProcessedSignalPtr;
233
234 //! Pointer to the running threads counter - default 0).
235 unsigned int volatile* m_runningThreadsCounterPtr;
236
237 //! A vector of input raster bands minimum values.
238 std::vector< std::complex< double > > m_inputRasterBandMinValues;
239
240 //! A vector of input raster bands maximum values.
241 std::vector< std::complex< double > > m_inputRasterBandMaxValues;
242
243 //! A vector of values to be used as input raster no-data values.
244 std::vector< std::complex< double > > m_inputRasterNoDataValues;
245
246 //! Enable/Disable the segmentation strategy to use its own progress interface (default:false).
248
249 //! The maximum number of input raster cached blocks per-thread.
251
252 //! A pointer to a string where the thread error message will be stored.
254
256
258 };
259
260 bool m_instanceInitialized; //"< Is this instance already initialized ?
261
262 Segmenter::InputParameters m_inputParameters; //!< Segmenter execution parameters.
263
264 /*!
265 \brief Calc the best sub-image block size for each thread to
266 process.
267 \param minBlockPixels The minimun allowed pixels number for each block (expanded block).
268 \param maxBlockPixels The maximum allowed pixels number for each block (expanded block).
269 \param blocksHOverlapSize The blocks horizontal overlap size (number of columns).
270 \param blocksVOverlapSize The blocks vertical overlap size (number of rows).
271 \param nonExpandedBlockWidth The calculated non-expanded block width (non-expanded block).
272 \param nonExpandedBlockHeight The calculated non-expanded block height (non-expanded block).
273 \param expandedBlockWidth The calculated expanded block width (non-expanded block).
274 \param expandedBlockHeight The calculated expanded block height (non-expanded block).
275 \return true if OK, false on errors.
276 */
278 const unsigned int minExapandedBlockPixels,
279 const unsigned int maxExapandedBlockPixels,
280 unsigned int& blocksHOverlapSize,
281 unsigned int& blocksVOverlapSize,
282 unsigned int& nonExpandedBlockWidth,
283 unsigned int& nonExpandedBlockHeight,
284 unsigned int& expandedBlockWidth,
285 unsigned int& expandedBlockHeight ) const;
286
287 /*!
288 \brief Segmenter thread entry.
289 \param paramsPtr A pointer to the segmenter thread parameters.
290 */
292
293 /*!
294 \brief Generate the horizontal cutOff prifles for the entire image..
295 \param profileCenter The profile center line.
296 \param inRaster The input raster.
297 \param inRasterBands The input raster bands.
298 \param pixelNeighborhoodSize The pixel neighborhood size over the line transverse to each tile line.
299 \param tileNeighborhoodSize The buffer size around each tile.
300 \param profileAntiSmoothingFactor A positive profile anti-smoothing factor.
301 \param profile The generated profile (each element is a inRaster line index ).
302 \return true if OK, false on errors.
303 */
304 bool genImageHCutOffProfile( const unsigned int profileCenter,
305 const te::rst::Raster& inRaster,
306 const std::vector< unsigned int >& inRasterBands,
307 const unsigned int pixelNeighborhoodSize,
308 const unsigned int tileNeighborhoodSize,
309 const unsigned int profileAntiSmoothingFactor,
310 std::vector< unsigned int>& profile ) const;
311
312 /*!
313 \brief Generate the vertical cutOff prifles for the entire image..
314 \param profileCenter The profile center column.
315 \param inRaster The input raster.
316 \param inRasterBands The input raster bands.
317 \param pixelNeighborhoodSize The pixel neighborhood size over the line transverse to each tile line.
318 \param tileNeighborhoodSize The buffer size around each tile.
319 \param profileAntiSmoothingFactor A positive profile anti-smoothing factor.
320 \param profile The generated profile (each element is a inRaster column index )
321 \return true if OK, false on errors.
322 */
323 bool genImageVCutOffProfile( const unsigned int profileCenter,
324 const te::rst::Raster& inRaster,
325 const std::vector< unsigned int >& inRasterBands,
326 const unsigned int pixelNeighborhoodSize,
327 const unsigned int tileNeighborhoodSize,
328 const unsigned int profileAntiSmoothingFactor,
329 std::vector< unsigned int>& profile ) const;
330
331 /*!
332 \brief Update the block cutOff profiles using the full image profiles.
333 \param imageVerticalProfiles The generated horizontal profiles (empty profiles also will be accepted).
334 \param horizontalProfiles The generated vertical profiles (empty profiles also will be accepted).
335 \param segmentsBlock The block to update.
336 \return true if OK, false on errors.
337 */
339 const std::vector< std::vector< unsigned int> >& imageHorizontalProfiles,
340 const std::vector< std::vector< unsigned int> >& imageVerticalProfiles,
341 SegmenterSegmentsBlock& segmentsBlock ) const;
342
344 const std::vector< std::vector< unsigned int> >& imageHorizontalProfiles,
345 const std::vector< unsigned int >& imageHorizontalProfilesCenterLines,
346 const std::vector< std::vector< unsigned int> >& imageVerticalProfiles,
347 const std::vector< unsigned int >& imageVerticalProfilesCenterLines,
348 const std::string& filename );
349 };
350
351 } // end namespace rp
352} // end namespace te
353
354#endif
355
Generic template matrix.
Segments IDs manager.
Raster segmenter strategy parameters base class.
Raster segmenter strategy base class.
Raster Processing algorithm input parameters base interface.
Raster Processing algorithm output parameters base interface.
A class to standardize algorithm parameters serialization.
Raster Processing algorithm base interface.
Definition: Algorithm.h:42
A generic template matrix.
Definition: Matrix.h:55
Segmenter segments IDs manager.
Segmenter segments block description class.
Segmenter Input Parameters.
Definition: Segmenter.h:82
unsigned int m_maxBlockSize
The input image will be split into blocks with this width for processing, this parameter tells the ma...
Definition: Segmenter.h:97
std::vector< std::complex< double > > m_inputRasterNoDataValues
A vector of values to be used as input raster no-data values or an empty vector indicating to use the...
Definition: Segmenter.h:89
SegmenterStrategyParameters const * getSegStrategyParams() const
Returns a pointer to the internal specific segmenter strategy parameters.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Segmenter.h:103
std::string m_strategyName
The segmenter strategy name see each te::rp::SegmenterStrategyFactory inherited classes documentation...
Definition: Segmenter.h:101
bool serialize(AlgorithmParametersSerializer &serializer) const
Returns a parameter serialization object.
const Segmenter::InputParameters & operator=(const Segmenter::InputParameters &params)
bool m_enableRasterCache
Enable/Disable the use of raster data cache (default:true).
Definition: Segmenter.h:105
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
Definition: Segmenter.h:87
void setSegStrategyParams(const SegmenterStrategyParameters &segStratParams)
Set specific segmenter strategy parameters.
unsigned int m_maxSegThreads
The maximum number of concurrent segmenter threads (default:0 - automatically found).
Definition: Segmenter.h:93
AbstractParameters * clone() const
Create a clone copy of this instance.
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
Definition: Segmenter.h:91
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Segmenter.h:85
InputParameters(const InputParameters &other)
unsigned char m_blocksOverlapPercent
The percentage of blocks overlapped area (valid range:0-25, defaul:5).
Definition: Segmenter.h:99
bool m_enableBlockProcessing
If true, the original raster will be splitted into small blocks, each one will be segmented independe...
Definition: Segmenter.h:95
std::unique_ptr< SegmenterStrategyParameters > m_segStratParamsPtr
A pointer to the internal specific segmenter strategy parameters or NULL if no parameters are present...
Definition: Segmenter.h:145
Segmenter Output Parameters.
Definition: Segmenter.h:153
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
Definition: Segmenter.h:160
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
const Segmenter::OutputParameters & operator=(const Segmenter::OutputParameters &params)
OutputParameters(const OutputParameters &other)
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Segmenter.h:156
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: Segmenter.h:158
AbstractParameters * clone() const
Create a clone copy of this instance.
The parameters passed to the Segmenter::segmenterthreadEntry method.
Definition: Segmenter.h:202
std::vector< std::complex< double > > m_inputRasterBandMaxValues
A vector of input raster bands maximum values.
Definition: Segmenter.h:241
boost::mutex * m_generalMutexPtr
Pointer to a general global mutex (default:0).
Definition: Segmenter.h:214
SegmenterIdsManager * m_segmentsIdsManagerPtr
Pointer to the segments Ids manager - (default 0).
Definition: Segmenter.h:229
bool volatile * m_abortSegmentationFlagPtr
Pointer to the abort segmentation flag (default:0).
Definition: Segmenter.h:226
te::rst::RasterSynchronizer * m_outputRasterSyncPtr
Pointer to the output raster synchronizer (default:0).
Definition: Segmenter.h:220
unsigned int m_maxInputRasterCachedBlocks
The maximum number of input raster cached blocks per-thread.
Definition: Segmenter.h:250
bool m_enableStrategyProgress
Enable/Disable the segmentation strategy to use its own progress interface (default:false).
Definition: Segmenter.h:247
boost::mutex * m_blockProcessedSignalMutexPtr
Pointer to the mutex used by the block processed signal (default:0).
Definition: Segmenter.h:223
boost::condition_variable * m_blockProcessedSignalPtr
Pointer to a signal to be emited when a segments block was processed (default:0).
Definition: Segmenter.h:232
te::rst::RasterSynchronizer * m_inputRasterSyncPtr
Pointer to the input raster synchronizer (default:0).
Definition: Segmenter.h:217
unsigned int volatile * m_runningThreadsCounterPtr
Pointer to the running threads counter - default 0).
Definition: Segmenter.h:235
Segmenter::InputParameters m_inputParameters
The global segmenter input execution parameters.
Definition: Segmenter.h:205
std::vector< std::complex< double > > m_inputRasterNoDataValues
A vector of values to be used as input raster no-data values.
Definition: Segmenter.h:244
std::string * m_threadErrorMessagePtr
A pointer to a string where the thread error message will be stored.
Definition: Segmenter.h:253
Segmenter::OutputParameters * m_outputParametersPtr
A pointer to the global segmenter input execution parameters (default:0).
Definition: Segmenter.h:208
SegmentsBlocksMatrixT * m_segsBlocksMatrixPtr
Pointer to the segments blocks matrix (default:0).
Definition: Segmenter.h:211
std::vector< std::complex< double > > m_inputRasterBandMinValues
A vector of input raster bands minimum values.
Definition: Segmenter.h:238
Raster segmentation.
Definition: Segmenter.h:74
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
bool genImageVCutOffProfile(const unsigned int profileCenter, const te::rst::Raster &inRaster, const std::vector< unsigned int > &inRasterBands, const unsigned int pixelNeighborhoodSize, const unsigned int tileNeighborhoodSize, const unsigned int profileAntiSmoothingFactor, std::vector< unsigned int > &profile) const
Generate the vertical cutOff prifles for the entire image..
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
bool createCutOffLinesTiff(const std::vector< std::vector< unsigned int > > &imageHorizontalProfiles, const std::vector< unsigned int > &imageHorizontalProfilesCenterLines, const std::vector< std::vector< unsigned int > > &imageVerticalProfiles, const std::vector< unsigned int > &imageVerticalProfilesCenterLines, const std::string &filename)
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
bool genImageHCutOffProfile(const unsigned int profileCenter, const te::rst::Raster &inRaster, const std::vector< unsigned int > &inRasterBands, const unsigned int pixelNeighborhoodSize, const unsigned int tileNeighborhoodSize, const unsigned int profileAntiSmoothingFactor, std::vector< unsigned int > &profile) const
Generate the horizontal cutOff prifles for the entire image..
static void segmenterThreadEntry(SegmenterThreadEntryParams *paramsPtr)
Segmenter thread entry.
Segmenter::InputParameters m_inputParameters
Segmenter execution parameters.
Definition: Segmenter.h:262
te::rp::Matrix< SegmenterSegmentsBlock > SegmentsBlocksMatrixT
Definition: Segmenter.h:196
bool calcBestBlockSize(const unsigned int minExapandedBlockPixels, const unsigned int maxExapandedBlockPixels, unsigned int &blocksHOverlapSize, unsigned int &blocksVOverlapSize, unsigned int &nonExpandedBlockWidth, unsigned int &nonExpandedBlockHeight, unsigned int &expandedBlockWidth, unsigned int &expandedBlockHeight) const
Calc the best sub-image block size for each thread to process.
bool updateBlockCutOffProfiles(const std::vector< std::vector< unsigned int > > &imageHorizontalProfiles, const std::vector< std::vector< unsigned int > > &imageVerticalProfiles, SegmenterSegmentsBlock &segmentsBlock) const
Update the block cutOff profiles using the full image profiles.
bool m_instanceInitialized
Definition: Segmenter.h:260
An access synchronizer to be used in SynchronizedRaster raster instances.
An abstract class for raster data strucutures.
Definition: Raster.h:72
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Proxy configuration file for TerraView (see terraview_config.h).
Abstract algorithm.