RasterAttributes.h
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.h
22 
23  \brief Extraction of attributes from Raster, Bands, and Polygons.
24  */
25 
26 #ifndef __TERRALIB_RP_INTERNAL_RASTERATTRIBUTES_H
27 #define __TERRALIB_RP_INTERNAL_RASTERATTRIBUTES_H
28 
29 // TerraLib
30 #include "../statistics/core/NumericStatisticalSummary.h"
31 #include "../statistics/core/NumericStatisticalComplexSummary.h"
32 #include "Algorithm.h"
33 #include "Config.h"
34 #include "Exception.h"
35 #include "Texture.h"
36 
37 // Boost
38 #include <boost/numeric/ublas/io.hpp>
39 #include <boost/numeric/ublas/matrix.hpp>
40 
41 // STL
42 #include <complex>
43 
44 namespace te
45 {
46 // Forward declaration
47  namespace gm
48  {
49  class Polygon;
50  }
51  namespace rst
52  {
53  class Band;
54  class Raster;
55  }
56 
57  namespace rp
58  {
59  /*!
60  \class RasterAttributes
61 
62  \brief Extraction of attributes from Raster, Bands, and Polygons.
63  */
65  {
66  public:
67 
68  /*! \brief Public constructor. */
69  RasterAttributes(bool enableTaskProgress = true);
70 
72 
73  // overload
74  bool initialize(const AlgorithmInputParameters& inputParams) _NOEXCEPT_OP(false);
75 
76  //overload
77  bool isInitialized() const;
78 
79  // overload
80  bool execute(AlgorithmOutputParameters& outputParams) _NOEXCEPT_OP(false);
81 
82  // overload
83  void reset() _NOEXCEPT_OP(false);
84 
85  /*!
86  \brief Returns the pixel values (real and imag) for the band, inside the polygon.
87 
88  \param raster The input raster.
89  \param band The position of the input band.
90  \param polygon The input polygon.
91 
92  \return The pixel values for the band, inside the polygon.
93 
94  \warning Band and polygon must fit.
95  */
96  std::vector<std::complex<double> > getComplexValuesFromBand(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon);
97 
98  /*!
99  \brief Returns the pixel values for the band, inside the polygon.
100 
101  \param raster The input raster.
102  \param band The position of the input band.
103  \param polygon The input polygon.
104 
105  \return The pixel values for the band, inside the polygon.
106 
107  \warning Band and polygon must fit.
108  */
109  std::vector<double> getValuesFromBand(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon);
110 
111  /*!
112  \brief Returns the pixel values for the band, inside the polygon.
113 
114  \param raster The input raster.
115  \param band The position of the input band.
116  \param polygon The input polygon.
117  \param values A map with pixel values as key and the number of occurrence as value for the current band, inside the polygon.
118 
119  \warning Band and polygon must fit.
120  */
121  void getValuesFromBand(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon, std::map<double, int>& values);
122 
123  /*!
124  \brief Returns the pixel values (real and imag) for all the bands in raster, inside the polygon.
125 
126  \param raster The input band.
127  \param polygon The input polygon.
128  \param bands Bands to be processed from the input raster.
129 
130  \return A vector with the pixel values for all the bands in raster, inside the polygon, with values[band][pixel].
131 
132  \warning Bands and polygon must fit.
133  */
134  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);
135 
136  /*!
137  \brief Returns the pixel values for all the bands in raster, inside the polygon.
138 
139  \param raster The input band.
140  \param polygon The input polygon.
141  \param bands Bands to be processed from the input raster.
142 
143  \return A vector with the pixel values for all the bands in raster, inside the polygon, with values[band][pixel].
144 
145  \warning Bands and polygon must fit.
146  */
147  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);
148 
149  /*!
150  \brief Returns several statistics from a set of pixels.
151 
152  \param pixels A vector of pixel values.
153 
154  \return A series of statistics (\sa te::stat::NumericStatisticalSummary).
155  */
156  te::stat::NumericStatisticalSummary getStatistics(std::vector<double>& pixels);
157 
158  /*!
159  \brief Computes several statistics from a set of pixels inside a polygon.
160 
161  \param raster The input raster.
162  \param band The number of the band to compute the statistics.
163  \param polygon The input polygon.
164  \param summary The statistical summary that will be filled by the method (\sa te::stat::NumericStatisticalSummary).
165  \param nodataValue The value that will be used when the polygon does not intersects the
166  raster. Default value is 0.0.
167  */
168  void getStatisticsFromPolygon(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon, te::stat::NumericStatisticalSummary &summary, double noDataValue = 0.0);
169 
170  /*!
171  \brief Returns several statistics from a set of pixels (real and imag).
172 
173  \param pixels A vector of pixel values.
174 
175  \return A series of statistics (\sa te::stat::NumericStatisticalSummary).
176  */
177  te::stat::NumericStatisticalComplexSummary getComplexStatistics(std::vector <std::complex <double> >& pixels);
178 
179  /*!
180  \brief Returns the covariance matrix between vectors of pixel values.
181 
182  \param vpixels The vector of pixel vectors, with vpixels[band][pixel].
183  \param vmeans The vector of pixels means, one mean per vector of pixels.
184 
185  \return The covariance matrix between the vectors of pixel values.
186 
187  \warning All vectors sizes must fit.
188  */
189  boost::numeric::ublas::matrix<double> getCovarianceMatrix(const std::vector<std::vector<double> >& vpixels, const std::vector<double>& vmeans);
190 
191  /*!
192  \brief Returns the covariance matrix between vectors of pixel values.
193 
194  \param vpixels The vector of pixel vectors, with vpixels[band][pixel].
195  \param vmeans The vector of pixels means, one mean per vector of pixels.
196 
197  \return The covariance matrix between the vectors of pixel values.
198 
199  \warning All vectors sizes must fit.
200  */
201  boost::numeric::ublas::matrix<std::complex <double> > getComplexCovarianceMatrix(const std::vector<std::vector<std::complex < double> > >& vpixels, const std::vector<std::complex < double > >& vmeans);
202 
203  /*!
204  \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band.
205 
206  \param rin The input raster.
207  \param band The input band position.
208  \param dx The displacement in x direction, to be considered as neighborhood, can be either + or -.
209  \param dy The displacement in y direction, to be considered as neighborhood, can be either + or -.
210  \param minPixel The minimum GL pixel value that occurs in the band.
211  \param maxPixel The maximum GL pixel value that occurs in the band.
212  \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
213  [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
214  'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
215 
216  \return The GLCM from the raster band.
217 
218  \exception te::common::Exception It will throw an exception if the parameters minPixel and maxPixel were not passed as parameters.
219 
220  \warning The pixels from the input band will be considered of type unsigned int.
221  */
222  boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
223  double minPixel, double maxPixel, double gLevels = 256);
224 
225  /*!
226  \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band, inside the polygon.
227 
228  \param rin The input raster.
229  \param band The input band position.
230  \param dx The displacement in x direction, to be considered as neighborhood, can be either + or -.
231  \param dy The displacement in y direction, to be considered as neighborhood, can be either + or -.
232  \param polygon The input polygon.
233  \param minPixel The minimum GL pixel value that occurs in the band.
234  \param maxPixel The maximum GL pixel value that occurs in the band.
235  \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
236  [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
237  'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
238 
239  \return The GLCM from the raster band, inside the polygon.
240 
241  \exception te::common::Exception It will throw an exception if the parameters minPixel and maxPixel were not passed as parameters.
242 
243  \warning The pixels from the input band will be considered of type unsigned int.
244  */
245  boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
246  const te::gm::Polygon& polygon, double minPixel, double maxPixel, double gLevels = 256);
247 
248  /*!
249  \brief Compute texture metrics from GLCM matrix.
250 
251  \param glcm The input GLCM matrix.
252 
253  \param noDataValue The value that will be used when the matrix received is empty, i. e.,
254  when the polygon does not intersects the raster. Default value is 0.0.
255 
256  \return The Texture structure will all available metrics computed
257  */
258  te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix<double> glcm, double noDataValue = 0.0);
259 
260  private:
262  };
263 
264  } // end namespace rp
265 } // end namespace te
266 
267 #endif // __TERRALIB_RP_INTERNAL_RASTERATTRIBUTES_H
A structure to hold the set of statistics from a set of numerical values.
A structure to hold the set of GLCM metrics.
Raster Processing algorithm output parameters base interface.
#define _NOEXCEPT_OP(x)
Raster Processing algorithm base interface class.
Extraction of attributes from Raster, Bands, and Polygons.
Exception class.
Raster Processing algorithm base interface.
Definition: Algorithm.h:41
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Configuration flags for the Raster Processing module of TerraLib.
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.