TiePointsLocatorSURFStrategy.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/TiePointsLocatorSURFStrategy.h
22  \brief Tie-Pointsr locator SURF strategy.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_TIEPOINTSLOCATORSURFSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_TIEPOINTSLOCATORSURFSTRATEGY_H
27 
31 
32 #include <boost/thread.hpp>
33 
34 #include <cmath>
35 
36 namespace te
37 {
38  namespace rp
39  {
40  /*!
41  \class TiePointsLocatorSURFStrategy
42  \brief Tie-points locator SURF strategy.
43  */
45  {
47 
48  public:
49 
50  /*!
51  \class Parameters
52  \brief TiePointsLocator SURF strategy parameters.
53  */
55  {
56  public:
57 
58  unsigned int m_surfScalesNumber; //!< The number of sub-sampling scales to generate, when applicable (default:3, minimum:3).
59 
60  unsigned int m_surfOctavesNumber; //!< The number of octaves to generate, when applicable (default: 2, minimum:2).
61 
62  double m_surfMaxNormEuclideanDist; //!< The maximum acceptable euclidean distance when matching features (when applicable), default:0.75, valid range: [0,1].
63 
64  Parameters();
65 
66  Parameters( const Parameters& );
67 
68  ~Parameters();
69 
70  //overload
71  void reset() throw( te::rp::Exception );
72 
73  //overload
74  const Parameters& operator=( const Parameters& params );
75 
76  //overload
77  AbstractParameters* clone() const;
78  };
79 
81 
82  //overload
83  void getSubSampledSpecStrategyParams(
84  const double subSampleOptimizationRescaleFactor,
85  const TiePointsLocatorStrategyParameters& inputSpecParams,
86  std::auto_ptr< TiePointsLocatorStrategyParameters >& subSampledSpecParamsPtr ) const;
87 
88  //overload
89  void getDefaultSpecStrategyParams(
90  std::auto_ptr< TiePointsLocatorStrategyParameters >& defaultSpecParamsPtr ) const;
91 
92  protected :
93 
94  /*!
95  \brief The parameters passed to the surfLocatorThreadEntry method.
96  */
98  {
99  public :
100 
101  bool* m_returnValuePtr; //! Thread return value pointer.
102 
103  unsigned int m_scalesNumber; //!< The number of sub-samples scales to generate (minimum:3).
104 
105  unsigned int m_octavesNumber; //!< The number of octaves to generate (minimum:1).
106 
107  std::vector< InterestPointsSetT >* m_interestPointsSubSectorsPtr; //!< A pointer to a valid interest points container (one element by subsector)..
108 
109  unsigned int m_maxInterestPointsBySubSector; //!< The maximum number of interest points by sub-sector.
110 
111  unsigned int m_tiePointsSubSectorsSplitFactor; //!< The number of sectors along each direction.
112 
113  FloatsMatrix const* m_integralRasterDataPtr; //!< The integral image raster data.
114 
115  UCharsMatrix const* m_maskRasterDataPtr; //!< The loaded mask raster data pointer (or zero if no mask is avaliable).
116 
117  boost::mutex* m_rastaDataAccessMutexPtr; //!< A pointer to a valid mutex to controle raster data access.
118 
119  boost::mutex* m_interestPointsAccessMutexPtr; //!< A pointer to a valid mutex to control the output interest points container access.
120 
121  unsigned int m_processingBlocksNumber; //!< The raster data will be splitted into this number of blocks for processing.
122 
123  unsigned int* m_nextRasterLinesBlockToProcessValuePtr; //!< A pointer to a valid counter to control the blocks processing sequence.
124 
126 
128  };
129 
130  /*!
131  \brief The parameters passed to the executeMatchingByEuclideanDistThreadEntry method.
132  */
134  {
135  public :
136 
138 
140 
142 
144 
146 
148 
149  boost::mutex* m_syncMutexPtr;
150 
151  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.
152 
153  double m_searchOptTreeSearchRadius; //!< Optimization tree search radius (pixels).
154 
156 
158  };
159 
160  bool m_isInitialized; //!< true if this instance is initialized.
161 
163 
165 
166  //overload
167  bool initialize(
168  const te::rp::TiePointsLocatorInputParameters& inputParameters );
169 
170  //overload
171  void reset();
172 
173  //overload
174  bool getMatchedInterestPoints(
175  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
176  const double raster1ToRaster2TransfDMapError,
177  MatchedInterestPointsSetT& matchedInterestPoints );
178 
179  //overload
180  unsigned int getAutoMaxTiePointsNumber() const;
181 
182  /*!
183  \brief Create an integral image.
184 
185  \param inputData The input data.
186 
187  \param outputData The output data.
188 
189  \note The entry of an integral image IΣ(x) at a location x = (x, y) represents the sum of all pixels in the input image I of a rectangular region formed by the point x and the origi.
190 
191  \return true if ok, false on errors.
192  */
193  static bool createIntegralImage(
194  const FloatsMatrix& inputData,
195  FloatsMatrix& outputData );
196 
197  /*!
198  \brief SURF interest points locator.
199 
200  \param maxInterestPoints The maximum number of interest points to find.
201 
202  \param integralRasterData Integral image raster data.
203 
204  \param maskRasterDataPtr The loaded mask raster data pointer (or zero if no mask is avaliable).
205 
206  \param interestPoints The found interest points (coords related to rasterData lines/cols).
207 
208  \return true if ok, false on errors.
209 
210  \note InterestPointT::m_feature1 will be sum of differences between the hessian matrix determinant each pixel and its neighborhoods (always a positive value).
211 
212  \note InterestPointT::m_feature2 will be used filter width (pixels).
213 
214  \note InterestPointT::m_feature3 will 1 if the laplacian sign is positive, or zero if negative.
215  */
216  bool locateSurfInterestPoints(
217  const unsigned int maxInterestPoints,
218  const FloatsMatrix& integralRasterData,
219  UCharsMatrix const* maskRasterDataPtr,
220  InterestPointsSetT& interestPoints ) const;
221 
222  /*!
223  \brief Surf locator thread entry.
224 
225  \param paramsPtr A pointer to the thread parameters.
226  */
227  static void locateSurfInterestPointsThreadEntry(SurfLocatorThreadParams* paramsPtr);
228 
229  /*!
230  \brief Generate a Surf features matrix for the given interes points.
231 
232  \param interestPoints The interest points (coords related to rasterData lines/cols).
233 
234  \param integralRasterData The integral raster data.
235 
236  \param validInterestPoints The valid interest points.
237 
238  \param features The generated features matrix (one feature per line, one feature per interest point).
239 
240  \return true if ok, false on errors.
241  */
242  static bool generateSurfFeatures(
243  const InterestPointsSetT& interestPoints,
244  const FloatsMatrix& integralRasterData,
245  InterestPointsSetT& validInterestPoints,
246  FloatsMatrix& features );
247 
248  /*!
249  \brief Match each feature using eucliean distance.
250 
251  \param featuresSet1 Features set 1.
252 
253  \param featuresSet2 Features set 2.
254 
255  \param interestPointsSet1 The interest pionts set 1 (full raster 1 indexed coods reference)..
256 
257  \param interestPointsSet2 The interest pionts set 2 (full raster 1 indexed coods reference)..
258 
259  \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.
260 
261  \param raster1ToRaster2TransfDMapError The expected transformation error.
262 
263  \param matchedPoints The matched points.
264 
265  \note Each matched point feature value ( MatchedInterestPoint::m_feature ) will be set to the distance value between both features.
266  */
267  bool executeMatchingByEuclideanDist(
268  const FloatsMatrix& featuresSet1,
269  const FloatsMatrix& featuresSet2,
270  const InterestPointsSetT& interestPointsSet1,
271  const InterestPointsSetT& interestPointsSet2,
272  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
273  const double raster1ToRaster2TransfDMapError,
274  MatchedInterestPointsSetT& matchedPoints ) const;
275 
276  /*!
277  \brief Correlation/Euclidean match thread entry.
278 
279  \param paramsPtr A pointer to the thread parameters.
280  */
281  static void executeMatchingByEuclideanDistThreadEntry(
283 
284  /*!
285  \brief Return a sum of all pixels inside a box over the given integral image buffer.
286 
287  \param bufferPtr Buffer pointer.
288 
289  \param upperLeftX Box upper left X.
290 
291  \param upperLeftY Box upper left Y.
292 
293  \param lowerRightX Box lower right X.
294 
295  \param lowerRightY Box lower right X.
296  */
297  template< typename BufferType >
298  inline static float getIntegralBoxSum( BufferType& buffer,
299  const unsigned int& upperLeftX, const unsigned int& upperLeftY,
300  const unsigned int& lowerRightX, const unsigned int& lowerRightY )
301  {
302  return buffer[ lowerRightY ][ lowerRightX ]
303  - ( ( upperLeftY ) ? buffer[ upperLeftY - 1 ][ lowerRightX ] : 0 )
304  - ( ( upperLeftX ) ? buffer[ lowerRightY ][ upperLeftX - 1 ] : 0 )
305  + ( ( ( upperLeftX != 0 ) && ( upperLeftY != 0 ) ) ? buffer[ upperLeftY - 1 ][ upperLeftX - 1 ] : 0 );
306  }
307 
308  /*!
309  \brief Return a SURF box filter Dxx derivative centered over the given position from the given integral image buffer.
310 
311  \param bufferPtr Buffer pointer.
312 
313  \param centerX Center X.
314 
315  \param centerY Center Y.
316 
317  \param lobeWidth Filter lobe width.
318 
319  \param lobeRadius Filter lobe radius.
320  */
321  inline static float getSurfDyyDerivative( float** bufferPtr,
322  const unsigned int& centerX, const unsigned int& centerY,
323  const unsigned int& lobeWidth, const unsigned int& lobeRadius )
324  {
325  return
326  getIntegralBoxSum(
327  bufferPtr,
328  ( centerX + 1 - lobeWidth ),
329  ( centerY - lobeWidth - lobeRadius ),
330  ( centerX + lobeWidth - 1 ),
331  ( centerY + lobeWidth + lobeRadius ) )
332  - ( 3.0f *
333  getIntegralBoxSum(
334  bufferPtr,
335  ( centerX + 1 - lobeWidth ),
336  ( centerY - lobeRadius ),
337  ( centerX + lobeWidth - 1 ),
338  ( centerY + lobeRadius ) ) );
339  };
340 
341  /*!
342  \brief Return a SURF box filter Dyy derivative centered over the given position from the given integral image buffer.
343 
344  \param bufferPtr Buffer pointer.
345 
346  \param centerX Center X.
347 
348  \param centerY Center Y.
349 
350  \param lobeWidth Filter lobe width.
351 
352  \param lobeRadius Filter lobe radius.
353  */
354  inline static float getSurfDxxDerivative( float** bufferPtr,
355  const unsigned int& centerX, const unsigned int& centerY,
356  const unsigned int& lobeWidth, const unsigned int& lobeRadius )
357  {
358  return
359  getIntegralBoxSum(
360  bufferPtr,
361  ( centerX - lobeWidth - lobeRadius ),
362  ( centerY + 1 - lobeWidth ),
363  ( centerX + lobeWidth + lobeRadius ),
364  ( centerY + lobeWidth - 1 ) )
365  - 3.0f *
366  getIntegralBoxSum(
367  bufferPtr,
368  ( centerX - lobeRadius ),
369  ( centerY + 1 - lobeWidth ),
370  ( centerX + lobeRadius ),
371  ( centerY + lobeWidth - 1 ) );
372  };
373 
374  /*!
375  \brief Return a SURF box filter Dxy derivative centered over the given position from the given integral image buffer.
376 
377  \param bufferPtr Buffer pointer.
378 
379  \param centerX Center X.
380 
381  \param centerY Center Y.
382 
383  \param lobeWidth Filter lobe width.
384  */
385  inline static float getSurfDxyDerivative( float** bufferPtr,
386  const unsigned int& centerX, const unsigned int& centerY,
387  const unsigned int& lobeWidth )
388  {
389  return
390  // upper-left filter lobe
391  getIntegralBoxSum(
392  bufferPtr,
393  ( centerX - lobeWidth ),
394  ( centerY - lobeWidth ),
395  ( centerX - 1 ),
396  ( centerY - 1 ) )
397  +
398  // lower-right filter lobe
399  getIntegralBoxSum(
400  bufferPtr,
401  ( centerX + 1 ),
402  ( centerY + 1 ),
403  ( centerX + lobeWidth ),
404  ( centerY + lobeWidth ) )
405  -
406  // upper-right filter lobe
407  getIntegralBoxSum(
408  bufferPtr,
409  ( centerX + 1 ),
410  ( centerY - lobeWidth ),
411  ( centerX + lobeWidth ),
412  ( centerY - 1 ) )
413  -
414  // lower-left filter lobe
415  getIntegralBoxSum(
416  bufferPtr,
417  ( centerX - lobeWidth ),
418  ( centerY + 1 ),
419  ( centerX - 1 ),
420  ( centerY + lobeWidth ) );
421  };
422 
423  /*!
424  \brief Return a Haar X intesity vector for the window centered at the given point.
425 
426  \param buffer Integral image buffer.
427 
428  \param centerX Center X.
429 
430  \param centerY Center Y.
431 
432  \param radius Window radius.
433  */
434  template< typename BufferType >
435  inline static float getHaarXVectorIntensity( BufferType& buffer,
436  const unsigned int& centerX, const unsigned int& centerY,
437  const unsigned int& radius )
438  {
439  return
440  getIntegralBoxSum(
441  buffer,
442  ( centerX + 1 ),
443  ( centerY - radius ),
444  ( centerX + radius ),
445  ( centerY + radius ) )
446  -
447  getIntegralBoxSum(
448  buffer,
449  ( centerX - radius ),
450  ( centerY - radius ),
451  ( centerX - 1 ),
452  ( centerY + radius ) );
453  }
454 
455  /*!
456  \brief Return a Haar Y intesity vector for the window centered at the given point.
457 
458  \param buffer Integral image buffer.
459 
460  \param centerX Center X.
461 
462  \param centerY Center Y.
463 
464  \param radius Window radius.
465  */
466  template< typename BufferType >
467  inline static float getHaarYVectorIntensity( BufferType& buffer,
468  const unsigned int& centerX, const unsigned int& centerY,
469  const unsigned int& radius )
470  {
471  return
472  getIntegralBoxSum(
473  buffer,
474  ( centerX - radius ),
475  ( centerY - radius ),
476  ( centerX + radius ),
477  ( centerY - 1 ) )
478  -
479  getIntegralBoxSum(
480  buffer,
481  ( centerX - radius ),
482  ( centerY + 1 ),
483  ( centerX + radius ),
484  ( centerY + radius ) );
485  }
486 
487  /*!
488  \brief Return the surf octave filter step size (width).
489 
490  \param octaveIndex Octave index (starting from zero).
491  */
492  inline static unsigned int getSurfOctaveFilterStepSize( const unsigned int& octaveIndex )
493  {
494  return (unsigned int)std::pow( 2.0, (double)(octaveIndex + 1) );
495  };
496 
497  /*!
498  \brief Return the surf octave base filter size (width).
499 
500  \param octaveIndex Octave index (starting from zero).
501  */
502  inline static unsigned int getSurfOctaveBaseFilterSize( const unsigned int& octaveIndex )
503  {
504  return 3 + ( 3 * getSurfOctaveFilterStepSize( octaveIndex ) );
505  };
506 
507  /*!
508  \brief Return the surf octave filter size (width).
509 
510  \param octaveIndex Octave index (starting from zero).
511 
512  \param scaleIndex Scale index (starting from zero).
513  */
514  inline static unsigned int getSurfFilterSize( const unsigned int& octaveIndex,
515  const unsigned int& scaleIndex )
516  {
517  return getSurfOctaveBaseFilterSize( octaveIndex ) +
518  ( 3 * ( getSurfOctaveFilterStepSize( octaveIndex ) * scaleIndex ) );
519  };
520  };
521 
522  /*!
523  \class TiePointsLocatorSURFStrategyFactory
524  \brief SURF tie-points locator strategy factory.
525  \note Factory key: SURF
526  */
529  {
530  public:
531 
533 
535 
536  //overload
538 
539  };
540 
541  } // end namespace rp
542 } // end namespace te
543 
544 #endif
545 
static float getIntegralBoxSum(BufferType &buffer, const unsigned int &upperLeftX, const unsigned int &upperLeftY, const unsigned int &lowerRightX, const unsigned int &lowerRightY)
Return a sum of all pixels inside a box over the given integral image buffer.
Tie Points Locator strategy parameters.
SURF tie-points locator strategy factory.
static float getSurfDxyDerivative(float **bufferPtr, const unsigned int &centerX, const unsigned int &centerY, const unsigned int &lobeWidth)
Return a SURF box filter Dxy derivative centered over the given position from the given integral imag...
unsigned int m_surfScalesNumber
The number of sub-sampling scales to generate, when applicable (default:3, minimum:3).
te::gm::GeometricTransformation const * m_raster1ToRaster2TransfPtr
A pointer to a transformation direct mapping raster 1 indexed coords into raster 2 indexed coords...
Base exception class for plugin module.
Definition: Exception.h:42
unsigned int m_tiePointsSubSectorsSplitFactor
The number of sectors along each direction.
TiePointsLocator SURF strategy parameters.
Raster tie points locator strategy factory base class.
2D Geometric transformation base class.
static float getSurfDyyDerivative(float **bufferPtr, const unsigned int &centerX, const unsigned int &centerY, const unsigned int &lobeWidth, const unsigned int &lobeRadius)
Return a SURF box filter Dxx derivative centered over the given position from the given integral imag...
Tie-Pointsr locator strategy.
unsigned int m_processingBlocksNumber
The raster data will be splitted into this number of blocks for processing.
unsigned int m_octavesNumber
The number of octaves to generate (minimum:1).
std::vector< InterestPointsSetT > * m_interestPointsSubSectorsPtr
A pointer to a valid interest points container (one element by subsector)..
static unsigned int getSurfOctaveBaseFilterSize(const unsigned int &octaveIndex)
Return the surf octave base filter size (width).
boost::mutex * m_rastaDataAccessMutexPtr
A pointer to a valid mutex to controle raster data access.
static unsigned int getSurfFilterSize(const unsigned int &octaveIndex, const unsigned int &scaleIndex)
Return the surf octave filter size (width).
te::rp::TiePointsLocatorInputParameters m_inputParameters
Input parameters.
The parameters passed to the executeMatchingByEuclideanDistThreadEntry method.
unsigned int m_surfOctavesNumber
The number of octaves to generate, when applicable (default: 2, minimum:2).
URI C++ Library.
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
FloatsMatrix const * m_integralRasterDataPtr
The integral image raster data.
Tie-points locator SURF strategy.
Tie-points locator strategy.
The parameters passed to the surfLocatorThreadEntry method.
UCharsMatrix const * m_maskRasterDataPtr
The loaded mask raster data pointer (or zero if no mask is avaliable).
A generic template matrix.
Definition: Matrix.h:51
Raster tie-points locator strategy factory base class.
boost::mutex * m_interestPointsAccessMutexPtr
A pointer to a valid mutex to control the output interest points container access.
unsigned int m_maxInterestPointsBySubSector
The maximum number of interest points by sub-sector.
bool m_isInitialized
true if this instance is initialized.
unsigned int * m_nextRasterLinesBlockToProcessValuePtr
A pointer to a valid counter to control the blocks processing sequence.
static float getSurfDxxDerivative(float **bufferPtr, const unsigned int &centerX, const unsigned int &centerY, const unsigned int &lobeWidth, const unsigned int &lobeRadius)
Return a SURF box filter Dyy derivative centered over the given position from the given integral imag...
double m_surfMaxNormEuclideanDist
The maximum acceptable euclidean distance when matching features (when applicable), default:0.75, valid range: [0,1].
static unsigned int getSurfOctaveFilterStepSize(const unsigned int &octaveIndex)
Return the surf octave filter step size (width).
std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT
static float getHaarYVectorIntensity(BufferType &buffer, const unsigned int &centerX, const unsigned int &centerY, const unsigned int &radius)
Return a Haar Y intesity vector for the window centered at the given point.
static float getHaarXVectorIntensity(BufferType &buffer, const unsigned int &centerX, const unsigned int &centerY, const unsigned int &radius)
Return a Haar X intesity vector for the window centered at the given point.