RasterAttributes.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/rp/RasterAttributes.cpp
22 
23  \brief Extraction of attributes from Raster, Bands, and Polygons.
24 */
25 
26 // TerraLib
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"
36 #include "RasterAttributes.h"
37 
39 {
40  m_enableTaskProgress = enableTaskProgress;
41 }
42 
44 
46  const AlgorithmInputParameters& /*inputParams*/) _NOEXCEPT_OP(false)
47 {
48  return true;
49 }
50 
52 {
53  return true;
54 }
55 
57  AlgorithmOutputParameters& /*outputParams*/) _NOEXCEPT_OP(false)
58 {
59  return true;
60 }
61 
63 {
65 }
66 
67 std::vector<std::complex<double> > te::rp::RasterAttributes::getComplexValuesFromBand(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon)
68 {
69  std::vector<double> dvalues = getValuesFromBand(raster, band, polygon);
70  std::vector<std::complex<double> > values;
71 
72  for (unsigned int i = 0; i < dvalues.size(); i++)
73  values.push_back(dvalues[i]);
74 
75  return values;
76 }
77 
78 std::vector<double> te::rp::RasterAttributes::getValuesFromBand(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon)
79 {
80  assert(band < raster.getNumberOfBands());
81 
82  std::vector<double> values;
83 
84 // create iterators for band and polygon
87 
88  double noDataValue = raster.getBand(band)->getProperty()->m_noDataValue;
89 
90  while (it != itend)
91  {
92 // using iterator
93  if((*it)[band] != noDataValue)
94  values.push_back((*it)[band]);
95 
96  ++it;
97  }
98 
99  return values;
100 }
101 
102 void te::rp::RasterAttributes::getValuesFromBand(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon, std::map<double, int>& values)
103 {
104  assert(band < raster.getNumberOfBands());
105 
106 // create iterators for band and polygon
109 
110  double noDataValue = raster.getBand(band)->getProperty()->m_noDataValue;
111 
112  while (it != itend)
113  {
114  if((*it)[band] != noDataValue)
115  ++values[(*it)[band]];
116 
117  ++it;
118  }
119 }
120 
121 std::vector<std::vector<std::complex<double> > > te::rp::RasterAttributes::getComplexValuesFromRaster(const te::rst::Raster& raster, const te::gm::Polygon& polygon, std::vector<unsigned int> bands,
122  unsigned int rowstep, unsigned int colstep)
123 {
124  assert(bands.size() > 0);
125  assert(bands.size() <= raster.getNumberOfBands());
126 
127  assert(rowstep > 0);
128  assert(colstep > 0);
129 
130  std::vector<std::vector<std::complex<double> > > allvalues;
131  std::complex<double> value;
132 
133 // create iterators for band and polygon
136 
137  //unsigned int initrow = it.getRow();
138 
139  for (unsigned int i = 0; i < bands.size(); i++)
140  allvalues.push_back(std::vector<std::complex< double > > ());
141 
142  while (it != itend)
143  {
144  for (unsigned int i = 0; i < bands.size(); i++)
145  {
146  raster.getValue(it.getColumn(), it.getRow(), value, bands[i]);
147  allvalues[i].push_back(value);
148  }
149 
150  ++it;
151  }
152 
153  return allvalues;
154 
155 
156  /* std::vector<std::vector<double> > dallvalues = getValuesFromRaster(raster, polygon, bands);
157  std::vector<std::complex<double> > values;
158  std::vector<std::vector<std::complex<double> > > allvalues;
159 
160  for (unsigned int i = 0; i < dallvalues.size(); i++)
161  {
162  values.clear();
163  for (unsigned int j = 0; j < dallvalues[i].size(); j++)
164  values.push_back(dallvalues[i][j]);
165  allvalues.push_back(values);
166  }
167 
168  return allvalues;*/
169 }
170 
171 std::vector<std::vector<double> > te::rp::RasterAttributes::getValuesFromRaster(const te::rst::Raster& raster, const te::gm::Polygon& polygon, std::vector<unsigned int> bands,
172  unsigned int rowstep, unsigned int colstep)
173 {
174  assert(bands.size() > 0);
175  assert(bands.size() <= raster.getNumberOfBands());
176 
177  assert(rowstep > 0);
178  assert(colstep > 0);
179 
180  std::vector<std::vector<double> > allvalues;
181  double value;
182 
183 // create iterators for band and polygon
186 
187  unsigned int initrow = it.getRow(), initcol;
188 
189  for (unsigned int i = 0; i < bands.size(); i++)
190  allvalues.push_back(std::vector<double> ());
191  while (it != itend)
192  {
193  if(!((it.getRow() - initrow) % rowstep))
194  {
195  for (unsigned int i = 0; i < bands.size(); i++)
196  {
197  double noDataValue = raster.getBand(i)->getProperty()->m_noDataValue;
198 
199  raster.getValue(it.getColumn(), it.getRow(), value, bands[i]);
200 
201  if(noDataValue != value)
202  allvalues[i].push_back(value);
203  }
204  }
205 
206  unsigned posstep = it.getColumn() + colstep;
207 
208  initcol = it.getColumn();
209 
210  for(; initcol < posstep; initcol++)
211  ++it;
212  }
213 
214  return allvalues;
215 }
216 
218 {
219  assert(pixels.size() > 0);
220 
223  te::stat::Mode(pixels, summary);
224 
225  return summary;
226 }
227 
228 void te::rp::RasterAttributes::getStatisticsFromPolygon(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon, te::stat::NumericStatisticalSummary &summary, double noDataValue) {
229  assert(band < raster.getNumberOfBands());
230 
233 
234  std::vector<double> values;
235  std::map<double, int> modeMap;
236 
237  if (it != itEnd) {
238  double delta = 0.0;
239  double delta_n = 0.0;
240  double delta_n2 = 0.0;
241  double term1 = 0.0;
242  double mean = 0.0;
243  double M2 = 0.0;
244  double M3 = 0.0;
245  double M4 = 0.0;
246 
247  while (it != itEnd) {
248  double value = (*it)[band];
249 
250  if (value != raster.getBand(band)->getProperty()->m_noDataValue) {
251  ++summary.m_validCount;
252 
253  values.push_back(value);
254  summary.m_sum += value;
255 
256  ++modeMap[value];
257 
258  // Computing summs of differences for the mean (used to variance, std deviation, skewness and kurtosis)
259  delta = value - mean;
260  delta_n = delta / summary.m_validCount;
261  delta_n2 = delta_n * delta_n;
262  term1 = delta * delta_n * (summary.m_validCount - 1);
263  mean += delta_n;
264  M4 += term1 * delta_n2 * (summary.m_validCount * summary.m_validCount - 3 * summary.m_validCount + 3) + 6 * delta_n2 * M2 - 4 * delta_n * M3;
265  M3 += term1 * delta_n * (summary.m_validCount - 2) - 3 * delta_n * M2;
266  M2 += term1;
267  }
268  ++summary.m_count;
269 
270  ++it;
271  }
272 
273  summary.m_mean = summary.m_sum / summary.m_validCount;
274 
275  if (summary.m_validCount > 3) {
276  summary.m_variance = M2 / (summary.m_validCount - 1.0);
277  summary.m_stdDeviation = sqrt(summary.m_variance);
278 
279  summary.m_skewness = M3 / pow(M2, 1.5);
280  summary.m_skewness *= (summary.m_validCount * sqrt(summary.m_validCount - 1)) / (summary.m_validCount - 2);
281 
282  summary.m_kurtosis = M4 / (M2 * M2);
283  summary.m_kurtosis *= ((summary.m_validCount * (summary.m_validCount + 1) * (summary.m_validCount - 1)) / ((summary.m_validCount - 2) * (summary.m_validCount - 3)));
284  }
285  else if (summary.m_validCount > 2){
286  summary.m_variance = M2 / (summary.m_validCount - 1.0);
287  summary.m_stdDeviation = sqrt(summary.m_variance);
288 
289  summary.m_skewness = M3 / pow(M2, 1.5);
290  summary.m_skewness *= (summary.m_validCount * sqrt(summary.m_validCount - 1)) / (summary.m_validCount - 2);
291 
292  summary.m_kurtosis = 0;
293  }
294  else if (summary.m_validCount > 1) {
295  summary.m_variance = M2 / (summary.m_validCount - 1.0);
296  summary.m_stdDeviation = sqrt(summary.m_variance);
297 
298  summary.m_skewness = 0.0;
299  summary.m_kurtosis = 0.0;
300  }
301  else {
302  summary.m_variance = 0.0;
303  summary.m_stdDeviation = 0.0;
304  summary.m_skewness = 0.0;
305  summary.m_kurtosis = 0.0;
306  }
307 
308  summary.m_varCoeff = (100 * summary.m_stdDeviation) / summary.m_mean;
309 
310  std::sort(values.begin(), values.end());
311 
312  summary.m_minVal = *values.begin();
313  summary.m_maxVal = values[summary.m_validCount - 1];
314  summary.m_amplitude = summary.m_maxVal - summary.m_minVal;
315 
316  if ((summary.m_validCount % 2) == 0)
317  summary.m_median = (values[(summary.m_validCount / 2)] + values[(summary.m_validCount / 2 - 1)]) / 2.0;
318  else
319  summary.m_median = values[(summary.m_validCount - 1) / 2];
320 
321  std::map<double, int>::iterator itMode = modeMap.begin();
322  int repeat = 0;
323 
324  while (itMode != modeMap.end()) {
325  if (repeat < itMode->second) {
326  repeat = itMode->second;
327  summary.m_mode.clear();
328  summary.m_mode.push_back(itMode->first);
329  }
330  else if (repeat == itMode->second) {
331  summary.m_mode.push_back(itMode->first);
332  }
333  itMode++;
334  }
335  } else {
336  summary.m_validCount = (int)noDataValue;
337  summary.m_amplitude = noDataValue;
338  summary.m_count = (int)noDataValue;
339  summary.m_kurtosis = noDataValue;
340  summary.m_maxVal = noDataValue;
341  summary.m_mean = noDataValue;
342  summary.m_median = noDataValue;
343  summary.m_minVal = noDataValue;
344  summary.m_mode.push_back(noDataValue);
345  summary.m_skewness = noDataValue;
346  summary.m_stdDeviation = noDataValue;
347  summary.m_sum = noDataValue;
348  summary.m_varCoeff = noDataValue;
349  summary.m_variance = noDataValue;
350  }
351 }
352 
354 {
355  assert(pixels.size() > 0);
356 
359 
360  return summary;
361 }
362 
363 boost::numeric::ublas::matrix<std::complex < double> > te::rp::RasterAttributes::getComplexCovarianceMatrix(const std::vector<std::vector<std::complex < double > > >& vpixels, const std::vector<std::complex < double > >& vmeans)
364 {
365  for (unsigned int i = 0; i < vpixels.size(); i++)
366  assert(vpixels[i].size() > 0);
367  for (unsigned int i = 1; i < vpixels.size(); i++)
368  assert(vpixels[0].size() == vpixels[i].size());
369  assert(vpixels.size() == vmeans.size());
370 
371  unsigned int i;
372  unsigned int j;
373  unsigned int k;
374  unsigned int nbands = static_cast<unsigned int>(vpixels.size());
375  unsigned int nvalues = static_cast<unsigned int>(vpixels[0].size());
376 
377  boost::numeric::ublas::matrix<std::complex < double > > covariance(nbands, nbands);
378 
379  // with few values, the covariance is default
380  if (nvalues < 2)
381  {
382  for (i = 0; i < nbands; i++)
383  {
384  for (j = 0; j < nbands; j++)
385  covariance(i, j) = 0.0;
386  covariance(i, i) = 1000.0;
387  }
388 
389  return covariance;
390  }
391 
392  // compute covariance matrix based on values and means
393  std::unique_ptr<te::common::TaskProgress> taskProgress;
395  taskProgress.reset(new te::common::TaskProgress("Computing covariance complex matrix", te::common::TaskProgress::UNDEFINED, nbands * nbands));
396 
397  std::complex<double> sum;
398  for (i = 0; i < nbands; i++)
399  for (j = 0; j < nbands; j++)
400  {
402  taskProgress->pulse();
403 
404  sum = std::complex<double> (0.0, 0.0);
405 
406  for (k = 0; k < nvalues; k++)
407  sum += (vpixels[i][k] - vmeans[i]) * (vpixels[j][k] - vmeans[j]);
408 
409  covariance(i, j) = sum / (nvalues - 1.0);
410  }
411 
412  return covariance;
413 
414 }
415 
416 boost::numeric::ublas::matrix<double> te::rp::RasterAttributes::getCovarianceMatrix(const std::vector<std::vector<double> >& vpixels, const std::vector<double>& vmeans)
417 {
418  for (unsigned int i = 0; i < vpixels.size(); i++)
419  assert(vpixels[i].size() > 0);
420  for (unsigned int i = 1; i < vpixels.size(); i++)
421  assert(vpixels[0].size() == vpixels[i].size());
422  assert(vpixels.size() == vmeans.size());
423 
424  unsigned int i = 0;
425  unsigned int j = 0;
426  unsigned int k = 0;
427  const unsigned int nbands = static_cast<unsigned int>(vpixels.size());
428  const unsigned int nvalues = static_cast<unsigned int>(vpixels[0].size());
429 
430  if( nvalues < 2 )
431  {
432  throw te::common::Exception(TE_TR("Covariance matrix can not be computed"));
433  }
434 
435  boost::numeric::ublas::matrix<double> covariance(nbands, nbands);
436 
437 // compute covariance matrix based on values and means
438 
439  std::unique_ptr<te::common::TaskProgress> taskProgress;
441  taskProgress.reset(new te::common::TaskProgress("Computing covariance matrix", te::common::TaskProgress::UNDEFINED, nbands * nbands));
442 
443  double sum = 0;
444 
445  for (i = 0; i < nbands; i++)
446  {
447  for (j = 0; j < nbands; j++)
448  {
450  taskProgress->pulse();
451 
452  sum = 0;
453 
454  for (k = 0; k < nvalues; k++)
455  sum += (vpixels[i][k] - vmeans[i]) * (vpixels[j][k] - vmeans[j]);
456 
457  covariance(i, j) = sum / ( (double)(nvalues - 1) );
458  }
459  }
460 
461  return covariance;
462 }
463 
464 boost::numeric::ublas::matrix<double> te::rp::RasterAttributes::getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
465  double minPixel, double maxPixel, double gLevels)
466 {
467  assert(band < rin.getNumberOfBands());
468 
469  if (maxPixel == 0 && minPixel == 0) {
470  throw te::common::Exception(TE_TR("GLCM can not be computed. Minimum and Maximum values are invalid."));
471  }
472 
473  double minValueNormalization, maxValueNormalization, matrixLimit;
474  bool normalize = false;
475 
476  if ((maxPixel - minPixel) > (gLevels - 1)) {
477  minValueNormalization = 0;
478  maxValueNormalization = gLevels - 1;
479  matrixLimit = gLevels;
480  normalize = true;
481  } else {
482  matrixLimit = (maxPixel - minPixel) + 1;
483  }
484 
485 
486  boost::numeric::ublas::matrix<double> glcm(static_cast<unsigned int>(matrixLimit), static_cast<unsigned int>(matrixLimit));
487  glcm.clear();
488  double pixel;
489  double neighborPixel;
490  double noDataValue = rin.getBand(band)->getProperty()->m_noDataValue;
491  double N = 0.0;
492 
493 // defining limits for iteration
494  int row_start = 0;
495  int row_end = rin.getNumberOfRows();
496  int column_start = 0;
497  int column_end = rin.getNumberOfColumns();
498 
499  if (dy > 0)
500  row_end -= dy;
501  else
502  row_start -= dy;
503 
504  if (dx > 0)
505  column_end -= dx;
506  else
507  column_start -= dx;
508 
509 // computing GLCM
510  std::unique_ptr<te::common::TaskProgress> taskProgress;
512  taskProgress.reset(new te::common::TaskProgress("Computing the GLCM", te::common::TaskProgress::UNDEFINED, (row_end - row_start) * (column_end - column_start)));
513 
514  for (int r = row_start; r < row_end; r++)
515  {
516  for (int c = column_start; c < column_end; c++)
517  {
519  taskProgress->pulse();
520 
521 // get central pixel
522  rin.getValue(c, r, pixel, band);
523  if (pixel == noDataValue)
524  continue;
525 
526  double auxPixel = pixel;
527  // normalizing between 0-maxValue
528  if (normalize) {
529  pixel = std::round((((maxValueNormalization - minValueNormalization) / (maxPixel - minPixel)) * (auxPixel - minPixel)) + minValueNormalization);
530  if (pixel < 0)
531  pixel = 0;
532  else if (pixel > maxValueNormalization)
533  pixel = maxValueNormalization;
534  }
535 
536 // get neighbor pixel
537  rin.getValue(c + dx, r + dy, neighborPixel, band);
538  if (neighborPixel == noDataValue)
539  continue;
540 
541  double auxNeighbor = neighborPixel;
542  // normalizing between 0-maxValue
543  if (normalize) {
544  neighborPixel = std::round((((maxValueNormalization - minValueNormalization) / (maxPixel - minPixel)) * (auxNeighbor - minPixel)) + minValueNormalization);
545  if (neighborPixel < 0)
546  neighborPixel = 0;
547  else if (neighborPixel > maxValueNormalization)
548  neighborPixel = maxValueNormalization;
549  }
550 
551 // update GLCM matrix
552  glcm(static_cast<unsigned int>(pixel), static_cast<unsigned int>(neighborPixel)) = glcm(static_cast<unsigned int>(pixel), static_cast<unsigned int>(neighborPixel))+1;
553  N++;
554  }
555  }
556 
557  if (N > 0.0)
558  {
559  for (unsigned int i = 0; i < glcm.size1(); i++)
560  for (unsigned int j = 0; j < glcm.size2(); j++)
561  glcm(i, j) = glcm(i, j) / N;
562  }
563 
564  return glcm;
565 }
566 
567 boost::numeric::ublas::matrix<double> te::rp::RasterAttributes::getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
568  const te::gm::Polygon& polygon, double minPixel, double maxPixel, double gLevels)
569 {
570  if (maxPixel == 0 && minPixel == 0) {
571  throw te::common::Exception(TE_TR("GLCM can not be computed. Minimum and Maximum values are invalid."));
572  }
573 
574  // create raster crop with polygon
575  std::map<std::string, std::string> rcropinfo;
576  rcropinfo["FORCE_MEM_DRIVER"] = "TRUE";
577  te::rst::RasterPtr rcrop = te::rst::CropRaster(rin, polygon, rcropinfo, "MEM");
578 
579  // call previous method using crop
580  if (rcrop)
581  return getGLCM(*rcrop.get(), band, dx, dy, minPixel, maxPixel, gLevels);
582  else
583  return boost::numeric::ublas::matrix<double>();
584 }
585 
586 te::rp::Texture te::rp::RasterAttributes::getGLCMMetrics(boost::numeric::ublas::matrix<double> glcm, double noDataValue)
587 {
588  te::rp::Texture metrics;
589 
590  unsigned int i;
591  unsigned int j;
592  double di;
593  double dj;
594  double di_minus_dj;
595  double square_di_minus_dj;
596 
597  if (glcm.size1() == 0 && glcm.size2() == 0) {
598  metrics.m_contrast = noDataValue;
599  metrics.m_dissimilarity = noDataValue;
600  metrics.m_energy = noDataValue;
601  metrics.m_entropy = noDataValue;
602  metrics.m_homogeneity = noDataValue;
603  return metrics;
604  }
605 
606  std::unique_ptr<te::common::TaskProgress> taskProgress;
608  taskProgress.reset(new te::common::TaskProgress("Computing GLCM Metrics", te::common::TaskProgress::UNDEFINED, static_cast<int>(glcm.size1() * glcm.size2())));
609  for (i = 0, di = 0.0; i < glcm.size1(); i++, di++)
610  {
611  for (j = 0, dj = 0.0; j < glcm.size2(); j++, dj++)
612  {
614  taskProgress->pulse();
615 
616  di_minus_dj = (di - dj);
617  square_di_minus_dj = di_minus_dj * di_minus_dj;
618 
619  metrics.m_contrast += glcm(i, j) * square_di_minus_dj;
620  metrics.m_dissimilarity += glcm(i, j) * std::abs(di_minus_dj);
621  metrics.m_energy += glcm(i, j) * glcm(i, j);
622  if (glcm(i, j) > 0)
623  metrics.m_entropy += glcm(i, j) * (-1.0 * log(glcm(i, j)));
624  metrics.m_homogeneity += glcm(i, j) / (1 + square_di_minus_dj);
625  }
626  }
627 
628  if (metrics.m_energy > 0)
629  metrics.m_energy = std::sqrt(metrics.m_energy);
630 
631  return metrics;
632 }
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.
std::vector< std::vector< std::complex< double > > > getComplexValuesFromRaster(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands, unsigned int rowstep=1, unsigned int colstep=1)
Returns the pixel values (real and imag) for all the bands in raster, inside the polygon.
unsigned int band
A structure to hold the set of statistics from a set of numerical values.
boost::numeric::ublas::matrix< std::complex< double > > getComplexCovarianceMatrix(const std::vector< std::vector< std::complex< double > > > &vpixels, const std::vector< std::complex< double > > &vmeans)
Returns the covariance matrix between vectors of pixel 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.
static te::dt::Date dx(2010, 12, 31)
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
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.
Definition: TaskProgress.h:53
Raster Processing algorithm output parameters base interface.
#define _NOEXCEPT_OP(x)
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
unsigned int getRow() const
Returns the current row in iterator.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
Definition: BandProperty.h:136
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
double m_energy
GLCM metric Energy (the square root of Angular Second Moment) ${{i,j=0}^{N-1}P_{i,j}^2}$.
Definition: Texture.h:77
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}$.
Definition: Texture.h:79
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.
boost::numeric::ublas::matrix< double > getGLCM(const te::rst::Raster &rin, unsigned int band, int dx, int dy, double minPixel, double maxPixel, double gLevels=256)
Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band.
te::stat::NumericStatisticalComplexSummary getComplexStatistics(std::vector< std::complex< double > > &pixels)
Returns several statistics from a set of pixels (real and imag).
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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.
static te::dt::Date di(2010, 06, 10)
double m_dissimilarity
GLCM metric Dissimilarity ${i,j=0}^{N-1}P_{i,j}|i-j|$.
Definition: Texture.h:76
list bands
Definition: compose.py:2
std::vector< std::vector< double > > getValuesFromRaster(const te::rst::Raster &raster, const te::gm::Polygon &polygon, std::vector< unsigned int > bands, unsigned int rowstep=1, unsigned int colstep=1)
Returns the pixel values for all the bands in raster, inside the polygon.
TESTATEXPORT void GetNumericStatisticalSummary(std::vector< double > &values, te::stat::NumericStatisticalSummary &ss, double nullValue)
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
te::stat::NumericStatisticalSummary getStatistics(std::vector< double > &pixels)
Returns several statistics from a set of pixels.
te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix< double > glcm, double noDataValue=0.0)
Compute texture metrics from GLCM matrix.
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.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p, const IterationType iterationType)
Returns an iterator referring to the first value of the band.
double m_entropy
GLCM metric Entropy ${i,j=0}^{N-1}P_{i,j}(-{P_{i,j}})$.
Definition: Texture.h:78
RasterAttributes(bool enableTaskProgress=true)
Public constructor.
double m_contrast
GLCM metric Contrast (also called Sum of Squares Variance) ${i,j=0}^{N-1}P_{i,j}(i-j)^2$.
Definition: Texture.h:75
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.
Definition: Polygon.h:50
A structure to hold the set of GLCM metrics.
Definition: Texture.h:44
Raster Processing algorithm input parameters base interface.
TESTATEXPORT void GetNumericComplexStatisticalSummary(std::vector< std::complex< double > > &values, te::stat::NumericStatisticalComplexSummary &ss)
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
virtual void reset() _NOEXCEPT_OP(false)
Clear all internal allocated objects and reset the algorithm to its initial state.
unsigned int getColumn() const
Returns the current column in iterator.
void getStatisticsFromPolygon(const te::rst::Raster &raster, unsigned int band, const te::gm::Polygon &polygon, te::stat::NumericStatisticalSummary &summary, double noDataValue=0.0)
Computes several statistics from a set of pixels inside a polygon.
TESTATEXPORT void Mode(const std::vector< double > &values, te::stat::NumericStatisticalSummary &ss)