TiePointsLocatorMoravecStrategy.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/TiePointsLocatorMoravecStrategy.h
22  \brief Tie-Pointsr locator Moravec strategy.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_TIEPOINTSLOCATORMORAVECSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_TIEPOINTSLOCATORMORAVECSTRATEGY_H
27 
31 #include "../geometry/GeometricTransformation.h"
32 
33 #include <vector>
34 
35 #include <boost/thread.hpp>
36 
37 namespace te
38 {
39  namespace rp
40  {
41  /*!
42  \class TiePointsLocatorMoravecStrategy
43  \brief Tie-points locator Moravec strategy.
44  */
46  {
48 
49  public:
50 
51  /*!
52  \class Parameters
53  \brief TiePointsLocator Moravec strategy parameters
54  */
56  {
57  public:
58 
59  unsigned int m_moravecCorrelationWindowWidth; //!< The correlation window width used to correlate points between the images (minimum 3, default: 21, odd number).
60 
61  unsigned int m_moravecWindowWidth; //!< The Moravec window width used to locate canditate tie-points (minimum 3, default: 21, odd number ).
62 
63  unsigned int m_moravecNoiseFilterIterations; //!< The number of noise filter iterations, when applicable (used to remove image noise, zero will disable the noise Filter, default:1).
64 
65  double m_moravecMinAbsCorrelation; //!< The minimum acceptable absolute correlation value when matching features (when applicable), default:0.25, valid range: [0,1].
66 
67  Parameters();
68 
69  Parameters( const Parameters& );
70 
71  ~Parameters();
72 
73  //overload
74  void reset() throw( te::rp::Exception );
75 
76  //overload
77  const Parameters& operator=( const Parameters& params );
78 
79  //overload
80  AbstractParameters* clone() const;
81  };
82 
84 
85  //overload
86  void getSubSampledSpecStrategyParams(
87  const double subSampleOptimizationRescaleFactor,
88  const TiePointsLocatorStrategyParameters& inputSpecParams,
89  std::auto_ptr< TiePointsLocatorStrategyParameters >& subSampledSpecParamsPtr ) const;
90 
91  //overload
92  void getDefaultSpecStrategyParams(
93  std::auto_ptr< TiePointsLocatorStrategyParameters >& defaultSpecParamsPtr ) const;
94 
95  protected :
96 
97  /*!
98  \brief The parameters passed to the moravecLocatorThreadEntry method.
99  */
101  {
102  public :
103 
104  bool* m_returnValuePtr; //! Thread return value pointer.
105 
106  unsigned int m_moravecWindowWidth; //!< The Moravec window width used to locate canditate tie-points (minimum 11, default: 11 ).
107 
108  FloatsMatrix const* m_rasterDataPtr; //!< The loaded raster data.
109 
110  UCharsMatrix const* m_maskRasterDataPtr; //!< The loaded mask raster data pointer (or zero if no mask is avaliable).
111 
112  std::vector< InterestPointsSetT >* m_interestPointsSubSectorsPtr; //!< A pointer to a valid interest points container (one element by subsector)..
113 
114  unsigned int m_maxInterestPointsBySubSector; //!< The maximum number of interest points by sub-sector.
115 
116  unsigned int m_tiePointsSubSectorsSplitFactor; //!< The number of sectors along each direction.
117 
118  boost::mutex* m_rastaDataAccessMutexPtr; //!< A pointer to a valid mutex to controle raster data access.
119 
120  boost::mutex* m_interestPointsAccessMutexPtr; //!< A pointer to a valid mutex to control the output interest points container access.
121 
122  unsigned int m_processingBlocksNumber; //!< The raster data will be splitted into this number of blocks for processing.
123 
124  unsigned int* m_nextRasterLinesBlockToProcessValuePtr; //!< A pointer to a valid counter to control the blocks processing sequence.
125 
127 
129  };
130 
131  /*!
132  \brief The parameters passed to the matchCorrelationEuclideanThreadEntry method.
133  */
135  {
136  public :
137 
138  FloatsMatrix const* m_featuresSet1Ptr;
139 
140  FloatsMatrix const* m_featuresSet2Ptr;
141 
142  InterestPointT const* m_interestPointsSet1Ptr;
143 
144  InterestPointT const* m_interestPointsSet2Ptr;
145 
147 
148  FloatsMatrix* m_corrMatrixPtr;
149 
150  boost::mutex* m_syncMutexPtr;
151 
152  te::gm::GeometricTransformation const * m_raster1ToRaster2TransfPtr; //!< A pointer to a transformation direct mapping raster 1 indexed coords into raster 2 indexed coords, of an empty pointer if there is no transformation avaliable.
153 
154  double m_searchOptTreeSearchRadius; //!< Optimization tree search radius (pixels).
155 
157 
159  };
160 
161  bool m_isInitialized; //!< true if this instance is initialized.
162 
164 
166 
167  //overload
168  bool initialize(
169  const te::rp::TiePointsLocatorInputParameters& inputParameters );
170 
171  //overload
172  void reset();
173 
174  //overload
175  bool getMatchedInterestPoints(
176  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
177  const double raster1ToRaster2TransfDMapError,
178  MatchedInterestPointsSetT& matchedInterestPoints );
179 
180  //overload
181  unsigned int getAutoMaxTiePointsNumber() const;
182 
183  /*!
184  \brief Mean Filter.
185 
186  \param inputData The input data.
187 
188  \param outputData The output data.
189 
190  \param iterationsNumber The number of filter iterations.
191 
192  \return true if ok, false on errors.
193  */
194  static bool applyMeanFilter(
195  const FloatsMatrix& inputData,
196  FloatsMatrix& outputData,
197  const unsigned int iterationsNumber );
198 
199  /*!
200  \brief Moravec interest points locator.
201 
202  \param maxInterestPoints The maximum number of interest points to find.
203 
204  \param rasterData The loaded raster data.
205 
206  \param maskRasterDataPtr The loaded mask raster data pointer (or zero if no mask is avaliable).
207 
208  \param interestPoints The found interest points (coords related to rasterData lines/cols).
209 
210  \note InterestPointT::m_feature1 will be sum of differences between the Moravec filter response of each pixel and its neighborhoods (always a positive value).
211 
212  \return true if ok, false on errors.
213  */
214  bool locateMoravecInterestPoints(
215  const unsigned int maxInterestPoints,
216  const FloatsMatrix& rasterData,
217  UCharsMatrix const* maskRasterDataPtr,
218  InterestPointsSetT& interestPoints ) const;
219 
220  /*!
221  \brief Movavec locator thread entry.
222 
223  \param paramsPtr A pointer to the thread parameters.
224  */
225  static void locateMoravecInterestPointsThreadEntry(MoravecLocatorThreadParams* paramsPtr);
226 
227  /*!
228  \brief Generate correlation features ( normalized - unit vector ) matrix for the given interes points.
229 
230  \param interestPoints The interest points (coords related to rasterData lines/cols).
231 
232  \param correlationWindowWidth The correlation window width used to correlate points between the images.
233 
234  \param rasterData The loaded raster data.
235 
236  \param features The generated features matrix (one feature per line, one feature per interes point).
237 
238  \param validInteresPoints The valid interest pionts related to each feature inside the features matrix (some interest points may be invalid and are removed).
239 
240  \return true if ok, false on errors.
241  */
242  static bool generateCorrelationFeatures(
243  const InterestPointsSetT& interestPoints,
244  const unsigned int correlationWindowWidth,
245  const FloatsMatrix& rasterData,
246  FloatsMatrix& features,
247  InterestPointsSetT& validInteresPoints );
248 
249  /*!
250  \brief Match each feature using correlation.
251 
252  \param featuresSet1 Features set 1.
253 
254  \param featuresSet2 Features set 2.
255 
256  \param interestPointsSet1 The interest pionts set 1 (full raster 1 indexed coods reference).
257 
258  \param interestPointsSet2 The interest pionts set 2 (full raster 1 indexed coods reference).
259 
260  \param raster1ToRaster2TransfPtr A pointer to a transformation direct mapping raster 1 indexed coords into raster 2 indexed coords, of an empty pointer if there is no transformation avaliable.
261 
262  \param raster1ToRaster2TransfDMapError The expected transformation error.
263 
264  \param matchedPoints The matched points (full raster 1 indexed coods reference).
265 
266  \note Each matched point feature value ( MatchedInterestPoint::m_feature ) will be set to the absolute value of the correlation between then.
267  */
268  bool executeMatchingByCorrelation(
269  const FloatsMatrix& featuresSet1,
270  const FloatsMatrix& featuresSet2,
271  const InterestPointsSetT& interestPointsSet1,
272  const InterestPointsSetT& interestPointsSet2,
273  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
274  const double raster1ToRaster2TransfDMapError,
275  MatchedInterestPointsSetT& matchedPoints ) const;
276 
277  /*!
278  \brief Correlation/Euclidean match thread entry.
279 
280  \param paramsPtr A pointer to the thread parameters.
281  */
282  static void executeMatchingByCorrelationThreadEntry(
284  };
285 
286  /*!
287  \class TiePointsLocatorMoravecStrategyFactory
288  \brief Moravec tie-points locator strategy factory.
289  \note Factory key: Moravec
290  */
293  {
294  public:
295 
297 
299 
300  //overload
302 
303  };
304 
305  } // end namespace rp
306 } // end namespace te
307 
308 #endif
309 
te::rp::TiePointsLocatorInputParameters m_inputParameters
Input parameters.
std::vector< InterestPointsSetT > * m_interestPointsSubSectorsPtr
A pointer to a valid interest points container (one element by subsector)..
Tie Points Locator strategy parameters.
Base exception class for plugin module.
Definition: Exception.h:42
unsigned int m_moravecWindowWidth
The Moravec window width used to locate canditate tie-points (minimum 3, default: 21...
Raster tie points locator strategy factory base class.
2D Geometric transformation base class.
Moravec tie-points locator strategy factory.
Tie-Pointsr locator strategy.
te::gm::GeometricTransformation const * m_raster1ToRaster2TransfPtr
A pointer to a transformation direct mapping raster 1 indexed coords into raster 2 indexed coords...
unsigned int m_processingBlocksNumber
The raster data will be splitted into this number of blocks for processing.
URI C++ Library.
TiePointsLocator Moravec strategy parameters.
std::multiset< InterestPointT > InterestPointsSetT
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
bool m_isInitialized
true if this instance is initialized.
unsigned int m_moravecCorrelationWindowWidth
The correlation window width used to correlate points between the images (minimum 3...
unsigned int m_maxInterestPointsBySubSector
The maximum number of interest points by sub-sector.
The parameters passed to the matchCorrelationEuclideanThreadEntry method.
Tie-points locator strategy.
unsigned int m_moravecNoiseFilterIterations
The number of noise filter iterations, when applicable (used to remove image noise, zero will disable the noise Filter, default:1).
The parameters passed to the moravecLocatorThreadEntry method.
unsigned int m_tiePointsSubSectorsSplitFactor
The number of sectors along each direction.
A generic template matrix.
Definition: Matrix.h:51
boost::mutex * m_interestPointsAccessMutexPtr
A pointer to a valid mutex to control the output interest points container access.
UCharsMatrix const * m_maskRasterDataPtr
The loaded mask raster data pointer (or zero if no mask is avaliable).
Raster tie-points locator strategy factory base class.
unsigned int * m_nextRasterLinesBlockToProcessValuePtr
A pointer to a valid counter to control the blocks processing sequence.
std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT
double m_moravecMinAbsCorrelation
The minimum acceptable absolute correlation value when matching features (when applicable), default:0.25, valid range: [0,1].
boost::mutex * m_rastaDataAccessMutexPtr
A pointer to a valid mutex to controle raster data access.