MajorityFilter.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/MajorityFilter.h
22  \brief This file contains a class that represents the method to remove pixels from classified image.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_MAJORITYFILTER_H
26 #define __TERRALIB_RP_INTERNAL_MAJORITYFILTER_H
27 
28 #include "Algorithm.h"
29 #include "../raster/Raster.h"
30 
31 // STL
32 #include <vector>
33 
34 namespace te
35 {
36  namespace rp
37  {
38  /*!
39  \class MajorityFilter
40  \brief This file contains a class that represents the method to remove pixels from classified image.
41  \ingroup rp_enh
42  */
44  {
45  public:
46 
47  /*!
48  \class InputParameters
49  \brief Majority Filter input parameters
50  */
52  {
53  public:
54 
55  /*! \enum The majority filter type.*/
57  {
58  InvalidFilterT = 0,
59  SimpleFilterT = 1,
60  FullFilterT = 2
61  };
62 
63  MajorityFilterType m_filterType; //!< The majority filter type.
64 
65  te::rst::Raster const* m_inRasterPtr; //!< Input raster.
66 
67  std::vector< unsigned int > m_inRasterBands; //!< Bands to be used from the input raster.
68 
69  unsigned int m_npixels; //!< Number of pixels
70 
71  unsigned int m_neighbors; //!< Number of neighbors
72 
73  /*! \enum Replacement threshold*/
75  {
76  InvalidThreshold = 0,
77  MajorityThreshold = 1,
78  HalfThreshold = 2
79  };
80 
81  MajorityFilterThreshold m_threshold; //!< Replacement threshold
82 
83  bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
84 
86 
88 
89  ~InputParameters();
90 
91  //overload
92  void reset() _NOEXCEPT_OP(false);
93 
94  //overload
95  const InputParameters& operator=( const InputParameters& params );
96 
97  //overload
98  AbstractParameters* clone() const;
99  };
100 
101  /*!
102  \class OutputParameters
103  \brief Majority Filter output parameters
104  */
106  {
107  public:
108 
109  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
110 
111  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the raster (as described in te::raster::RasterFactory).
112 
113  std::unique_ptr< te::rst::Raster > m_outputRasterPtr; //!< A pointer the ge generated output raster (label image).
114 
116 
118 
119  ~OutputParameters();
120 
121  //overload
122  void reset() _NOEXCEPT_OP(false);
123 
124  //overload
125  const OutputParameters& operator=( const OutputParameters& params );
126 
127  //overload
128  AbstractParameters* clone() const;
129  };
130 
131  MajorityFilter();
132 
133  ~MajorityFilter();
134 
135  //overload
136  bool execute( AlgorithmOutputParameters& outputParams ) _NOEXCEPT_OP(false);
137 
138  //overload
139  void reset() _NOEXCEPT_OP(false);
140 
141  //overload
142  bool initialize( const AlgorithmInputParameters& inputParams ) _NOEXCEPT_OP(false);
143 
144  //overload
145  bool isInitialized() const;
146 
147  protected:
148 
149  bool m_isInitialized; //!< Is this instance already initialized?
150 
151  MajorityFilter::InputParameters m_inputParameters; //!< Input parameters.
152 
153  te::rst::Raster* m_outputRaster; //!< Output raster
154 
155  /*!
156  \brief Apply the simple majority filter over the source raster band.
157  \param srcRaster Source raster.
158  \param srcBandIdx Source raster band index.
159  \param dstBandIdx Destination raster band index.
160  \param useProgress if true, the progress interface must be used.
161  */
162  bool SimpleFilter(const te::rst::Raster& srcRaster, const unsigned int srcBandIdx,
163  const unsigned int dstBandIdx, const bool useProgress);
164 
165  /*!
166  \brief Apply the full majority filter over the source raster band.
167  \param srcRaster Source raster.
168  \param srcBandIdx Source raster band index.
169  \param dstBandIdx Destination raster band index.
170  \param useProgress if true, the progress interface must be used.
171  */
172  bool FullFilter(const te::rst::Raster& srcRaster, const unsigned int srcBandIdx,
173  const unsigned int dstBandIdx, const bool useProgress);
174 
175  /*!
176  \brief Find the neighbors (right, down, left and up) of the pixel located in a given column and row. This function is used in the simple filter.
177  \param dstBand Output raster band.
178  \param lcol Column of the current pixel
179  \param lrow Row of the current pixel
180  \param col Column of the neighbor pixel
181  \param row Row of the neighbor pixel
182  \param index Index from vector of columns and rows
183  \param totalPixel Total pixels found with same class as the current pixel
184  \param contClass Used to store the frequency of the classes
185  \param veccol Vector to store the columns of the pixels to change the class
186  \param vecrow Vector to store the rows of the pixels to change the class
187  */
188  void findNeighbors(te::rst::Band& dstBand, unsigned int lcol, unsigned int lrow, unsigned int col, unsigned int row,
189  int& index, int& totalPixel, int* contClass, std::vector<int>& veccol, std::vector<int>& vecrow);
190 
191  /*!
192  \brief Find the neighbors (right, down, left and up) of the pixel located in a given column and row. This function is used in the full filter.
193  \param dstBand Output raster band.
194  \param col Column of the current pixel
195  \param row Row of the current pixel
196  \param contClass Used to store the frequency of the classes
197  */
198  void find4Neighbors(te::rst::Band& dstBand, unsigned int col, unsigned int row, int* contClass);
199 
200  /*!
201  \brief Find the eight neighbors of the pixel located in a given column and row. This function is used in the full filter.
202  \param dstBand Output raster band.
203  \param col Column of the current pixel
204  \param row Row of the current pixel
205  \param contClass Used to store the frequency of the classes
206  */
207  void find8Neighbors(te::rst::Band& dstBand, unsigned int col, unsigned int row, int* contClass);
208  };
209 
210  } // end namespace rp
211 } // end namespace te
212 
213 #endif
214 
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Raster Processing algorithm output parameters base interface.
#define _NOEXCEPT_OP(x)
Majority Filter output parameters.
Raster Processing algorithm base interface class.
unsigned int m_npixels
Number of pixels.
Raster Processing algorithm base interface.
Definition: Algorithm.h:41
Majority Filter input parameters.
te::rst::Raster const * m_inRasterPtr
Input raster.
An abstract class for raster data strucutures.
Definition: Raster.h:71
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
std::vector< unsigned int > m_inRasterBands
Bands to be used from the input raster.
This file contains a class that represents the method to remove pixels from classified image...
unsigned int m_neighbors
Number of neighbors.
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
Raster Processing algorithm input parameters base interface.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
MajorityFilterThreshold m_threshold
Replacement threshold.
MajorityFilterType m_filterType
The majority filter type.