All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
te::rp::SegmenterRegionGrowingStrategy Class Reference

Raster region growing segmenter strategy. More...

#include <SegmenterRegionGrowingStrategy.h>

Inheritance diagram for te::rp::SegmenterRegionGrowingStrategy:
te::rp::SegmenterStrategy

Classes

class  BaatzMerger
 Baatz based Segments merger. More...
 
class  MeanMerger
 Mean based Segments merger. More...
 
class  Merger
 Segments merger. More...
 
class  Parameters
 Segmenter Parameters. More...
 

Public Member Functions

bool execute (SegmenterIdsManager &segmenterIdsManager, const te::rp::SegmenterSegmentsBlock &block2ProcessInfo, const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< double > &inputRasterNoDataValues, const std::vector< double > &inputRasterBandMinValues, const std::vector< double > &inputRasterBandMaxValues, te::rst::Raster &outputRaster, const unsigned int outputRasterBand, const bool enableProgressInterface) throw ( te::rp::Exception )
 Executes the segmentation strategy over region delimited by the given block. More...
 
double getMemUsageEstimation (const unsigned int bandsToProcess, const unsigned int pixelsNumber) const
 Returns a memory estimation (bytes). More...
 
unsigned int getOptimalBlocksOverlapSize () const
 Returns a optimal blocks overlap size (number of border pixels overlapped between blocks, under one direction). More...
 
bool initialize (SegmenterStrategyParameters const *const strategyParams) throw ( te::rp::Exception )
 Initialize the segmentation strategy. More...
 
void reset ()
 Clear all internal allocated resources and go back to the initial not-initialized state. More...
 
 SegmenterRegionGrowingStrategy ()
 
 ~SegmenterRegionGrowingStrategy ()
 

Protected Types

typedef Matrix
< SegmenterSegmentsBlock::SegmentIdDataType
SegmentsIdsMatrixT
 Internal segments ids matrix type definition. More...
 

Protected Member Functions

void exportSegs2Tif (const SegmentsIdsMatrixT &segmentsIds, bool normto8bits, const std::string &fileName)
 Export the segments IDs to a tif file. More...
 
unsigned int getActiveSegmentsNumber (SegmenterRegionGrowingSegment *const actSegsListHeadPtr) const
 Returns the number of active segments. More...
 
bool initializeSegments (SegmenterIdsManager &segmenterIdsManager, const te::rp::SegmenterSegmentsBlock &block2ProcessInfo, const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< double > &inputRasterNoDataValues, const std::vector< double > &inputRasterBandMinValues, const std::vector< double > &inputRasterBandMaxValues, SegmenterRegionGrowingSegment **actSegsListHeadPtr)
 Initialize the segment objects container and the segment IDs container. More...
 
void mergeSegments (const SegmenterRegionGrowingSegment::FeatureType disimilarityThreshold, const unsigned int maxSegSizeThreshold, SegmenterIdsManager &segmenterIdsManager, Merger &merger, const bool enablelocalMutualBestFitting, const bool enableSameIterationMerges, SegmenterRegionGrowingSegment *auxSeg1Ptr, SegmenterRegionGrowingSegment *auxSeg2Ptr, SegmenterRegionGrowingSegment *auxSeg3Ptr, SegmenterRegionGrowingSegment::FeatureType &minFoundDissimilarity, SegmenterRegionGrowingSegment::FeatureType &maxFoundDissimilarity, unsigned int &totalMergesNumber, SegmenterRegionGrowingSegment::IterationCounterType &globalMergeIterationsCounter, SegmenterRegionGrowingSegment **const actSegsListHeadPtrPtr)
 Merge closest segments. More...
 

Static Protected Member Functions

static void getTouchingEdgeLength (const SegmentsIdsMatrixT &segsIds, const unsigned int &xStart, const unsigned int &yStart, const unsigned int &xBound, const unsigned int &yBound, const SegmenterSegmentsBlock::SegmentIdDataType &id1, const SegmenterSegmentsBlock::SegmentIdDataType &id2, unsigned int &edgeLength1, unsigned int &edgeLength2)
 Returns the count of points from region 1 (with ID1) touching the region 2 (with ID2). More...
 

Protected Attributes

bool m_isInitialized
 true if this instance is initialized. More...
 
SegmenterRegionGrowingStrategy::Parameters m_parameters
 Internal execution parameters. More...
 
SegmentsIdsMatrixT m_segmentsIdsMatrix
 A internal segments IDs matrix that can be reused on each strategy execution. More...
 
SegmenterRegionGrowingSegmentsPool m_segmentsPool
 A pool of segments that can be reused on each strategy execution. More...
 

Detailed Description

Raster region growing segmenter strategy.

Definition at line 50 of file SegmenterRegionGrowingStrategy.h.

Member Typedef Documentation

Internal segments ids matrix type definition.

Definition at line 154 of file SegmenterRegionGrowingStrategy.h.

Constructor & Destructor Documentation

te::rp::SegmenterRegionGrowingStrategy::~SegmenterRegionGrowingStrategy ( )

Definition at line 697 of file SegmenterRegionGrowingStrategy.cpp.

References reset().

te::rp::SegmenterRegionGrowingStrategy::SegmenterRegionGrowingStrategy ( )

Definition at line 692 of file SegmenterRegionGrowingStrategy.cpp.

References m_isInitialized.

Member Function Documentation

bool te::rp::SegmenterRegionGrowingStrategy::execute ( SegmenterIdsManager segmenterIdsManager,
const te::rp::SegmenterSegmentsBlock block2ProcessInfo,
const te::rst::Raster inputRaster,
const std::vector< unsigned int > &  inputRasterBands,
const std::vector< double > &  inputRasterNoDataValues,
const std::vector< double > &  inputRasterBandMinValues,
const std::vector< double > &  inputRasterBandMaxValues,
te::rst::Raster outputRaster,
const unsigned int  outputRasterBand,
const bool  enableProgressInterface 
)
throw (te::rp::Exception
)
virtual

Executes the segmentation strategy over region delimited by the given block.

Parameters
segmenterIdsManagerThe segments IDs manager to be used when acquiring/releaseing unique segment IDs.
block2ProcessInfoThe information about the block of raster that must be processed.
inputRasterInput raster.
inputRasterBandsInput raster bands.
inputRasterNoDataValuesA vector of values to be used as input raster no-data values.
inputRasterBandMinValuesThe minimum value present on each band.
inputRasterBandMinValuesThe maximum value present on each band.
outputRasterOutput raster.
outputRasterBandOutput raster band.
enableProgressInterfaceEnable the internal strategy to update the progress interface.
Returns
true if OK, false on errors.
Note
The used gaind/ofset calcule: new_value = ( old_value + offset ) * gain

Implements te::rp::SegmenterStrategy.

Definition at line 770 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::SegmenterRegionGrowingStrategy::Parameters::BaatzFeaturesType, te::rp::SegmenterRegionGrowingSegment::disable(), te::rp::Matrix< TemplateElementType >::getColumnsNumber(), te::rp::Matrix< TemplateElementType >::getLinesNumber(), te::rp::SegmenterRegionGrowingSegmentsPool::getNextSegment(), te::rp::SegmenterRegionGrowingSegmentsPool::initialize(), initializeSegments(), te::rp::SegmenterRegionGrowingStrategy::Parameters::m_bandsWeights, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_colorWeight, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_compactnessWeight, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_enableLocalMutualBestFitting, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_enableSameIterationMerges, m_isInitialized, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_minSegmentSize, m_parameters, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_segmentFeatures, m_segmentsIdsMatrix, m_segmentsPool, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_segmentsSimilarityThreshold, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_segmentsSimIncreaseSteps, te::rp::SegmenterRegionGrowingStrategy::Parameters::MeanFeaturesType, mergeSegments(), te::rp::Matrix< TemplateElementType >::reset(), TERP_LOG_AND_THROW, and TERP_TRUE_OR_RETURN_FALSE.

void te::rp::SegmenterRegionGrowingStrategy::exportSegs2Tif ( const SegmentsIdsMatrixT segmentsIds,
bool  normto8bits,
const std::string &  fileName 
)
protected

Export the segments IDs to a tif file.

Parameters
segmentsIdsThe output segment ids container.
normto8bitsIf true, a 8 bits file will be generated.
fileNameThe output tif file name.

Definition at line 1658 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::Matrix< TemplateElementType >::getColumnsNumber(), te::rp::Matrix< TemplateElementType >::getLinesNumber(), te::sa::Grid, te::rst::RasterFactory::make(), te::rst::Raster::setValue(), TERP_TRUE_OR_THROW, te::dt::UCHAR_TYPE, and te::dt::UINT32_TYPE.

unsigned int te::rp::SegmenterRegionGrowingStrategy::getActiveSegmentsNumber ( SegmenterRegionGrowingSegment *const  actSegsListHeadPtr) const
protected

Returns the number of active segments.

Parameters
actSegsListHeadPtrA pointer the the active segments list head.
Returns
Returns the number of active segments.

Definition at line 1816 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::SegmenterRegionGrowingSegment::m_nextActiveSegment.

double te::rp::SegmenterRegionGrowingStrategy::getMemUsageEstimation ( const unsigned int  bandsToProcess,
const unsigned int  pixelsNumber 
) const
virtual

Returns a memory estimation (bytes).

This parameter is used by the segmenter to guess the sub-image blocks size.

Parameters
bandsToProcessThe number of input raster bands that will be processed at the strategy execution time.
pixelsNumberThe number of pixels.
Returns
A positive memory use estimation.

Implements te::rp::SegmenterStrategy.

Definition at line 1030 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::SegmenterRegionGrowingStrategy::Parameters::BaatzFeaturesType, m_isInitialized, m_parameters, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_segmentFeatures, te::rp::SegmenterRegionGrowingStrategy::Parameters::MeanFeaturesType, TERP_LOG_AND_THROW, and TERP_TRUE_OR_THROW.

unsigned int te::rp::SegmenterRegionGrowingStrategy::getOptimalBlocksOverlapSize ( ) const
virtual

Returns a optimal blocks overlap size (number of border pixels overlapped between blocks, under one direction).

Note
This value will be used in the case where the image is splitted into blocks for segmentation.
Returns
The blocks overlap size.

Implements te::rp::SegmenterStrategy.

Definition at line 1109 of file SegmenterRegionGrowingStrategy.cpp.

References m_isInitialized, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_minSegmentSize, m_parameters, and TERP_TRUE_OR_THROW.

void te::rp::SegmenterRegionGrowingStrategy::getTouchingEdgeLength ( const SegmentsIdsMatrixT segsIds,
const unsigned int &  xStart,
const unsigned int &  yStart,
const unsigned int &  xBound,
const unsigned int &  yBound,
const SegmenterSegmentsBlock::SegmentIdDataType id1,
const SegmenterSegmentsBlock::SegmentIdDataType id2,
unsigned int &  edgeLength1,
unsigned int &  edgeLength2 
)
staticprotected

Returns the count of points from region 1 (with ID1) touching the region 2 (with ID2).

Parameters
segsIdsThe segment ids container.
xStartThe upper left X of the bounding box surrounding both regions.
yStartThe upper left Y of the bounding box surrounding both regions.
xBoundThe lower right X bound of the bounding box surrounding both regions.
yBoundThe lower right Y bound of the bounding box surrounding both regions.
id1Region 1 ID.
id2Region 2 ID.
edgeLength1The touching edge length for the region 1.
edgeLength2The touching edge length for the region 2.
Returns
Returns the count of points from region 1 (with ID1) touching the region 2 (with ID2).

Definition at line 1722 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::Matrix< TemplateElementType >::getColumnsNumber(), te::rp::Matrix< TemplateElementType >::getLinesNumber(), and TERP_DEBUG_TRUE_OR_THROW.

Referenced by te::rp::SegmenterRegionGrowingStrategy::BaatzMerger::getDissimilarity().

bool te::rp::SegmenterRegionGrowingStrategy::initialize ( SegmenterStrategyParameters const *const  strategyParams)
throw (te::rp::Exception
)
virtual
bool te::rp::SegmenterRegionGrowingStrategy::initializeSegments ( SegmenterIdsManager segmenterIdsManager,
const te::rp::SegmenterSegmentsBlock block2ProcessInfo,
const te::rst::Raster inputRaster,
const std::vector< unsigned int > &  inputRasterBands,
const std::vector< double > &  inputRasterNoDataValues,
const std::vector< double > &  inputRasterBandMinValues,
const std::vector< double > &  inputRasterBandMaxValues,
SegmenterRegionGrowingSegment **  actSegsListHeadPtr 
)
protected

Initialize the segment objects container and the segment IDs container.

Parameters
segmenterIdsManagerA segments ids manager to acquire unique segments ids.
block2ProcessInfoInfo about the block to process.
inputRasterThe input raster.
inputRasterBandsInput raster bands to use.
inputRasterNoDataValuesA vector of values to be used as input raster no-data values.
inputRasterBandMinValuesThe minimum value present on each band.
inputRasterBandMinValuesThe maximum value present on each band.
actSegsListHeadPtrA pointer the the active segments list head.
Returns
true if OK, false on errors.

Definition at line 1115 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::SegmenterIdsManager::addFreeIDs(), te::rp::SegmenterRegionGrowingSegment::addNeighborSegment(), BAATZ_CO, BAATZ_EL, BAATZ_SM, BAATZ_SS, BAATZ_ST, BAATZ_SU, te::rp::SegmenterRegionGrowingStrategy::Parameters::BaatzFeaturesType, te::rp::SegmenterRegionGrowingSegment::clearNeighborSegments(), te::rp::SegmenterIdsManager::getNewIDs(), te::rp::SegmenterRegionGrowingSegmentsPool::getNextSegment(), te::rst::Raster::getValue(), te::rp::SegmenterSegmentsBlock::m_bottomCutOffProfile, te::rp::SegmenterRegionGrowingSegment::m_features, te::rp::SegmenterSegmentsBlock::m_height, te::rp::SegmenterRegionGrowingSegment::m_id, te::rp::SegmenterSegmentsBlock::m_leftCutOffProfile, te::rp::SegmenterRegionGrowingSegment::m_mergetIteration, te::rp::SegmenterRegionGrowingSegment::m_nextActiveSegment, m_parameters, te::rp::SegmenterRegionGrowingSegment::m_prevActiveSegment, te::rp::SegmenterSegmentsBlock::m_rightCutOffProfile, te::rp::SegmenterRegionGrowingStrategy::Parameters::m_segmentFeatures, m_segmentsIdsMatrix, m_segmentsPool, te::rp::SegmenterRegionGrowingSegment::m_size, te::rp::SegmenterSegmentsBlock::m_startX, te::rp::SegmenterSegmentsBlock::m_startY, te::rp::SegmenterSegmentsBlock::m_topCutOffProfile, te::rp::SegmenterSegmentsBlock::m_width, te::rp::SegmenterRegionGrowingSegment::m_xBound, te::rp::SegmenterRegionGrowingSegment::m_xStart, te::rp::SegmenterRegionGrowingSegment::m_yBound, te::rp::SegmenterRegionGrowingSegment::m_yStart, te::rp::SegmenterRegionGrowingStrategy::Parameters::MeanFeaturesType, and TERP_LOG_AND_THROW.

Referenced by execute().

void te::rp::SegmenterRegionGrowingStrategy::mergeSegments ( const SegmenterRegionGrowingSegment::FeatureType  disimilarityThreshold,
const unsigned int  maxSegSizeThreshold,
SegmenterIdsManager segmenterIdsManager,
Merger merger,
const bool  enablelocalMutualBestFitting,
const bool  enableSameIterationMerges,
SegmenterRegionGrowingSegment auxSeg1Ptr,
SegmenterRegionGrowingSegment auxSeg2Ptr,
SegmenterRegionGrowingSegment auxSeg3Ptr,
SegmenterRegionGrowingSegment::FeatureType minFoundDissimilarity,
SegmenterRegionGrowingSegment::FeatureType maxFoundDissimilarity,
unsigned int &  totalMergesNumber,
SegmenterRegionGrowingSegment::IterationCounterType globalMergeIterationsCounter,
SegmenterRegionGrowingSegment **const  actSegsListHeadPtrPtr 
)
protected

Merge closest segments.

Parameters
disimilarityThresholdThe maximum similarity value allowed when deciding when to merge two segments.
maxSegSizeThresholdSegments with sizes smaller then this value will allways be merged with the closest segment (disimilarityThreshold will be ignored).
segmenterIdsManagerA segments ids manager to acquire unique segments ids.
mergerThe merger instance to use.
enablelocalMutualBestFittingIf enabled, a merge only occurs between two segments if the minimum dissimilarity criteria is best fulfilled mutually.
enableSameIterationMergesIf enabled, a merged segment could be merged with another under the same iteration.
auxSeg1PtrA pointer to a valid auxiliar segment that will be used by this method.
auxSeg2PtrA pointer to a valid auxiliar segment that will be used by this method.
auxSeg3PtrA pointer to a valid auxiliar segment that will be used by this method.
minFoundDissimilarityThe minimum dissimilarity value found.
maxFoundDissimilarityThe maximum dissimilarity value found.
totalMergesNumberThe total number of merges.
mergeIterationCounterA reference to a iteration number counter (this variable will be only incremented, never zeroed. It never must be reset. ).
actSegsListHeadPtrA pointer the the active segments list head.

Definition at line 1369 of file SegmenterRegionGrowingStrategy.cpp.

References te::rp::SegmenterIdsManager::addFreeIDs(), te::rp::SegmenterRegionGrowingSegment::addNeighborSegment(), te::rp::SegmenterRegionGrowingSegment::clearNeighborSegments(), te::rp::SegmenterRegionGrowingSegment::disable(), te::rp::SegmenterRegionGrowingStrategy::Merger::getDissimilarity(), te::rp::SegmenterRegionGrowingSegment::m_id, te::rp::SegmenterRegionGrowingSegment::m_mergetIteration, te::rp::SegmenterRegionGrowingSegment::m_neighborSegments, te::rp::SegmenterRegionGrowingSegment::m_neighborSegmentsSize, te::rp::SegmenterRegionGrowingSegment::m_nextActiveSegment, te::rp::SegmenterRegionGrowingSegment::m_prevActiveSegment, m_segmentsIdsMatrix, te::rp::SegmenterRegionGrowingSegment::m_size, te::rp::SegmenterRegionGrowingSegment::m_xBound, te::rp::SegmenterRegionGrowingSegment::m_xStart, te::rp::SegmenterRegionGrowingSegment::m_yBound, te::rp::SegmenterRegionGrowingSegment::m_yStart, te::rp::SegmenterRegionGrowingStrategy::Merger::mergeFeatures(), te::rp::SegmenterRegionGrowingSegment::removeNeighborSegment(), TERP_TRUE_OR_THROW, and te::rp::SegmenterRegionGrowingStrategy::Merger::update().

Referenced by execute().

Member Data Documentation

bool te::rp::SegmenterRegionGrowingStrategy::m_isInitialized
protected

true if this instance is initialized.

Definition at line 349 of file SegmenterRegionGrowingStrategy.h.

Referenced by execute(), getMemUsageEstimation(), getOptimalBlocksOverlapSize(), initialize(), reset(), and SegmenterRegionGrowingStrategy().

SegmenterRegionGrowingStrategy::Parameters te::rp::SegmenterRegionGrowingStrategy::m_parameters
protected

Internal execution parameters.

Definition at line 354 of file SegmenterRegionGrowingStrategy.h.

Referenced by execute(), getMemUsageEstimation(), getOptimalBlocksOverlapSize(), initialize(), initializeSegments(), and reset().

SegmentsIdsMatrixT te::rp::SegmenterRegionGrowingStrategy::m_segmentsIdsMatrix
protected

A internal segments IDs matrix that can be reused on each strategy execution.

Definition at line 360 of file SegmenterRegionGrowingStrategy.h.

Referenced by execute(), initializeSegments(), mergeSegments(), and reset().

SegmenterRegionGrowingSegmentsPool te::rp::SegmenterRegionGrowingStrategy::m_segmentsPool
protected

A pool of segments that can be reused on each strategy execution.

Definition at line 357 of file SegmenterRegionGrowingStrategy.h.

Referenced by execute(), initializeSegments(), and reset().


The documentation for this class was generated from the following files: