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) throw(te::rp::Exception);
75 
76  //overload
77  bool isInitialized() const;
78 
79  // overload
80  bool execute(AlgorithmOutputParameters& outputParams) throw(te::rp::Exception);
81 
82  // overload
83  void reset() throw(te::rp::Exception);
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  */
166  void getStatisticsFromPolygon(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon, te::stat::NumericStatisticalSummary &summary);
167 
168  /*!
169  \brief Returns several statistics from a set of pixels (real and imag).
170 
171  \param pixels A vector of pixel values.
172 
173  \return A series of statistics (\sa te::stat::NumericStatisticalSummary).
174  */
175  te::stat::NumericStatisticalComplexSummary getComplexStatistics(std::vector <std::complex <double> >& pixels);
176 
177  /*!
178  \brief Returns the covariance matrix between vectors of pixel values.
179 
180  \param vpixels The vector of pixel vectors, with vpixels[band][pixel].
181  \param vmeans The vector of pixels means, one mean per vector of pixels.
182 
183  \return The covariance matrix between the vectors of pixel values.
184 
185  \warning All vectors sizes must fit.
186  */
187  boost::numeric::ublas::matrix<double> getCovarianceMatrix(const std::vector<std::vector<double> >& vpixels, const std::vector<double>& vmeans);
188 
189  /*!
190  \brief Returns the covariance matrix between vectors of pixel values.
191 
192  \param vpixels The vector of pixel vectors, with vpixels[band][pixel].
193  \param vmeans The vector of pixels means, one mean per vector of pixels.
194 
195  \return The covariance matrix between the vectors of pixel values.
196 
197  \warning All vectors sizes must fit.
198  */
199  boost::numeric::ublas::matrix<std::complex <double> > getComplexCovarianceMatrix(const std::vector<std::vector<std::complex < double> > >& vpixels, const std::vector<std::complex < double > >& vmeans);
200 
201  /*!
202  \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band.
203 
204  \param rin The input raster.
205  \param band The input band position.
206  \param dx The displacement in x direction, to be considered as neighborhood, can be either + or -.
207  \param dy The displacement in y direction, to be considered as neighborhood, can be either + or -.
208  \param minPixel The minimum GL pixel value that occurs in the band.
209  \param maxPixel The maximum GL pixel value that occurs in the band.
210  \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
211  [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
212  'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
213 
214  \return The GLCM from the raster band.
215 
216  \exception te::common::Exception It will throw an exception if the parameters minPixel and maxPixel were not passed as parameters.
217 
218  \warning The pixels from the input band will be considered of type unsigned int.
219  */
220  boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
221  double minPixel, double maxPixel, double gLevels = 256);
222 
223  /*!
224  \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band, inside the polygon.
225 
226  \param rin The input raster.
227  \param band The input band position.
228  \param dx The displacement in x direction, to be considered as neighborhood, can be either + or -.
229  \param dy The displacement in y direction, to be considered as neighborhood, can be either + or -.
230  \param polygon The input polygon.
231  \param minPixel The minimum GL pixel value that occurs in the band.
232  \param maxPixel The maximum GL pixel value that occurs in the band.
233  \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
234  [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
235  'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
236 
237  \return The GLCM from the raster band, inside the polygon.
238 
239  \exception te::common::Exception It will throw an exception if the parameters minPixel and maxPixel were not passed as parameters.
240 
241  \warning The pixels from the input band will be considered of type unsigned int.
242  */
243  boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
244  const te::gm::Polygon& polygon, double minPixel, double maxPixel, double gLevels = 256);
245 
246  /*!
247  \brief Compute texture metrics from GLCM matrix.
248 
249  \param glcm The input GLCM matrix.
250 
251  \return The Texture structure will all available metrics computed
252  */
253  te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix<double> glcm);
254 
255  private:
257  };
258 
259  } // end namespace rp
260 } // end namespace te
261 
262 #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.
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.