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 
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 
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 
132 
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 
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rp::AlgorithmOutputParameters
Raster Processing algorithm output parameters base interface.
Definition: AlgorithmOutputParameters.h:40
te::rp::MajorityFilter::OutputParameters::reset
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rp::MajorityFilter::InputParameters::m_enableProgress
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: MajorityFilter.h:83
te::rp::MajorityFilter::OutputParameters
Majority Filter output parameters.
Definition: MajorityFilter.h:106
te::rp::MajorityFilter
This file contains a class that represents the method to remove pixels from classified image.
Definition: MajorityFilter.h:44
te::rp::MajorityFilter::OutputParameters::m_outputRasterPtr
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
Definition: MajorityFilter.h:113
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::rp::MajorityFilter::InputParameters::InputParameters
InputParameters()
te::rp::AlgorithmInputParameters
Raster Processing algorithm input parameters base interface.
Definition: AlgorithmInputParameters.h:40
_NOEXCEPT_OP
#define _NOEXCEPT_OP(x)
Definition: NoExceptDefinition.h:36
te::rp::MajorityFilter::InputParameters::m_inRasterBands
std::vector< unsigned int > m_inRasterBands
Bands to be used from the input raster.
Definition: MajorityFilter.h:67
te::rp::MajorityFilter::OutputParameters::m_rType
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: MajorityFilter.h:109
te::rp::MajorityFilter::OutputParameters::OutputParameters
OutputParameters()
te::rp::MajorityFilter::InputParameters::m_filterType
MajorityFilterType m_filterType
The majority filter type.
Definition: MajorityFilter.h:63
te::rp::Algorithm
Raster Processing algorithm base interface.
Definition: Algorithm.h:42
te::rp::MajorityFilter::InputParameters::MajorityFilterThreshold
MajorityFilterThreshold
Definition: MajorityFilter.h:75
te::rp::MajorityFilter::InputParameters::~InputParameters
~InputParameters()
te::rp::MajorityFilter::OutputParameters::OutputParameters
OutputParameters(const OutputParameters &)
te::rp::MajorityFilter::OutputParameters::~OutputParameters
~OutputParameters()
TERPEXPORT
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
te::rp::MajorityFilter::InputParameters
Majority Filter input parameters.
Definition: MajorityFilter.h:52
te::rp::MajorityFilter::InputParameters::reset
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rp::MajorityFilter::OutputParameters::m_rInfo
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: MajorityFilter.h:111
te::rp::MajorityFilter::InputParameters::MajorityFilterType
MajorityFilterType
Definition: MajorityFilter.h:57
te::rp::MajorityFilter::InputParameters::m_inRasterPtr
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: MajorityFilter.h:65
te::rp::MajorityFilter::InputParameters::m_npixels
unsigned int m_npixels
Number of pixels.
Definition: MajorityFilter.h:69
Algorithm.h
Abstract algorithm.
te::rp::MajorityFilter::InputParameters::m_neighbors
unsigned int m_neighbors
Number of neighbors.
Definition: MajorityFilter.h:71
te::rp::MajorityFilter::InputParameters::m_threshold
MajorityFilterThreshold m_threshold
Replacement threshold.
Definition: MajorityFilter.h:81
te::rp::MajorityFilter::InputParameters::InputParameters
InputParameters(const InputParameters &)