Loading...
Searching...
No Matches
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
44namespace 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
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 a non zero value either + or -.
209 \param dy The displacement in y direction, to be considered as neighborhood, can be non zero value either + or -.
210 \param minPixel The minimum GL pixel value that occurs in the band (leave 0 for automatic detection).
211 \param maxPixel The maximum GL pixel value that occurs in the band (leave 0 for automatic detection).
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 \note If minPixel = 0 and maxPixel = 0 both values will be automatically detected.
219
220 \exception te::common::Exception It will throw an exception for incorrect parameters or execution errors.
221
222 \warning The pixels from the input band will be considered of type unsigned int.
223 */
224 boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
225 double minPixel, double maxPixel, unsigned int gLevels = 256);
226
227 /*!
228 \brief Computes the Gray-Level Co-occurrence Matrix (GLCM) from a raster band, inside the polygon.
229
230 \param rin The input raster.
231 \param band The input band position.
232 \param dx The displacement in x direction, to be considered as neighborhood, can be a non zero value either + or -.
233 \param dy The displacement in y direction, to be considered as neighborhood, can be non zero value either + or -.
234 \param polygon The input polygon.
235 \param minPixel The minimum GL pixel value that occurs in the band (leave 0 for automatic detection).
236 \param maxPixel The maximum GL pixel value that occurs in the band (leave 0 for automatic detection).
237 \param gLevels The number of Gray Levels (GL) to normalize the GLCM. The GLs will be normalized to the interval
238 [0,(gLevels - 1)]. It is important to emphasize that the matrix will have 'gLevels' lines and
239 'gLevels' columns. Default value is 256, normalizing the GLs to the interval [0, 255].
240
241 \return The GLCM from the raster band, inside the polygon.
242
243 \exception te::common::Exception It will throw an exception for incorrect parameters or execution errors.
244
245 \warning The pixels from the input band will be considered of type unsigned int.
246 */
247 boost::numeric::ublas::matrix<double> getGLCM(const te::rst::Raster& rin, unsigned int band, int dx, int dy,
248 const te::gm::Polygon& polygon, double minPixel, double maxPixel, unsigned int gLevels = 256);
249
250 /*!
251 \brief Compute texture metrics from GLCM matrix.
252
253 \param glcm The input GLCM matrix.
254
255 \param noDataValue The value that will be used when the matrix received is empty, i. e.,
256 when the polygon does not intersects the raster. Default value is 0.0.
257
258 \return The Texture structure will all available metrics computed
259 */
260 te::rp::Texture getGLCMMetrics(boost::numeric::ublas::matrix<double> glcm, double noDataValue = 0.0);
261
262 private:
263 bool m_enableTaskProgress;
264 };
265
266 } // end namespace rp
267} // end namespace te
268
269#endif // __TERRALIB_RP_INTERNAL_RASTERATTRIBUTES_H
#define _NOEXCEPT_OP(x)
A structure to hold the set of GLCM metrics.
Raster Processing algorithm input parameters base interface.
Raster Processing algorithm output parameters base interface.
Raster Processing algorithm base interface.
Definition: Algorithm.h:42
Extraction of attributes from Raster, Bands, and Polygons.
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
RasterAttributes(bool enableTaskProgress=true)
Public constructor.
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
void reset() _NOEXCEPT_OP(false)
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.
TerraLib.
A structure to hold the set of GLCM metrics.
Definition: Texture.h:45
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Proxy configuration file for TerraView (see terraview_config.h).
Abstract algorithm.
An exception class for the XML module.