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" 115 std::vector< int >
dt;
118 std::vector< double > noDataValues;
122 "Output raster creation error" );
125 "Output raster palette creation error" );
133 std::vector<unsigned int> classification;
152 if(!classifier.
initialize(classifierParameters))
172 unsigned int col = 0;
173 unsigned int row = 0;
174 double inputValue = 0;
176 while (rit != ritend)
181 inBand0.
getValue( col, row, inputValue );
183 if( inputValue == inNoDataValue )
185 outBand0.
setValue( col, row, outNoDataValue );
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.
Base exception class for plugin module.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
bool createOutputRaster(const std::vector< int > &bandsDataTypes, const std::vector< double > &noDataValues)
Create the output raster using the EXPANSIBLE driver.
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.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
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.
bool execute()
Executes the classification strategy.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
std::vector< unsigned int > m_inputRasterBands
Input raster bands.
void setTotalSteps(int value)
Set the task total stepes.
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.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
BandProperty * getProperty()
Returns the band property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
ClassifierKMeansStrategyFactory()
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer to the output raster.
bool m_isInitialized
True if this instance is initialized.
KMeans strategy for classification. Step-by-step:
Abstract parameters base interface.
te::rst::Raster const * m_inputRasterPtr
A pointer to the input raster.
void setCurrentStep(int value)
Set the task current step.
~ClassifierKMeansStrategy()
Classifier Strategy Parameters.
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.
Raster Processing functions.
AbstractParameters * clone() const
Create a clone copy of this instance.
#define TERP_INSTANCE_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged, the current instance erro...
bool setOutputRasterPalette(const unsigned int size)
Create and set the output raster palette folowing the current internal settings.
bool initialize(ClassifierStrategyParameters const *const strategyParams)
Initialize the classification strategy.
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:
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
bool train(TTRAIN &itBegin, TTRAIN &itEnd, const std::vector< unsigned int > &attributesIndices, const std::vector< unsigned int > &labels, const bool enableProgressInterface)
~ClassifierKMeansStrategyFactory()