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() 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::unique_ptr< TiePointsLocatorStrategyParameters >& subSampledSpecParamsPtr ) const;
90 
91  //overload
92  void getDefaultSpecStrategyParams(
93  std::unique_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
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  */
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  */
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  */
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  */
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 );
276 
277  /*!
278  \brief Correlation/Euclidean match thread entry.
279 
280  \param paramsPtr A pointer to the thread parameters.
281  */
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::Matrix
A generic template matrix.
Definition: Matrix.h:55
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::~ExecuteMatchingByCorrelationThreadEntryParams
~ExecuteMatchingByCorrelationThreadEntryParams()
Definition: TiePointsLocatorMoravecStrategy.h:158
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_rastaDataAccessMutexPtr
boost::mutex * m_rastaDataAccessMutexPtr
A pointer to a valid mutex to controle raster data access.
Definition: TiePointsLocatorMoravecStrategy.h:118
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams
The parameters passed to the matchCorrelationEuclideanThreadEntry method.
Definition: TiePointsLocatorMoravecStrategy.h:135
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_interestPointsAccessMutexPtr
boost::mutex * m_interestPointsAccessMutexPtr
A pointer to a valid mutex to control the output interest points container access.
Definition: TiePointsLocatorMoravecStrategy.h:120
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_processingBlocksNumber
unsigned int m_processingBlocksNumber
The raster data will be splitted into this number of blocks for processing.
Definition: TiePointsLocatorMoravecStrategy.h:122
te::rp::TiePointsLocatorMoravecStrategyFactory::~TiePointsLocatorMoravecStrategyFactory
~TiePointsLocatorMoravecStrategyFactory()
te::rp::TiePointsLocatorMoravecStrategy::Parameters
TiePointsLocator Moravec strategy parameters.
Definition: TiePointsLocatorMoravecStrategy.h:56
te::rp::TiePointsLocatorMoravecStrategy::executeMatchingByCorrelation
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.
te::rp::TiePointsLocatorMoravecStrategy::TiePointsLocatorMoravecStrategy
TiePointsLocatorMoravecStrategy()
te::rp::TiePointsLocatorMoravecStrategy::Parameters::~Parameters
~Parameters()
te::rp::TiePointsLocatorMoravecStrategy::Parameters::reset
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state.
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_tiePointsSubSectorsSplitFactor
unsigned int m_tiePointsSubSectorsSplitFactor
The number of sectors along each direction.
Definition: TiePointsLocatorMoravecStrategy.h:116
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::~MoravecLocatorThreadParams
~MoravecLocatorThreadParams()
Definition: TiePointsLocatorMoravecStrategy.h:128
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::MoravecLocatorThreadParams
MoravecLocatorThreadParams()
Definition: TiePointsLocatorMoravecStrategy.h:126
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_featuresSet2Ptr
FloatsMatrix const * m_featuresSet2Ptr
Definition: TiePointsLocatorMoravecStrategy.h:140
te::rp::TiePointsLocatorMoravecStrategy
Tie-points locator Moravec strategy.
Definition: TiePointsLocatorMoravecStrategy.h:46
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_interestPointsSubSectorsPtr
std::vector< InterestPointsSetT > * m_interestPointsSubSectorsPtr
A pointer to a valid interest points container (one element by subsector)..
Definition: TiePointsLocatorMoravecStrategy.h:112
te::rp::TiePointsLocatorMoravecStrategy::m_isInitialized
bool m_isInitialized
true if this instance is initialized.
Definition: TiePointsLocatorMoravecStrategy.h:161
TiePointsLocatorStrategyFactory.h
Raster tie points locator strategy factory base class.
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_searchOptTreeSearchRadius
double m_searchOptTreeSearchRadius
Optimization tree search radius (pixels).
Definition: TiePointsLocatorMoravecStrategy.h:154
TiePointsLocatorStrategy.h
Tie-Pointsr locator strategy.
te::rp::TiePointsLocatorMoravecStrategy::generateCorrelationFeatures
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.
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams
The parameters passed to the moravecLocatorThreadEntry method.
Definition: TiePointsLocatorMoravecStrategy.h:101
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_nextRasterLinesBlockToProcessValuePtr
unsigned int * m_nextRasterLinesBlockToProcessValuePtr
A pointer to a valid counter to control the blocks processing sequence.
Definition: TiePointsLocatorMoravecStrategy.h:124
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_corrMatrixPtr
FloatsMatrix * m_corrMatrixPtr
Definition: TiePointsLocatorMoravecStrategy.h:148
te::rp::TiePointsLocatorMoravecStrategy::reset
void reset()
Clear all internal allocated resources and go back to the initial not-initialized state.
te::rp::TiePointsLocatorMoravecStrategy::locateMoravecInterestPointsThreadEntry
static void locateMoravecInterestPointsThreadEntry(MoravecLocatorThreadParams *paramsPtr)
Movavec locator thread entry.
TiePointsLocatorStrategyParameters.h
Tie Points Locator strategy parameters.
te::rp::TiePointsLocatorMoravecStrategy::initialize
bool initialize(const te::rp::TiePointsLocatorInputParameters &inputParameters)
Initialize the strategy.
te::rp::TiePointsLocatorStrategyFactory
Raster tie-points locator strategy factory base class.
Definition: TiePointsLocatorStrategyFactory.h:46
te::rp::TiePointsLocatorMoravecStrategy::locateMoravecInterestPoints
bool locateMoravecInterestPoints(const unsigned int maxInterestPoints, const FloatsMatrix &rasterData, UCharsMatrix const *maskRasterDataPtr, InterestPointsSetT &interestPoints) const
Moravec interest points locator.
te::Exception
Base exception class for plugin module.
Definition: Exception.h:42
te::rp::TiePointsLocatorMoravecStrategy::m_inputParameters
te::rp::TiePointsLocatorInputParameters m_inputParameters
Input parameters.
Definition: TiePointsLocatorMoravecStrategy.h:163
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_maskRasterDataPtr
UCharsMatrix const * m_maskRasterDataPtr
The loaded mask raster data pointer (or zero if no mask is avaliable).
Definition: TiePointsLocatorMoravecStrategy.h:110
te::rp::TiePointsLocatorMoravecStrategy::Parameters::Parameters
Parameters(const Parameters &)
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_moravecWindowWidth
unsigned int m_moravecWindowWidth
Thread return value pointer.
Definition: TiePointsLocatorMoravecStrategy.h:106
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_featuresSet1Ptr
FloatsMatrix const * m_featuresSet1Ptr
Definition: TiePointsLocatorMoravecStrategy.h:138
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::TiePointsLocatorMoravecStrategy::Parameters::m_moravecCorrelationWindowWidth
unsigned int m_moravecCorrelationWindowWidth
The correlation window width used to correlate points between the images (minimum 3,...
Definition: TiePointsLocatorMoravecStrategy.h:59
te::rp::TiePointsLocatorMoravecStrategy::Parameters::Parameters
Parameters()
te::rp::TiePointsLocatorMoravecStrategy::getAutoMaxTiePointsNumber
unsigned int getAutoMaxTiePointsNumber() const
Returns a automatically calculated optimum maximum amount tie-points following the current parameters...
te::rp::TiePointsLocatorStrategyParameters
TiePointsLocator strategy parameters.
Definition: TiePointsLocatorStrategyParameters.h:39
te::rp::TiePointsLocatorStrategy::InterestPointsSetT
std::multiset< InterestPointT > InterestPointsSetT
Definition: TiePointsLocatorStrategy.h:152
te::rp::TiePointsLocatorStrategy
Tie-points locator strategy.
Definition: TiePointsLocatorStrategy.h:53
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::ExecuteMatchingByCorrelationThreadEntryParams
ExecuteMatchingByCorrelationThreadEntryParams()
Definition: TiePointsLocatorMoravecStrategy.h:156
te::rp::TiePointsLocatorMoravecStrategyFactory::TiePointsLocatorMoravecStrategyFactory
TiePointsLocatorMoravecStrategyFactory()
te::rp::TiePointsLocatorMoravecStrategy::Parameters::m_moravecMinAbsCorrelation
double m_moravecMinAbsCorrelation
The minimum acceptable absolute correlation value when matching features (when applicable),...
Definition: TiePointsLocatorMoravecStrategy.h:65
te::rp::TiePointsLocatorMoravecStrategyFactory
Moravec tie-points locator strategy factory.
Definition: TiePointsLocatorMoravecStrategy.h:293
te::rp::TiePointsLocatorStrategy::MatchedInterestPointsSetT
std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT
Definition: TiePointsLocatorStrategy.h:199
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_maxInterestPointsBySubSector
unsigned int m_maxInterestPointsBySubSector
The maximum number of interest points by sub-sector.
Definition: TiePointsLocatorMoravecStrategy.h:114
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_rasterDataPtr
FloatsMatrix const * m_rasterDataPtr
The loaded raster data.
Definition: TiePointsLocatorMoravecStrategy.h:108
te::gm::GeometricTransformation
2D Geometric transformation base class.
Definition: GeometricTransformation.h:57
te::rp::TiePointsLocatorMoravecStrategy::getMatchedInterestPoints
bool getMatchedInterestPoints(te::gm::GeometricTransformation const *const raster1ToRaster2TransfPtr, const double raster1ToRaster2TransfDMapError, MatchedInterestPointsSetT &matchedInterestPoints)
Try to find matched interest points.
te::rp::TiePointsLocatorMoravecStrategy::MoravecLocatorThreadParams::m_returnValuePtr
bool * m_returnValuePtr
Definition: TiePointsLocatorMoravecStrategy.h:104
te::rp::TiePointsLocatorMoravecStrategyFactory::build
te::rp::TiePointsLocatorStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects.
te::rp::TiePointsLocatorInputParameters
TiePointsLocator input parameters.
Definition: TiePointsLocatorInputParameters.h:49
te::rp::TiePointsLocatorMoravecStrategy::applyMeanFilter
static bool applyMeanFilter(const FloatsMatrix &inputData, FloatsMatrix &outputData, const unsigned int iterationsNumber)
Mean Filter.
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_raster1ToRaster2TransfPtr
te::gm::GeometricTransformation const * m_raster1ToRaster2TransfPtr
A pointer to a transformation direct mapping raster 1 indexed coords into raster 2 indexed coords,...
Definition: TiePointsLocatorMoravecStrategy.h:152
te::rp::TiePointsLocatorMoravecStrategy::Parameters::m_moravecWindowWidth
unsigned int m_moravecWindowWidth
The Moravec window width used to locate canditate tie-points (minimum 3, default: 21,...
Definition: TiePointsLocatorMoravecStrategy.h:61
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_interestPointsSet2Ptr
InterestPointT const * m_interestPointsSet2Ptr
Definition: TiePointsLocatorMoravecStrategy.h:144
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_nextFeatureIdx1ToProcessPtr
unsigned int * m_nextFeatureIdx1ToProcessPtr
Definition: TiePointsLocatorMoravecStrategy.h:146
te::rp::TiePointsLocatorMoravecStrategy::executeMatchingByCorrelationThreadEntry
static void executeMatchingByCorrelationThreadEntry(ExecuteMatchingByCorrelationThreadEntryParams *paramsPtr)
Correlation/Euclidean match thread entry.
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_interestPointsSet1Ptr
InterestPointT const * m_interestPointsSet1Ptr
Definition: TiePointsLocatorMoravecStrategy.h:142
te::rp::TiePointsLocatorMoravecStrategy::ExecuteMatchingByCorrelationThreadEntryParams::m_syncMutexPtr
boost::mutex * m_syncMutexPtr
Definition: TiePointsLocatorMoravecStrategy.h:150
te::rp::TiePointsLocatorMoravecStrategy::Parameters::m_moravecNoiseFilterIterations
unsigned int m_moravecNoiseFilterIterations
The number of noise filter iterations, when applicable (used to remove image noise,...
Definition: TiePointsLocatorMoravecStrategy.h:63