Filter.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/Filter.h
22  \brief A series of well-known filtering algorithms for images, linear and non-linear.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_FILTER_H
26 #define __TERRALIB_RP_INTERNAL_FILTER_H
27 
28 #include "Algorithm.h"
29 #include "../raster/Raster.h"
30 
31 // Boost
32 #include <boost/numeric/ublas/io.hpp>
33 #include <boost/numeric/ublas/matrix.hpp>
34 
35 // STL
36 #include <vector>
37 
38 namespace te
39 {
40  namespace rp
41  {
42  /*!
43  \class Filter
44  \brief A series of well-known filtering algorithms for images, linear and non-linear..
45  \ingroup rp_enh
46  */
47  class TERPEXPORT Filter : public Algorithm
48  {
49  public:
50 
51  /*!
52  \class InputParameters
53  \brief Filter input parameters
54  */
56  {
57  public:
58 
59  /*! \enum The edge filter type.*/
61  {
62  InvalidFilterT = 0, //!< Invalid strategy.
63  SobelFilterT = 1, //!< Sobel filter type.
64  RobertsFilterT = 2, //!< Roberts filter type.
65  MeanFilterT = 3, //!< The resultant pixel will be the mean of pixels in the convolution window.
66  ModeFilterT = 4, //!< The resultant pixel will be the mode of pixels in the convolution window. When the window is multimodal, the first mode will be assumed.
67  MedianFilterT = 5, //!< The resultant pixel will be the median of pixels in the convolution window.
68  DilationFilterT = 6, //!< The resultant pixel will be the highest pixel value in the convolution window.
69  ErosionFilterT = 7, //!< The resultant pixel will be the lowest pixel value in the convolution window.
70  UserDefinedWindowT = 8 //!< The user will define the weights of a convolution window.
71  };
72 
73  FilterType m_filterType; //!< The edge filter type.
74 
75  te::rst::Raster const* m_inRasterPtr; //!< Input raster.
76 
77  std::vector< unsigned int > m_inRasterBands; //!< Bands to be used from the input raster 1.
78 
79  unsigned int m_iterationsNumber; //!< The number of iterations to perform (default:1).
80 
81  unsigned int m_windowH; //!< The height of the convolution window. (commonly 3, with W=3 to make a 3x3 window, and so on)
82 
83  unsigned int m_windowW; //!< The width of the convolution window.
84 
85  bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
86 
87  boost::numeric::ublas::matrix<double> m_window; //!< User defined convolution window. (The size must be equal to m_windowH x m_windowW)
88 
90 
92 
93  ~InputParameters();
94 
95  //overload
96  void reset() throw( te::rp::Exception );
97 
98  //overload
99  const InputParameters& operator=( const InputParameters& params );
100 
101  //overload
102  AbstractParameters* clone() const;
103  };
104 
105  /*!
106  \class OutputParameters
107  \brief Filter output parameters
108  */
110  {
111  public:
112 
113  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
114 
115  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the raster (as described in te::raster::RasterFactory).
116 
117  std::auto_ptr< te::rst::Raster > m_outputRasterPtr; //!< A pointer the ge generated output raster (label image).
118 
120 
122 
123  ~OutputParameters();
124 
125  //overload
126  void reset() throw( te::rp::Exception );
127 
128  //overload
129  const OutputParameters& operator=( const OutputParameters& params );
130 
131  //overload
132  AbstractParameters* clone() const;
133  };
134 
135  Filter();
136 
137  ~Filter();
138 
139  //overload
140  bool execute( AlgorithmOutputParameters& outputParams ) throw( te::rp::Exception );
141 
142  //overload
143  void reset() throw( te::rp::Exception );
144 
145  //overload
146  bool initialize( const AlgorithmInputParameters& inputParams ) throw( te::rp::Exception );
147 
148  //overload
149  bool isInitialized() const;
150 
151  protected:
152 
153  /*!
154  \brief Type definition for a filter method pointer.
155  \param srcRaster Source raster.
156  \param srcBandIdx Source raster band index.
157  \param dstRaster Destination raster.
158  \param dstBandIdx Destination raster band index.
159  \param useProgress if true, the progress interface must be used.
160  \return true if ok, false on errors.
161  */
162  typedef bool (Filter::*FilterMethodPointerT)( const te::rst::Raster& srcRaster,
163  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
164  const unsigned int dstBandIdx, const bool useProgress );
165 
166  bool m_isInitialized; //!< Is this instance already initialized?
167 
168  Filter::InputParameters m_inputParameters; //!< Input parameters.
169 
170  /*!
171  \brief Applay the Roberts filter over the source raster band.
172  \param srcRaster Source raster.
173  \param srcBandIdx Source raster band index.
174  \param dstRaster Destination raster.
175  \param dstBandIdx Destination raster band index.
176  \param useProgress if true, the progress interface must be used.
177  */
178  bool RobertsFilter( const te::rst::Raster& srcRaster,
179  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
180  const unsigned int dstBandIdx, const bool useProgress );
181 
182  /*!
183  \brief Applay the Sobel filter over the source raster band.
184  \param srcRaster Source raster.
185  \param srcBandIdx Source raster band index.
186  \param dstRaster Destination raster.
187  \param dstBandIdx Destination raster band index.
188  \param useProgress if true, the progress interface must be used.
189  */
190  bool SobelFilter( const te::rst::Raster& srcRaster,
191  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
192  const unsigned int dstBandIdx, const bool useProgress );
193 
194  /*!
195  \brief Applay the mean filter over the source raster band.
196  \param srcRaster Source raster.
197  \param srcBandIdx Source raster band index.
198  \param dstRaster Destination raster.
199  \param dstBandIdx Destination raster band index.
200  \param useProgress if true, the progress interface must be used.
201  */
202  bool MeanFilter( const te::rst::Raster& srcRaster,
203  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
204  const unsigned int dstBandIdx, const bool useProgress );
205 
206  /*!
207  \brief Applay the mode filter over the source raster band.
208  \param srcRaster Source raster.
209  \param srcBandIdx Source raster band index.
210  \param dstRaster Destination raster.
211  \param dstBandIdx Destination raster band index.
212  \param useProgress if true, the progress interface must be used.
213  */
214  bool ModeFilter( const te::rst::Raster& srcRaster,
215  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
216  const unsigned int dstBandIdx, const bool useProgress );
217 
218  /*!
219  \brief Applay the median filter over the source raster band.
220  \param srcRaster Source raster.
221  \param srcBandIdx Source raster band index.
222  \param dstRaster Destination raster.
223  \param dstBandIdx Destination raster band index.
224  \param useProgress if true, the progress interface must be used.
225  */
226  bool MedianFilter( const te::rst::Raster& srcRaster,
227  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
228  const unsigned int dstBandIdx, const bool useProgress );
229 
230  /*!
231  \brief Applay the dilation filter over the source raster band.
232  \param srcRaster Source raster.
233  \param srcBandIdx Source raster band index.
234  \param dstRaster Destination raster.
235  \param dstBandIdx Destination raster band index.
236  \param useProgress if true, the progress interface must be used.
237  */
238  bool DilationFilter( const te::rst::Raster& srcRaster,
239  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
240  const unsigned int dstBandIdx, const bool useProgress );
241 
242  /*!
243  \brief Applay the erosion filter over the source raster band.
244  \param srcRaster Source raster.
245  \param srcBandIdx Source raster band index.
246  \param dstRaster Destination raster.
247  \param dstBandIdx Destination raster band index.
248  \param useProgress if true, the progress interface must be used.
249  */
250  bool ErosionFilter( const te::rst::Raster& srcRaster,
251  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
252  const unsigned int dstBandIdx, const bool useProgress );
253 
254  /*!
255  \brief Applay the user defined filter over the source raster band.
256  \param srcRaster Source raster.
257  \param srcBandIdx Source raster band index.
258  \param dstRaster Destination raster.
259  \param dstBandIdx Destination raster band index.
260  \param useProgress if true, the progress interface must be used.
261  */
262  bool UserDefinedFilter( const te::rst::Raster& srcRaster,
263  const unsigned int srcBandIdx, te::rst::Raster& dstRaster,
264  const unsigned int dstBandIdx, const bool useProgress );
265 
266  /*!
267  \brief Returns true if i < j.
268  \return Returns true if i < j.
269  */
270  static bool OrderFunction(double i, double j);
271  };
272 
273  } // end namespace rp
274 } // end namespace te
275 
276 #endif
277 
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Filter.h:85
Base exception class for plugin module.
Definition: Exception.h:42
Raster Processing algorithm output parameters base interface.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Filter.h:113
Raster Processing algorithm base interface class.
unsigned int m_windowH
The height of the convolution window. (commonly 3, with W=3 to make a 3x3 window, and so on) ...
Definition: Filter.h:81
std::vector< unsigned int > m_inRasterBands
Bands to be used from the input raster 1.
Definition: Filter.h:77
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: Filter.h:115
Raster Processing algorithm base interface.
Definition: Algorithm.h:41
unsigned int m_iterationsNumber
The number of iterations to perform (default:1).
Definition: Filter.h:79
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
A series of well-known filtering algorithms for images, linear and non-linear..
Definition: Filter.h:47
Filter input parameters.
Definition: Filter.h:55
unsigned int m_windowW
The width of the convolution window.
Definition: Filter.h:83
FilterType m_filterType
The edge filter type.
Definition: Filter.h:73
Raster Processing algorithm input parameters base interface.
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
Definition: Filter.h:117
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Filter.h:75
Filter output parameters.
Definition: Filter.h:109
boost::numeric::ublas::matrix< double > m_window
User defined convolution window. (The size must be equal to m_windowH x m_windowW) ...
Definition: Filter.h:87