27 #include "../classification/KMeans.h"
28 #include "../common/progress/TaskProgress.h"
29 #include "../geometry/Envelope.h"
30 #include "../raster/Grid.h"
31 #include "../raster/PositionIterator.h"
32 #include "../raster/RasterIterator.h"
33 #include "../raster/Utils.h"
114 const std::vector<te::gm::Polygon*>& inputPolygons,
te::rst::Raster& outputRaster,
115 const unsigned int outputRasterBand,
const bool enableProgressInterface)
throw(te::rp::Exception)
124 std::vector<unsigned int> classification;
138 if(!classifier.
initialize(classifierParameters))
140 if(!classifier.
train(pit, pitend, inputRasterBands, std::vector<unsigned int>(),
true))
142 if(!classifier.
classify(rit, ritend, inputRasterBands, classification,
true))
147 task.
setTotalSteps(inputRaster.getNumberOfColumns() * inputRaster.getNumberOfRows());
151 while (rit != ritend)
153 outputRaster.setValue(rit.
getColumn(), rit.
getRow(), classification[i], outputRasterBand);
bool execute(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< te::gm::Polygon * > &inputPolygons, te::rst::Raster &outputRaster, const unsigned int outputRasterBand, const bool enableProgressInterface)
Executes the classification strategy.
ClassifierKMeansStrategy::Parameters m_parameters
Internal execution parameters.
Raster KMeans Classifier strategy factory.
void setMessage(const std::string &message)
Set the task message.
bool initialize(const Parameters ¶ms)
unsigned int getRow() const
Returns the current row in iterator.
KMeans strategy for image classification.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
ClassifierKMeansStrategy()
This class implements and iterator to "navigate" over a raster, with a predefined number of bands...
This class can be used to inform the progress of a task.
bool classify(TCLASSIFY &itBegin, TCLASSIFY &itEnd, const std::vector< unsigned int > &attributesIndices, std::vector< unsigned int > &classification, const bool enableProgressInterface)
static PointSetIterator end(const te::rst::Raster *r, const std::vector< te::gm::Point * > p)
Returns an iterator referring to after the end of the iterator.
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
#define TE_TR(message)
It marks a string in order to get translated.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
Raster Processing functions.
void setTotalSteps(int value)
Set the task total stepes.
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
te::rp::ClassifierStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects...
Raster classifier strategy factory base class.
unsigned int m_K
The number of clusters (means) to detect in image.
const Parameters & operator=(const Parameters ¶ms)
An abstract class for raster data strucutures.
static RasterIterator begin(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to the first value.
Raster strategy parameters base class.
bool initialize(StrategyParameters const *const strategyParams)
Initialize the classification strategy.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
ClassifierKMeansStrategyFactory()
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
bool m_isInitialized
True if this instance is initialized.
KMeans strategy for classification. Step-by-step:
Abstract parameters base interface.
void setCurrentStep(int value)
Set the task current step.
~ClassifierKMeansStrategy()
Raster classifier strategy base class.
TERASTEREXPORT std::vector< te::gm::Point * > GetRandomPointsInRaster(const te::rst::Raster &inputRaster, unsigned int numberOfPoints=1000)
Creates a vector of random positions (points) inside the raster.
unsigned int m_maxIterations
The maximum of iterations to perform if convergence is not achieved.
static RasterIterator end(Raster *r, const std::vector< unsigned int > &bands)
Returns an iterator referring to after the end of the iterator.
unsigned int getColumn() const
Returns the current column in iterator.
AbstractParameters * clone() const
Create a clone copy of this instance.
static PointSetIterator begin(const te::rst::Raster *r, const std::vector< te::gm::Point * > p)
Returns an iterator referring to the first value of the band.
KMeans strategy for image classification. Step-by-step:
bool train(TTRAIN &itBegin, TTRAIN &itEnd, const std::vector< unsigned int > &attributesIndices, const std::vector< unsigned int > &labels, const bool enableProgressInterface)
~ClassifierKMeansStrategyFactory()