te::rp::ClassifierKMeansStrategy Class Reference

KMeans strategy for image classification. Step-by-step: More...

#include <ClassifierKMeansStrategy.h>

Inheritance diagram for te::rp::ClassifierKMeansStrategy:
te::rp::ClassifierStrategy

Classes

class  Parameters
 Classifier Parameters. More...
 

Public Member Functions

 ClassifierKMeansStrategy ()
 
void enableMultiThread (const bool &enable)
 Enable / disable the use of multiple threads. More...
 
void enableOutputPalette (const bool enabled)
 Enable (true) or disable (false) the creation of a paletted output raster. More...
 
void enableProgressInterface (const bool &enable)
 Enable / disable the progress interface. More...
 
void enableRasterCache (const bool &enable)
 Enable / disable the use of raster data cache. More...
 
bool execute () throw (te::rp::Exception)
 Executes the classification strategy. More...
 
const std::string & getErrorMessage () const
 Return the current error message if there is any. More...
 
void getMetaData (std::map< std::string, std::string > &metadata) const
 Returns strategy-dependent metadata. More...
 
bool initialize (ClassifierStrategyParameters const *const strategyParams) throw (te::rp::Exception)
 Initialize the classification strategy. More...
 
std::unique_ptr< te::rst::RasterreleaseOutputRaster ()
 Returns a pointer to the output raster or a void pointer if there is none. More...
 
void setInputPolygons (const std::vector< te::gm::Polygon * > &polygonsPtrs)
 Set the input polygons. More...
 
void setInputRaster (const te::rst::Raster &raster)
 Set the input raster. More...
 
void setInputRasterBands (const std::vector< unsigned int > &rasterBands)
 Set the input raste bandsr. More...
 
void setUserOutputPalette (std::vector< te::rst::BandProperty::ColorEntry > &userPalette)
 Set the output user palette. More...
 
 ~ClassifierKMeansStrategy ()
 

Protected Member Functions

bool createOutputRaster (const std::vector< int > &bandsDataTypes, const std::vector< double > &noDataValues)
 Create the output raster using the EXPANSIBLE driver. More...
 
virtual void reset ()
 Reset to an initial state. More...
 
void setErrorMessage (const std::string &newErrorMessage)
 Set the current error message. More...
 
bool setOutputRasterPalette (const unsigned int size)
 Create and set the output raster palette folowing the current internal settings. More...
 

Protected Attributes

bool m_createRasterPalette
 Enable (true) or disable (false) the creation of a paletted output raster. More...
 
bool m_enableMultiThread
 Enable or disable the use multipe threads. More...
 
bool m_enableRasterCache
 Enable or disable the use a raster data cache. More...
 
std::vector< te::gm::Polygon * > const * m_inputPolygonsPtr
 Input polygons. More...
 
std::vector< unsigned intm_inputRasterBands
 Input raster bands. More...
 
te::rst::Raster const * m_inputRasterPtr
 A pointer to the input raster. More...
 
bool m_isInitialized
 True if this instance is initialized. More...
 
std::map< std::string, std::string > m_metaData
 Strategy-dependent metadata. More...
 
std::unique_ptr< te::rst::Rasterm_outputRasterPtr
 A pointer to the output raster. More...
 
ClassifierKMeansStrategy::Parameters m_parameters
 Internal execution parameters. More...
 
bool m_progressInterfaceEnabled
 Progress interface status. More...
 
std::vector< te::rst::BandProperty::ColorEntrym_userOutputPalette
 User output raster palette (it must be large enough to accomodate all classifyier generated classes or an empty vector to automatically generate an random palette. More...
 

Detailed Description

KMeans strategy for image classification. Step-by-step:

  1. Define a random solution, creating K values of mean.
  2. Classify each pixel according to the closest mean.
  3. Calculate new means using the classified pixels.
  4. Go back to step 2, or stop depending on the following checks:
  5. Check if the new means are different from the previous iteration, using the convergence threshold.
  6. Check if maximum number of iterations has achieved.

Definition at line 52 of file ClassifierKMeansStrategy.h.

Constructor & Destructor Documentation

te::rp::ClassifierKMeansStrategy::ClassifierKMeansStrategy ( )

Definition at line 79 of file ClassifierKMeansStrategy.cpp.

References m_isInitialized, and ~ClassifierKMeansStrategy().

te::rp::ClassifierKMeansStrategy::~ClassifierKMeansStrategy ( )
default

Member Function Documentation

bool te::rp::ClassifierStrategy::createOutputRaster ( const std::vector< int > &  bandsDataTypes,
const std::vector< double > &  noDataValues 
)
protectedinherited
void te::rp::ClassifierStrategy::enableMultiThread ( const bool enable)
inherited

Enable / disable the use of multiple threads.

Parameters
enableEnable (true) or disable (false) the use of multiple threads.

Definition at line 80 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_enableMultiThread.

void te::rp::ClassifierStrategy::enableOutputPalette ( const bool  enabled)
inherited

Enable (true) or disable (false) the creation of a paletted output raster.

Parameters
enabledEnable (true) or disable (false) the creation of a paletted output raster.

Definition at line 90 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_createRasterPalette.

void te::rp::ClassifierStrategy::enableProgressInterface ( const bool enable)
inherited

Enable / disable the progress interface.

Parameters
enableEnable (true) or disable (false) the progress interface.

Definition at line 70 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_progressInterfaceEnabled.

void te::rp::ClassifierStrategy::enableRasterCache ( const bool enable)
inherited

Enable / disable the use of raster data cache.

Parameters
enableEnable (true) or disable (false) the use of raster cache.

Definition at line 75 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_enableRasterCache.

bool te::rp::ClassifierKMeansStrategy::execute ( )
throw (te::rp::Exception
)
virtual

Executes the classification strategy.

Returns
true if OK, false on errors.

Implements te::rp::ClassifierStrategy.

Definition at line 109 of file ClassifierKMeansStrategy.cpp.

References te::rst::RasterIterator< T >::begin(), te::rst::PointSetIterator< T >::begin(), te::cl::KMeans< TTRAIN, TCLASSIFY >::classify(), col, te::rp::ClassifierStrategy::createOutputRaster(), dt, te::rst::RasterIterator< T >::end(), te::rst::PointSetIterator< T >::end(), te::rst::Raster::getBand(), te::rst::RasterIterator< T >::getColumn(), te::rst::Raster::getNumberOfColumns(), te::rst::Raster::getNumberOfRows(), te::rst::Band::getProperty(), te::rst::GetRandomPointsInRaster(), te::rst::RasterIterator< T >::getRow(), te::rst::Band::getValue(), te::cl::KMeans< TTRAIN, TCLASSIFY >::initialize(), te::rp::ClassifierKMeansStrategy::Parameters::m_epsilon, te::rp::ClassifierStrategy::m_inputRasterBands, te::rp::ClassifierStrategy::m_inputRasterPtr, m_isInitialized, te::rp::ClassifierKMeansStrategy::Parameters::m_K, te::rp::ClassifierKMeansStrategy::Parameters::m_maxInputPoints, te::rp::ClassifierKMeansStrategy::Parameters::m_maxIterations, te::rst::BandProperty::m_noDataValue, te::rp::ClassifierStrategy::m_outputRasterPtr, m_parameters, te::common::TaskProgress::pulse(), te::common::TaskProgress::setCurrentStep(), te::common::TaskProgress::setMessage(), te::rp::ClassifierStrategy::setOutputRasterPalette(), te::common::TaskProgress::setTotalSteps(), te::rst::Band::setValue(), TE_TR, TERP_INSTANCE_TRUE_OR_RETURN_FALSE, te::cl::KMeans< TTRAIN, TCLASSIFY >::train(), and te::dt::UINT32_TYPE.

const std::string & te::rp::ClassifierStrategy::getErrorMessage ( ) const
inherited

Return the current error message if there is any.

Returns
Return the current error message if there is any.

Definition at line 100 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_errorMessage.

void te::rp::ClassifierStrategy::getMetaData ( std::map< std::string, std::string > &  metadata) const
inherited

Returns strategy-dependent metadata.

Parameters
metadataStrategy-dependent metadata.

Definition at line 85 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_metaData.

bool te::rp::ClassifierKMeansStrategy::initialize ( ClassifierStrategyParameters const *const  strategyParams)
throw (te::rp::Exception
)
virtual

Initialize the classification strategy.

Parameters
strategyParamsA pointer to the user given specific classification strategy parameters ou NULL if no parameters are present.
Returns
true if OK, false on errors.

Implements te::rp::ClassifierStrategy.

Definition at line 86 of file ClassifierKMeansStrategy.cpp.

References te::rp::ClassifierKMeansStrategy::Parameters::m_epsilon, m_isInitialized, te::rp::ClassifierKMeansStrategy::Parameters::m_K, te::rp::ClassifierKMeansStrategy::Parameters::m_maxInputPoints, te::rp::ClassifierKMeansStrategy::Parameters::m_maxIterations, m_parameters, TE_TR, and TERP_INSTANCE_TRUE_OR_RETURN_FALSE.

std::unique_ptr< te::rst::Raster > te::rp::ClassifierStrategy::releaseOutputRaster ( )
inherited

Returns a pointer to the output raster or a void pointer if there is none.

Returns
Returns a pointer to the output raster or a void pointer if there is none.
Note
The caller of this method must take the ownership of the returned object.

Definition at line 60 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_outputRasterPtr.

void te::rp::ClassifierStrategy::setErrorMessage ( const std::string &  newErrorMessage)
protectedinherited

Set the current error message.

Parameters
newErrorMessageNew error message;

Definition at line 180 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_errorMessage.

void te::rp::ClassifierStrategy::setInputPolygons ( const std::vector< te::gm::Polygon * > &  polygonsPtrs)
inherited

Set the input polygons.

Parameters
polygonsPtrsInput polygons pointers.
Note
The caller of this method must keep the ownership of the objects.

Definition at line 65 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_inputPolygonsPtr.

void te::rp::ClassifierStrategy::setInputRaster ( const te::rst::Raster raster)
inherited

Set the input raster.

Parameters
rasterInput raster.

Definition at line 50 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_inputRasterPtr.

void te::rp::ClassifierStrategy::setInputRasterBands ( const std::vector< unsigned int > &  rasterBands)
inherited

Set the input raste bandsr.

Parameters
rasterBandsInput raster bands.

Definition at line 55 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_inputRasterBands.

bool te::rp::ClassifierStrategy::setOutputRasterPalette ( const unsigned int  size)
protectedinherited
void te::rp::ClassifierStrategy::setUserOutputPalette ( std::vector< te::rst::BandProperty::ColorEntry > &  userPalette)
inherited

Set the output user palette.

Parameters
userPaletteUser output raster palette (it must be large enough to accomodate all classifyier generated classes or an empty vector to automatically generate an random palette.

Definition at line 95 of file ClassifierStrategy.cpp.

References te::rp::ClassifierStrategy::m_userOutputPalette.

Member Data Documentation

bool te::rp::ClassifierStrategy::m_createRasterPalette
protectedinherited

Enable (true) or disable (false) the creation of a paletted output raster.

Definition at line 164 of file ClassifierStrategy.h.

Referenced by te::rp::ClassifierStrategy::enableOutputPalette(), te::rp::ClassifierStrategy::reset(), and te::rp::ClassifierStrategy::setOutputRasterPalette().

bool te::rp::ClassifierStrategy::m_enableMultiThread
protectedinherited
bool te::rp::ClassifierStrategy::m_enableRasterCache
protectedinherited

Enable or disable the use a raster data cache.

Definition at line 154 of file ClassifierStrategy.h.

Referenced by te::rp::ClassifierStrategy::enableRasterCache(), te::rp::ClassifierISOSegStrategy::execute(), and te::rp::ClassifierStrategy::reset().

std::vector<te::gm::Polygon*> const* te::rp::ClassifierStrategy::m_inputPolygonsPtr
protectedinherited
bool te::rp::ClassifierKMeansStrategy::m_isInitialized
protected

True if this instance is initialized.

Definition at line 98 of file ClassifierKMeansStrategy.h.

Referenced by ClassifierKMeansStrategy(), execute(), and initialize().

std::map< std::string, std::string > te::rp::ClassifierStrategy::m_metaData
protectedinherited

Strategy-dependent metadata.

Definition at line 184 of file ClassifierStrategy.h.

Referenced by te::rp::ClassifierStrategy::getMetaData(), and te::rp::ClassifierStrategy::reset().

ClassifierKMeansStrategy::Parameters te::rp::ClassifierKMeansStrategy::m_parameters
protected

Internal execution parameters.

Definition at line 99 of file ClassifierKMeansStrategy.h.

Referenced by execute(), and initialize().

std::vector< te::rst::BandProperty::ColorEntry > te::rp::ClassifierStrategy::m_userOutputPalette
protectedinherited

User output raster palette (it must be large enough to accomodate all classifyier generated classes or an empty vector to automatically generate an random palette.

Definition at line 189 of file ClassifierStrategy.h.

Referenced by te::rp::ClassifierStrategy::reset(), te::rp::ClassifierStrategy::setOutputRasterPalette(), and te::rp::ClassifierStrategy::setUserOutputPalette().


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