29 #include "../raster/RasterFactory.h" 30 #include "../raster/BandProperty.h" 31 #include "../raster/Grid.h" 32 #include "../raster/Band.h" 105 m_outputRasterPtr.reset();
141 std::vector<te::rst::BandProperty*> bandsProperties;
143 bandsProperties.push_back(bprop);
150 "Output raster creation error");
156 for (
unsigned int row = 0; row < (outputParamsPtr->
m_outputRasterPtr->getNumberOfRows() - 2); row++)
162 for (
int i = 0; i < 3; i++)
169 std::map<int, int> freq;
176 for (
int c = 0; c < 3; c++)
178 for (
int r = 0; r < 3; r++)
180 bout.
getValue(
col + static_cast<unsigned int>(c), row + static_cast<unsigned int>(r), pixels[c][r]);
182 if (pixels[c][r] == pixels[1][1])
188 std::map<int, int>::iterator itFreq = freq.find(static_cast<int>(pixels[c][r]));
190 if (itFreq != freq.end())
193 freq.insert(std::map<int, int>::value_type(static_cast<int>(pixels[c][r]), 1));
197 if (freq.size() == 0)
203 std::map<int, int>::iterator itFreq = freq.begin();
205 int bestClass = itFreq->first;
206 int bestFreq = itFreq->second;
209 while (itFreq != freq.end())
211 if (itFreq->second > bestFreq)
213 bestClass = itFreq->first;
214 bestFreq = itFreq->second;
221 itFreq = freq.begin();
222 while (itFreq != freq.end())
226 bestFreq = itFreq->second;
227 bestClass = itFreq->first;
260 TE_TR(
"Invalid raster pointer"));
263 TE_TR(
"Invalid raster"));
266 TE_TR(
"Invalid weight value"));
269 TE_TR(
"Invalid threshold value"));
284 unsigned int weight,
unsigned int threshold)
290 for (
unsigned int row = 0; row < (dstRaster.
getNumberOfRows() - 2); row++)
296 for (
int i = 0; i < 3; i++)
303 std::map<int, int> freq;
310 for (
int c = 0; c < 3; c++)
312 for (
int r = 0; r < 3; r++)
314 bout.
getValue(
col + static_cast<unsigned int>(c), row + static_cast<unsigned int>(r), pixels[c][r]);
316 if (pixels[c][r] == pixels[1][1])
322 std::map<int, int>::iterator itFreq = freq.find(static_cast<int>(pixels[c][r]));
324 if (itFreq != freq.end())
327 freq.insert(std::map<int, int>::value_type(static_cast<int>(pixels[c][r]), 1));
331 if (freq.size() == 0)
334 freqvcenter += weight - 1;
337 std::map<int, int>::iterator itFreq = freq.begin();
339 int bestClass = itFreq->first;
340 int bestFreq = itFreq->second;
343 while (itFreq != freq.end())
345 if (itFreq->second > bestFreq)
347 bestClass = itFreq->first;
348 bestFreq = itFreq->second;
355 itFreq = freq.begin();
356 while (itFreq != freq.end())
358 if ((itFreq->second > static_cast<int>(threshold)) && (itFreq->second > bestFreq))
360 bestFreq = itFreq->second;
361 bestClass = itFreq->first;
367 if ((bestFreq > static_cast<int>(threshold)) && (bestFreq > freqvcenter))
368 dstRaster.
setIValue(
col + 1, row + 1, static_cast<double>(bestClass));
PostClassification output parameters.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
bool m_isInitialized
Is this instance already initialized?
A raster band description.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another.
Raster Processing algorithm output parameters base interface.
virtual void setIValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the imaginary attribute value in a complex band of a cell.
#define TE_TR(message)
It marks a string in order to get translated.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
unsigned int m_weight
The weight value defines the number of times the frequency of the central point has to be considered...
AbstractParameters * clone() const
Create a clone copy of this instance.
PostClassification::InputParameters m_inputParameters
Input parameters.
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state...
unsigned int m_threshold
The threshold value is the frequency value above which the central point is modified.
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
BandProperty * getProperty()
Returns the band property.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
A raster band description.
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
Raster post classification.
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Abstract parameters base interface.
const OutputParameters & operator=(const OutputParameters ¶ms)
static Raster * make()
It creates and returns an empty raster with default raster driver.
AbstractParameters * clone() const
Create a clone copy of this instance.
bool runPostClassification(const te::rst::Raster &srcRaster, te::rst::Raster &dstRaster, unsigned int weight, unsigned int threshold)
Apply the post classification.
bool isInitialized() const
Returns true if the algorithm instance is initialized and ready for execution.
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
const InputParameters & operator=(const InputParameters ¶ms)
Raster Processing functions.
te::rst::Raster const * m_inRasterPtr
Input raster.
virtual void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
A rectified grid is the spatial support for raster data.
#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...
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state...
#define TERP_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.