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 
68 
70 
72 
73  //overload
74  void reset() ;
75 
76  //overload
77  const Parameters& operator=( const Parameters& params );
78 
79  //overload
80  AbstractParameters* clone() const;
81 
82  //overload
83  bool serialize ( AlgorithmParametersSerializer& serializer ) const;
84  };
85 
87 
88  //overload
90  const double subSampleOptimizationRescaleFactor,
91  const TiePointsLocatorStrategyParameters& inputSpecParams,
92  std::unique_ptr< TiePointsLocatorStrategyParameters >& subSampledSpecParamsPtr ) const;
93 
94  //overload
96  std::unique_ptr< TiePointsLocatorStrategyParameters >& defaultSpecParamsPtr ) const;
97 
98  protected :
99 
100  /*!
101  \brief The parameters passed to the moravecLocatorThreadEntry method.
102  */
104  {
105  public :
106 
107  bool* m_returnValuePtr; //! Thread return value pointer.
108 
109  unsigned int m_moravecWindowWidth; //!< The Moravec window width used to locate canditate tie-points (minimum 11, default: 11 ).
110 
111  FloatsMatrix const* m_rasterDataPtr; //!< The loaded raster data.
112 
113  UCharsMatrix const* m_maskRasterDataPtr; //!< The loaded mask raster data pointer (or zero if no mask is avaliable).
114 
115  std::vector< InterestPointsSetT >* m_interestPointsSubSectorsPtr; //!< A pointer to a valid interest points container (one element by subsector)..
116 
117  unsigned int m_maxInterestPointsBySubSector; //!< The maximum number of interest points by sub-sector.
118 
119  unsigned int m_tiePointsSubSectorsSplitFactor; //!< The number of sectors along each direction.
120 
121  boost::mutex* m_rastaDataAccessMutexPtr; //!< A pointer to a valid mutex to controle raster data access.
122 
123  boost::mutex* m_interestPointsAccessMutexPtr; //!< A pointer to a valid mutex to control the output interest points container access.
124 
125  unsigned int m_processingBlocksNumber; //!< The raster data will be splitted into this number of blocks for processing.
126 
127  unsigned int* m_nextRasterLinesBlockToProcessValuePtr; //!< A pointer to a valid counter to control the blocks processing sequence.
128 
130 
132  };
133 
134  /*!
135  \brief The parameters passed to the matchCorrelationEuclideanThreadEntry method.
136  */
138  {
139  public :
140 
142 
144 
146 
148 
150 
152 
153  boost::mutex* m_syncMutexPtr;
154 
155  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.
156 
157  double m_searchOptTreeSearchRadius; //!< Optimization tree search radius (pixels).
158 
160 
162  };
163 
164  bool m_isInitialized; //!< true if this instance is initialized.
165 
167 
169 
170  //overload
171  bool initialize(
172  const te::rp::TiePointsLocatorInputParameters& inputParameters );
173 
174  //overload
175  void reset();
176 
177  //overload
179  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
180  const double raster1ToRaster2TransfDMapError,
181  MatchedInterestPointsSetT& matchedInterestPoints );
182 
183  //overload
184  unsigned int getAutoMaxTiePointsNumber() const;
185 
186  /*!
187  \brief Mean Filter.
188 
189  \param inputData The input data.
190 
191  \param outputData The output data.
192 
193  \param iterationsNumber The number of filter iterations.
194 
195  \return true if ok, false on errors.
196  */
197  static bool applyMeanFilter(
198  const FloatsMatrix& inputData,
199  FloatsMatrix& outputData,
200  const unsigned int iterationsNumber );
201 
202  /*!
203  \brief Moravec interest points locator.
204 
205  \param maxInterestPoints The maximum number of interest points to find.
206 
207  \param rasterData The loaded raster data.
208 
209  \param maskRasterDataPtr The loaded mask raster data pointer (or zero if no mask is avaliable).
210 
211  \param interestPoints The found interest points (coords related to rasterData lines/cols).
212 
213  \note InterestPointT::m_feature1 will be sum of differences between the Moravec filter response of each pixel and its neighborhoods (always a positive value).
214 
215  \return true if ok, false on errors.
216  */
218  const unsigned int maxInterestPoints,
219  const FloatsMatrix& rasterData,
220  UCharsMatrix const* maskRasterDataPtr,
221  InterestPointsSetT& interestPoints ) const;
222 
223  /*!
224  \brief Movavec locator thread entry.
225 
226  \param paramsPtr A pointer to the thread parameters.
227  */
229 
230  /*!
231  \brief Generate correlation features ( normalized - unit vector ) matrix for the given interes points.
232 
233  \param interestPoints The interest points (coords related to rasterData lines/cols).
234 
235  \param correlationWindowWidth The correlation window width used to correlate points between the images.
236 
237  \param rasterData The loaded raster data.
238 
239  \param features The generated features matrix (one feature per line, one feature per interes point).
240 
241  \param validInteresPoints The valid interest pionts related to each feature inside the features matrix (some interest points may be invalid and are removed).
242 
243  \return true if ok, false on errors.
244  */
246  const InterestPointsSetT& interestPoints,
247  const unsigned int correlationWindowWidth,
248  const FloatsMatrix& rasterData,
249  FloatsMatrix& features,
250  InterestPointsSetT& validInteresPoints );
251 
252  /*!
253  \brief Match each feature using correlation.
254 
255  \param featuresSet1 Features set 1.
256 
257  \param featuresSet2 Features set 2.
258 
259  \param interestPointsSet1 The interest pionts set 1 (full raster 1 indexed coods reference).
260 
261  \param interestPointsSet2 The interest pionts set 2 (full raster 1 indexed coods reference).
262 
263  \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.
264 
265  \param raster1ToRaster2TransfDMapError The expected transformation error.
266 
267  \param matchedPoints The matched points (full raster 1 indexed coods reference).
268 
269  \note Each matched point feature value ( MatchedInterestPoint::m_feature ) will be set to the absolute value of the correlation between then.
270  */
272  const FloatsMatrix& featuresSet1,
273  const FloatsMatrix& featuresSet2,
274  const InterestPointsSetT& interestPointsSet1,
275  const InterestPointsSetT& interestPointsSet2,
276  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
277  const double raster1ToRaster2TransfDMapError,
278  MatchedInterestPointsSetT& matchedPoints );
279 
280  /*!
281  \brief Correlation/Euclidean match thread entry.
282 
283  \param paramsPtr A pointer to the thread parameters.
284  */
287  };
288 
289  /*!
290  \class TiePointsLocatorMoravecStrategyFactory
291  \brief Moravec tie-points locator strategy factory.
292  \note Factory key: Moravec
293  */
296  {
297  public:
298 
300 
302 
303  //overload
305 
306  };
307 
308  } // end namespace rp
309 } // end namespace te
310 
311 #endif
312 
Raster tie points locator strategy factory base class.
Tie Points Locator strategy parameters.
Tie-Pointsr locator strategy.
2D Geometric transformation base class.
A class to standardize algorithm parameters serialization.
A generic template matrix.
Definition: Matrix.h:55
Moravec tie-points locator strategy factory.
te::rp::TiePointsLocatorStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects.
The parameters passed to the matchCorrelationEuclideanThreadEntry method.
te::gm::GeometricTransformation const * m_raster1ToRaster2TransfPtr
A pointer to a transformation direct mapping raster 1 indexed coords into raster 2 indexed coords,...
The parameters passed to the moravecLocatorThreadEntry method.
unsigned int * m_nextRasterLinesBlockToProcessValuePtr
A pointer to a valid counter to control the blocks processing sequence.
unsigned int m_tiePointsSubSectorsSplitFactor
The number of sectors along each direction.
UCharsMatrix const * m_maskRasterDataPtr
The loaded mask raster data pointer (or zero if no mask is avaliable).
boost::mutex * m_rastaDataAccessMutexPtr
A pointer to a valid mutex to controle raster data access.
unsigned int m_maxInterestPointsBySubSector
The maximum number of interest points by sub-sector.
std::vector< InterestPointsSetT > * m_interestPointsSubSectorsPtr
A pointer to a valid interest points container (one element by subsector)..
boost::mutex * m_interestPointsAccessMutexPtr
A pointer to a valid mutex to control the output interest points container access.
unsigned int m_processingBlocksNumber
The raster data will be splitted into this number of blocks for processing.
bool serialize(AlgorithmParametersSerializer &serializer) const
Returns a parameter serialization object.
unsigned int m_moravecNoiseFilterIterations
The number of noise filter iterations, when applicable (used to remove image noise,...
double m_moravecMinAbsCorrelation
The minimum acceptable absolute correlation value when matching features (when applicable),...
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
unsigned int m_moravecCorrelationWindowWidth
The correlation window width used to correlate points between the images (minimum 3,...
unsigned int m_moravecWindowWidth
The Moravec window width used to locate canditate tie-points (minimum 3, default: 21,...
AbstractParameters * clone() const
Create a clone copy of this instance.
const Parameters & operator=(const Parameters &params)
bool m_isInitialized
true if this instance is initialized.
bool executeMatchingByCorrelation(const FloatsMatrix &featuresSet1, const FloatsMatrix &featuresSet2, const InterestPointsSetT &interestPointsSet1, const InterestPointsSetT &interestPointsSet2, te::gm::GeometricTransformation const *const raster1ToRaster2TransfPtr, const double raster1ToRaster2TransfDMapError, MatchedInterestPointsSetT &matchedPoints)
Match each feature using correlation.
static bool applyMeanFilter(const FloatsMatrix &inputData, FloatsMatrix &outputData, const unsigned int iterationsNumber)
Mean Filter.
bool getMatchedInterestPoints(te::gm::GeometricTransformation const *const raster1ToRaster2TransfPtr, const double raster1ToRaster2TransfDMapError, MatchedInterestPointsSetT &matchedInterestPoints)
Try to find matched interest points.
bool initialize(const te::rp::TiePointsLocatorInputParameters &inputParameters)
Initialize the strategy.
te::rp::TiePointsLocatorInputParameters m_inputParameters
Input parameters.
static void locateMoravecInterestPointsThreadEntry(MoravecLocatorThreadParams *paramsPtr)
Movavec locator thread entry.
unsigned int getAutoMaxTiePointsNumber() const
Returns a automatically calculated optimum maximum amount tie-points following the current parameters...
bool locateMoravecInterestPoints(const unsigned int maxInterestPoints, const FloatsMatrix &rasterData, UCharsMatrix const *maskRasterDataPtr, InterestPointsSetT &interestPoints) const
Moravec interest points locator.
void reset()
Clear all internal allocated resources and go back to the initial not-initialized state.
void getSubSampledSpecStrategyParams(const double subSampleOptimizationRescaleFactor, const TiePointsLocatorStrategyParameters &inputSpecParams, std::unique_ptr< TiePointsLocatorStrategyParameters > &subSampledSpecParamsPtr) const
Returns a sub-sampled version of the given locator strategy specific input parameters.
void getDefaultSpecStrategyParams(std::unique_ptr< TiePointsLocatorStrategyParameters > &defaultSpecParamsPtr) const
Returns a sub-sampled version of the given locator strategy specific input parameters.
static void executeMatchingByCorrelationThreadEntry(ExecuteMatchingByCorrelationThreadEntryParams *paramsPtr)
Correlation/Euclidean match thread entry.
static bool generateCorrelationFeatures(const InterestPointsSetT &interestPoints, const unsigned int correlationWindowWidth, const FloatsMatrix &rasterData, FloatsMatrix &features, InterestPointsSetT &validInteresPoints)
Generate correlation features ( normalized - unit vector ) matrix for the given interes points.
Raster tie-points locator strategy factory base class.
std::multiset< InterestPointT > InterestPointsSetT
std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139