27 #include "../common/progress/TaskProgress.h" 
   28 #include "../geometry.h" 
   29 #include "../raster/Band.h" 
   30 #include "../raster/BandIterator.h" 
   31 #include "../raster/Grid.h" 
   32 #include "../raster/PositionIterator.h" 
   33 #include "../raster/Raster.h" 
   34 #include "../raster/Utils.h" 
   35 #include "../statistics.h" 
   67   std::vector<double> dvalues = getValuesFromBand(raster, band, polygon);
 
   68   std::vector<std::complex<double> > values;
 
   70   for (
unsigned int i = 0; i < dvalues.size(); i++)
 
   71     values.push_back(dvalues[i]);
 
   80   std::vector<double> values;
 
   89     values.push_back((*it)[band]);
 
   99   std::vector<std::vector<double> > dallvalues = getValuesFromRaster(raster, polygon, bands);
 
  100   std::vector<std::complex<double> > values;
 
  101   std::vector<std::vector<std::complex<double> > > allvalues;
 
  103   for (
unsigned int i = 0; i < dallvalues.size(); i++)
 
  106     for (
unsigned int j = 0; j < dallvalues[i].size(); j++)
 
  107       values.push_back(dallvalues[i][j]);
 
  108     allvalues.push_back(values);
 
  116   assert(bands.size() > 0);
 
  119   std::vector<std::vector<double> > allvalues;
 
  126   for (
unsigned int i = 0; i < bands.size(); i++)
 
  127     allvalues.push_back(std::vector<double> ());
 
  130     for (
unsigned int i = 0; i < bands.size(); i++)
 
  133       allvalues[i].push_back(value);
 
  144   assert(pixels.size() > 0);
 
  154   for (
unsigned int i = 0; i < vpixels.size(); i++)
 
  155     assert(vpixels[i].size() > 0);
 
  156   for (
unsigned int i = 1; i < vpixels.size(); i++)
 
  157     assert(vpixels[0].size() == vpixels[i].size());
 
  158   assert(vpixels.size() == vmeans.size());
 
  163   unsigned int nbands = vpixels.size();
 
  164   unsigned int nvalues = vpixels[0].size();
 
  166   boost::numeric::ublas::matrix<double> covariance(nbands, nbands);
 
  171     for (i = 0; i < nbands; i++)
 
  173       for (j = 0; j < nbands; j++)
 
  174         covariance(i, j) = 0.0;
 
  175       covariance(i, i) = 1000.0;
 
  183   std::complex<double> sum;
 
  184   for (i = 0; i < nbands; i++)
 
  185     for (j = 0; j < nbands; j++)
 
  187       taskProgress.
pulse();
 
  189       sum = std::complex<double> (0.0, 0.0);
 
  191       for (k = 0; k < nvalues; k++)
 
  192         sum += (vpixels[i][k] - vmeans[i]) * (vpixels[j][k] - vmeans[j]);
 
  194       covariance(i, j) = sum.real() / (nvalues - 1);
 
  208   boost::numeric::ublas::matrix<double> glcm (maxPixel + 1, maxPixel + 1);
 
  211   double neighborPixel;
 
  218   int column_start = 0;
 
  233   for (
int r = row_start; r < row_end; r++)
 
  235     for (
int c = column_start; c < column_end; c++)
 
  237       taskProgress.
pulse();
 
  241       if (pixel == noDataValue)
 
  245       rin.
getValue(c + dx, r + dy, neighborPixel, band);
 
  246       if (neighborPixel == noDataValue)
 
  250       glcm(pixel, neighborPixel) = glcm(pixel, neighborPixel) + 1;
 
  257     for (
unsigned int i = 0; i < glcm.size1(); i++)
 
  258       for (
unsigned int j = 0; j < glcm.size2(); j++)
 
  259         glcm(i, j) = glcm(i, j) / N;
 
  268   std::map<std::string, std::string> rcropinfo;
 
  269   rcropinfo[
"FORCE_MEM_DRIVER"] = 
"TRUE";
 
  273   return getGLCM(*rcrop.get(), band, dx, dy);
 
  285   double square_di_minus_dj;
 
  287   for (i = 0, di = 0.0; i < glcm.size1(); i++, di++)
 
  289     for (j = 0, dj = 0.0; j < glcm.size2(); j++, dj++)
 
  291       taskProgress.
pulse();
 
  293       di_minus_dj = (di - dj);
 
  294       square_di_minus_dj = di_minus_dj * di_minus_dj;
 
  296       metrics.
m_contrast += glcm(i, j) * square_di_minus_dj;
 
  298       metrics.
m_energy += glcm(i, j) * glcm(i, j);
 
  300         metrics.
m_entropy += glcm(i, j) * (-1.0 * log(glcm(i, j)));
 
  301       metrics.
m_homogeneity += glcm(i, j) / (1 + square_di_minus_dj);
 
TERASTEREXPORT te::rst::RasterPtr CropRaster(const te::rst::Raster &rin, const te::gm::Polygon &pin, const std::map< std::string, std::string > &rinfo, const std::string &rType=std::string("GDAL"))
Creates a raster crop using a polygon delimiter. 
 
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullVal)
 
A structure to hold the set of statistics from a set of numerical values. 
 
boost::numeric::ublas::matrix< double > getCovarianceMatrix(const std::vector< std::vector< double > > &vpixels, const std::vector< double > &vmeans)
Returns the covariance matrix between vectors of pixel values. 
 
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type. 
 
unsigned int getNumberOfColumns() const 
Returns the raster number of columns. 
 
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band. 
 
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
 
Extraction of attributes from Raster, Bands, and Polygons. 
 
This class can be used to inform the progress of a task. 
 
Raster Processing algorithm output parameters base interface. 
 
unsigned int getRow() const 
Returns the current row in iterator. 
 
boost::numeric::ublas::matrix< double > getGLCM(const te::rst::Raster &rin, unsigned int band, int dx, int dy)
Computes the Gray-Level CoOccurrence Matrix (GLCM) from a raster band. 
 
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max(). 
 
double m_energy
GLCM metric Energy (the square root of Angular Second Moment) ${{i,j=0}^{N-1}P_{i,j}^2}$. 
 
void reset()
Clear all internal allocated objects and reset the algorithm to its initial state. 
 
bool isInitialized() const 
Returns true if the algorithm instance is initialized and ready for execution. 
 
double m_homogeneity
GLCM metric Homogeneity (also called Inverse Difference Moment) ${i,j=0}^{N-1}{P_{i,j}}{1+(i-j)^2}$. 
 
boost::shared_ptr< Raster > RasterPtr
 
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator. 
 
An abstract class for raster data strucutures. 
 
unsigned int getNumberOfRows() const 
Returns the raster number of rows. 
 
std::vector< std::complex< double > > getComplexValuesFromBand(const te::rst::Raster &raster, unsigned int band, const te::gm::Polygon &polygon)
Returns the pixel values (real and imag) for the band, inside the polygon. 
 
BandProperty * getProperty()
Returns the band property. 
 
std::vector< std::vector< double > > getValuesFromRaster(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands)
Returns the pixel values for all the bands in raster, inside the polygon. 
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
double m_dissimilarity
GLCM metric Dissimilarity ${i,j=0}^{N-1}P_{i,j}|i-j|$. 
 
te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix< double > glcm)
Compute texture metrics from GLCM matrix. 
 
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1. 
 
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters. 
 
te::stat::NumericStatisticalSummary getStatistics(std::vector< double > &pixels)
Returns several statistics from a set of pixels. 
 
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const 
Returns the attribute value of a band of a cell. 
 
RasterAttributes()
Public constructor. 
 
double m_entropy
GLCM metric Entropy ${i,j=0}^{N-1}P_{i,j}(-{P_{i,j}})$. 
 
double m_contrast
GLCM metric Contrast (also called Sum of Squares Variance) ${i,j=0}^{N-1}P_{i,j}(i-j)^2$. 
 
std::vector< double > getValuesFromBand(const te::rst::Raster &raster, unsigned int band, const te::gm::Polygon &polygon)
Returns the pixel values for the band, inside the polygon. 
 
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings. 
 
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band. 
 
std::vector< std::vector< std::complex< double > > > getComplexValuesFromRaster(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands)
Returns the pixel values (real and imag) for all the bands in raster, inside the polygon. 
 
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution. 
 
A structure to hold the set of GLCM metrics. 
 
unsigned int getColumn() const 
Returns the current column in iterator. 
 
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).