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. */
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 (real and imag) for all the bands in raster, inside the polygon.
113 
114  \param raster The input band.
115  \param polygon The input polygon.
116  \param bands Bands to be processed from the input raster.
117 
118  \return A vector with the pixel values for all the bands in raster, inside the polygon, with values[band][pixel].
119 
120  \warning Bands and polygon must fit.
121  */
122  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);
123 
124  /*!
125  \brief Returns the pixel values for all the bands in raster, inside the polygon.
126 
127  \param raster The input band.
128  \param polygon The input polygon.
129  \param bands Bands to be processed from the input raster.
130 
131  \return A vector with the pixel values for all the bands in raster, inside the polygon, with values[band][pixel].
132 
133  \warning Bands and polygon must fit.
134  */
135  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);
136 
137  /*!
138  \brief Returns several statistics from a set of pixels.
139 
140  \param pixels A vector of pixel values.
141 
142  \return A series of statistics (\sa te::stat::NumericStatisticalSummary).
143  */
144  te::stat::NumericStatisticalSummary getStatistics(std::vector<double>& pixels);
145 
146  /*!
147  \brief Computes several statistics from a set of pixels inside a polygon.
148 
149  \param raster The input raster.
150  \param band The number of the band to compute the statistics.
151  \param polygon The input polygon.
152  \param summary The statistical summary that will be filled by the method (\sa te::stat::NumericStatisticalSummary).
153  */
154  void getStatisticsFromPolygon(const te::rst::Raster& raster, unsigned int band, const te::gm::Polygon& polygon, te::stat::NumericStatisticalSummary &summary);
155 
156  /*!
157  \brief Returns several statistics from a set of pixels (real and imag).
158 
159  \param pixels A vector of pixel values.
160 
161  \return A series of statistics (\sa te::stat::NumericStatisticalSummary).
162  */
163  te::stat::NumericStatisticalComplexSummary getComplexStatistics(std::vector <std::complex <double> >& pixels);
164 
165  /*!
166  \brief Returns the covariance matrix between vectors of pixel values.
167 
168  \param vpixels The vector of pixel vectors, with vpixels[band][pixel].
169  \param vmeans The vector of pixels means, one mean per vector of pixels.
170 
171  \return The covariance matrix between the vectors of pixel values.
172 
173  \warning All vectors sizes must fit.
174  */
175  boost::numeric::ublas::matrix<double> getCovarianceMatrix(const std::vector<std::vector<double> >& vpixels, const std::vector<double>& vmeans);
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<std::complex <double> > getComplexCovarianceMatrix(const std::vector<std::vector<std::complex < double> > >& vpixels, const std::vector<std::complex < double > >& vmeans);
188 
189  /*!
190  \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band.
191 
192  \param rin The input raster.
193  \param band The input band position.
194  \param dx The displacement in x direction, to be considered as neighborhood, can be either + or -.
195  \param dy The displacement in y direction, to be considered as neighborhood, can be either + or -.
196  \param minPixel The minimum GL pixel value that occurs in the band.
197  \param maxPixel The maximum GL pixel value that occurs in the band.
198  \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
199  [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
200  'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
201 
202  \return The GLCM from the raster band.
203 
204  \exception te::common::Exception It will throw an exception if the parameters minPixel and maxPixel were not passed as parameters.
205 
206  \warning The pixels from the input band will be considered of type unsigned int.
207  */
208  boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
209  double minPixel, double maxPixel, double gLevels = 256);
210 
211  /*!
212  \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band, inside the polygon.
213 
214  \param rin The input raster.
215  \param band The input band position.
216  \param dx The displacement in x direction, to be considered as neighborhood, can be either + or -.
217  \param dy The displacement in y direction, to be considered as neighborhood, can be either + or -.
218  \param polygon The input polygon.
219  \param minPixel The minimum GL pixel value that occurs in the band.
220  \param maxPixel The maximum GL pixel value that occurs in the band.
221  \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
222  [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
223  'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
224 
225  \return The GLCM from the raster band, inside the polygon.
226 
227  \exception te::common::Exception It will throw an exception if the parameters minPixel and maxPixel were not passed as parameters.
228 
229  \warning The pixels from the input band will be considered of type unsigned int.
230  */
231  boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
232  const te::gm::Polygon& polygon, double minPixel, double maxPixel, double gLevels = 256);
233 
234  /*!
235  \brief Compute texture metrics from GLCM matrix.
236 
237  \param glcm The input GLCM matrix.
238 
239  \return The Texture structure will all available metrics computed
240  */
241  te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix<double> glcm);
242 
243  };
244 
245  } // end namespace rp
246 } // end namespace te
247 
248 #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.