OTB  9.0.0
Orfeo Toolbox
otbImageToSIFTKeyPointSetFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbImageToSIFTKeyPointSetFilter_h
22 #define otbImageToSIFTKeyPointSetFilter_h
23 
24 #include <vector>
25 
26 #include "itkExpandImageFilter.h"
27 #include "itkDiscreteGaussianImageFilter.h"
28 #include "itkRecursiveGaussianImageFilter.h"
29 #include "itkSubtractImageFilter.h"
30 #include "itkShrinkImageFilter.h"
31 #include "itkConstNeighborhoodIterator.h"
32 #include "itkImageRegionConstIterator.h"
33 #include "itkVector.h"
34 #include "itkMinimumMaximumImageCalculator.h"
35 #include "itkUnaryFunctorImageFilter.h"
36 #include "itkGradientImageFilter.h"
37 
39 #include "otbImageList.h"
40 #include "otbMath.h"
41 
42 namespace otb
43 {
44 
45 namespace Functor
46 {
52 template <class TInputPixel, class TOutputPixel>
54 {
55 public:
56  inline TOutputPixel operator()(const TInputPixel& input)
57  {
58  return std::sqrt(input[0] * input[0] + input[1] * input[1]);
59  }
60 };
61 
68 template <class TInputPixel, class TOutputPixel>
70 {
71 public:
72  inline TOutputPixel operator()(const TInputPixel& input)
73  {
74  TOutputPixel resp = std::atan2(input[1], input[0]);
75  if (resp < 0)
76  {
77  resp += CONST_2PI;
78  }
79 
80  return resp;
81  }
82 };
83 } // end namespace Functor
84 
115 template <class TInputImage, class TOutputPointSet>
116 class ITK_EXPORT ImageToSIFTKeyPointSetFilter : public ImageToPointSetFilter<TInputImage, TOutputPointSet>
117 {
118 public:
122  typedef itk::SmartPointer<Self> Pointer;
123  typedef itk::SmartPointer<const Self> ConstPointer;
124 
126  itkNewMacro(Self);
127 
130 
132  typedef TInputImage InputImageType;
133  typedef typename TInputImage::Pointer InputImagePointerType;
134  typedef typename TInputImage::PixelType PixelType;
135 
136  typedef TOutputPointSet OutputPointSetType;
137  typedef typename TOutputPointSet::Pointer OutputPointSetPointerType;
138  typedef typename TOutputPointSet::PixelType OutputPixelType;
139  typedef typename TOutputPointSet::PointType OutputPointType;
140  typedef typename TOutputPointSet::PointIdentifier OutputPointIdentifierType;
141 
142  typedef itk::Vector<PixelType, 3> VectorPointType;
143 
145  itkSetMacro(OctavesNumber, unsigned int);
146  itkGetMacro(OctavesNumber, unsigned int);
148 
150  itkSetMacro(ScalesNumber, unsigned int);
151  itkGetMacro(ScalesNumber, unsigned int);
153 
155  itkSetMacro(ExpandFactors, unsigned int);
156  itkGetMacro(ExpandFactors, unsigned int);
158 
160  itkSetMacro(ShrinkFactors, unsigned int);
161  itkGetMacro(ShrinkFactors, unsigned int);
163 
165  itkSetMacro(Sigma0, double);
166  itkGetMacro(Sigma0, double);
168 
172  itkSetMacro(DoGThreshold, double);
173  itkGetMacro(DoGThreshold, double);
175 
179  itkSetMacro(EdgeThreshold, double);
180  itkGetMacro(EdgeThreshold, double);
182 
184  itkSetMacro(SigmaFactorOrientation, double);
185  itkGetMacro(SigmaFactorOrientation, double);
187 
189  itkSetMacro(SigmaFactorDescriptor, double);
190  itkGetMacro(SigmaFactorDescriptor, double);
192 
194  typedef itk::ExpandImageFilter<TInputImage, TInputImage> ExpandFilterType;
195  typedef typename ExpandFilterType::Pointer ExpandFilterPointerType;
196 
197  typedef itk::ShrinkImageFilter<InputImageType, InputImageType> ShrinkFilterType;
198  typedef typename ShrinkFilterType::Pointer ShrinkFilterPointerType;
199 
200  typedef itk::RecursiveGaussianImageFilter<InputImageType, InputImageType> GaussianFilterType;
201  typedef typename GaussianFilterType::Pointer GaussianFilterPointerType;
202 
205 
206  typedef itk::SubtractImageFilter<InputImageType, InputImageType, InputImageType> SubtractFilterType;
207  typedef typename SubtractFilterType::Pointer SubtractFilterPointerType;
208 
209  typedef itk::ConstNeighborhoodIterator<InputImageType> NeighborhoodIteratorType;
210  typedef typename NeighborhoodIteratorType::NeighborhoodType NeighborhoodType;
211  typedef typename NeighborhoodType::OffsetType OffsetType;
212 
213  typedef itk::ImageRegionConstIterator<InputImageType> RegionIteratorType;
214 
215  typedef itk::MinimumMaximumImageCalculator<InputImageType> MinimumMaximumCalculatorType;
216  typedef typename MinimumMaximumCalculatorType::Pointer MinimumMaximumCalculatorPointerType;
217 
218  typedef itk::GradientImageFilter<InputImageType, PixelType, PixelType> GradientFilterType;
219  typedef typename GradientFilterType::Pointer GradientFilterPointerType;
220  typedef typename GradientFilterType::OutputImageType GradientOutputImageType;
221 
222  typedef itk::UnaryFunctorImageFilter<GradientOutputImageType, InputImageType,
225  typedef typename MagnitudeFilterType::Pointer MagnitudeFilterPointerType;
226 
227  typedef itk::UnaryFunctorImageFilter<GradientOutputImageType, InputImageType,
230  typedef typename OrientationFilterType::Pointer OrientationFilterPointerType;
231 
232 protected:
234  void GenerateData() override;
235 
238 
241  {
242  }
243 
245  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
246 
248  void InitializeInputImage();
249 
254  void ComputeDifferenceOfGaussian(InputImagePointerType input);
255 
257  void DetectKeyPoint(const unsigned int octave);
258 
267  bool IsLocalExtremum(const NeighborhoodIteratorType& currentScale, const NeighborhoodIteratorType& previousScale,
268  const NeighborhoodIteratorType& nextScale) const;
269 
283  bool RefineLocationKeyPoint(const NeighborhoodIteratorType& currentScale, const NeighborhoodIteratorType& previousScale,
284  const NeighborhoodIteratorType& nextScale, VectorPointType& solution);
285 
294  std::vector<PixelType> ComputeKeyPointOrientations(const NeighborhoodIteratorType& currentScale, const unsigned int scale, const PixelType translation);
295 
304  std::vector<PixelType> ComputeKeyPointDescriptor(const NeighborhoodIteratorType& currentScale, const unsigned int scale, const PixelType& orientation);
305 
306 private:
307  ImageToSIFTKeyPointSetFilter(const Self&) = delete;
308  void operator=(const Self&) = delete;
309 
311  unsigned int m_OctavesNumber;
312 
314  unsigned int m_ScalesNumber;
315 
317  unsigned int m_ExpandFactors;
318 
320  unsigned int m_ShrinkFactors;
321 
324 
327 
330 
333 
335  typename GaussianFilterType::ScalarRealType m_Sigma0;
336 
338  double m_Sigmak;
339 
342 
345 
348 
351 
355 
358 
361 
364 
367 
370 
373 
376 
379 
382 
385 
387  unsigned int m_DiscardedKeyPoints;
388 
391 
393  std::vector<double> m_HistogramGaussianWeights;
394 
396  OffsetType m_Offsets[8];
397 };
398 } // End namespace otb
399 #ifndef OTB_MANUAL_INSTANTIATION
401 #endif
402 
403 #endif
otb::ImageToSIFTKeyPointSetFilter::m_OctavesNumber
unsigned int m_OctavesNumber
Definition: otbImageToSIFTKeyPointSetFilter.h:311
otbImageList.h
otb::ImageToSIFTKeyPointSetFilter::m_ExpandFactors
unsigned int m_ExpandFactors
Definition: otbImageToSIFTKeyPointSetFilter.h:317
otb::ImageToSIFTKeyPointSetFilter::MinimumMaximumCalculatorPointerType
MinimumMaximumCalculatorType::Pointer MinimumMaximumCalculatorPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:216
otb::ImageToSIFTKeyPointSetFilter::NeighborhoodIteratorType
itk::ConstNeighborhoodIterator< InputImageType > NeighborhoodIteratorType
Definition: otbImageToSIFTKeyPointSetFilter.h:209
otb::ImageToSIFTKeyPointSetFilter::RegionIteratorType
itk::ImageRegionConstIterator< InputImageType > RegionIteratorType
Definition: otbImageToSIFTKeyPointSetFilter.h:213
otb::ImageToSIFTKeyPointSetFilter::MinimumMaximumCalculatorType
itk::MinimumMaximumImageCalculator< InputImageType > MinimumMaximumCalculatorType
Definition: otbImageToSIFTKeyPointSetFilter.h:215
otb::ImageToSIFTKeyPointSetFilter::m_ValidatedKeyPoints
OutputPointIdentifierType m_ValidatedKeyPoints
Definition: otbImageToSIFTKeyPointSetFilter.h:381
otb::ImageToSIFTKeyPointSetFilter::VectorPointType
itk::Vector< PixelType, 3 > VectorPointType
Definition: otbImageToSIFTKeyPointSetFilter.h:142
otb::ImageToSIFTKeyPointSetFilter::InputImageType
TInputImage InputImageType
Definition: otbImageToSIFTKeyPointSetFilter.h:129
otb::ImageToSIFTKeyPointSetFilter::m_ShrinkFilter
ShrinkFilterPointerType m_ShrinkFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:350
otb::Functor::OrientationFunctor
This functor computes the orientation of a cavariant vector Orientation values lies between 0 and 2*...
Definition: otbImageToSIFTKeyPointSetFilter.h:69
otb::ImageToSIFTKeyPointSetFilter::OutputPointType
TOutputPointSet::PointType OutputPointType
Definition: otbImageToSIFTKeyPointSetFilter.h:139
otb::ImageToSIFTKeyPointSetFilter::m_HistogramGaussianWeights
std::vector< double > m_HistogramGaussianWeights
Definition: otbImageToSIFTKeyPointSetFilter.h:393
otb::ImageToSIFTKeyPointSetFilter::m_SubtractFilter
SubtractFilterPointerType m_SubtractFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:369
otb::ImageToSIFTKeyPointSetFilter::m_SigmaFactorDescriptor
double m_SigmaFactorDescriptor
Definition: otbImageToSIFTKeyPointSetFilter.h:344
otb::Functor::MagnitudeFunctor::operator()
TOutputPixel operator()(const TInputPixel &input)
Definition: otbImageToSIFTKeyPointSetFilter.h:56
otb::ImageToSIFTKeyPointSetFilter::GradientOutputImageType
GradientFilterType::OutputImageType GradientOutputImageType
Definition: otbImageToSIFTKeyPointSetFilter.h:220
otb::ImageToPointSetFilter
Base class to output PointSet data with image data as input.
Definition: otbImageToPointSetFilter.h:44
otb::ImageToSIFTKeyPointSetFilter::m_DoGThreshold
double m_DoGThreshold
Definition: otbImageToSIFTKeyPointSetFilter.h:323
otb::ImageToSIFTKeyPointSetFilter::m_YGaussianFilter
GaussianFilterPointerType m_YGaussianFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:354
otb::ImageToSIFTKeyPointSetFilter::m_Sigmak
double m_Sigmak
Definition: otbImageToSIFTKeyPointSetFilter.h:338
otb::ImageToSIFTKeyPointSetFilter::NeighborhoodType
NeighborhoodIteratorType::NeighborhoodType NeighborhoodType
Definition: otbImageToSIFTKeyPointSetFilter.h:210
otbMath.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ImageToSIFTKeyPointSetFilter::m_ChangeSamplePointsMax
unsigned int m_ChangeSamplePointsMax
Definition: otbImageToSIFTKeyPointSetFilter.h:390
otb::ImageToSIFTKeyPointSetFilter::Self
ImageToSIFTKeyPointSetFilter Self
Definition: otbImageToSIFTKeyPointSetFilter.h:120
otbImageToSIFTKeyPointSetFilter.hxx
otb::ImageToSIFTKeyPointSetFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImageToSIFTKeyPointSetFilter.h:123
otb::ImageToSIFTKeyPointSetFilter::Superclass
ImageToPointSetFilter< TInputImage, TOutputPointSet > Superclass
Definition: otbImageToSIFTKeyPointSetFilter.h:121
otb::ImageToSIFTKeyPointSetFilter::ExpandFilterType
itk::ExpandImageFilter< TInputImage, TInputImage > ExpandFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:190
otb::ImageToSIFTKeyPointSetFilter::OrientationFilterPointerType
OrientationFilterType::Pointer OrientationFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:230
otb::ImageToSIFTKeyPointSetFilter::m_XGaussianFilter
GaussianFilterPointerType m_XGaussianFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:353
otb::ImageToSIFTKeyPointSetFilter::ShrinkFilterType
itk::ShrinkImageFilter< InputImageType, InputImageType > ShrinkFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:197
otb::ImageToSIFTKeyPointSetFilter::OutputPointIdentifierType
TOutputPointSet::PointIdentifier OutputPointIdentifierType
Definition: otbImageToSIFTKeyPointSetFilter.h:140
otb::ImageToSIFTKeyPointSetFilter::OutputPointSetPointerType
TOutputPointSet::Pointer OutputPointSetPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:137
otb::ImageToSIFTKeyPointSetFilter::m_RatioEdgeThreshold
double m_RatioEdgeThreshold
Definition: otbImageToSIFTKeyPointSetFilter.h:329
otb::ImageToSIFTKeyPointSetFilter::GaussianFilterPointerType
GaussianFilterType::Pointer GaussianFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:201
otb::ImageToSIFTKeyPointSetFilter::GaussianFilterType
itk::RecursiveGaussianImageFilter< InputImageType, InputImageType > GaussianFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:200
otb::ImageToSIFTKeyPointSetFilter::InputImagePointerType
TInputImage::Pointer InputImagePointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:133
otb::CONST_2PI
constexpr double CONST_2PI
Definition: otbMath.h:55
otb::ImageToSIFTKeyPointSetFilter::SubtractFilterPointerType
SubtractFilterType::Pointer SubtractFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:207
otb::ImageToSIFTKeyPointSetFilter::m_ExpandFilter
ExpandFilterPointerType m_ExpandFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:347
otb::ImageToSIFTKeyPointSetFilter::m_OrientationList
ImageListPointerType m_OrientationList
Definition: otbImageToSIFTKeyPointSetFilter.h:366
otb::ImageList::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageList.h:45
otb::ImageToSIFTKeyPointSetFilter
This class extracts key points from an input image, trough a pyramidal decomposition.
Definition: otbImageToSIFTKeyPointSetFilter.h:116
otb::ImageToSIFTKeyPointSetFilter::ExpandFilterPointerType
ExpandFilterType::Pointer ExpandFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:195
otbImageToPointSetFilter.h
otb::ImageToSIFTKeyPointSetFilter::ShrinkFilterPointerType
ShrinkFilterType::Pointer ShrinkFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:198
otb::ImageToSIFTKeyPointSetFilter::m_SigmaFactorOrientation
double m_SigmaFactorOrientation
Definition: otbImageToSIFTKeyPointSetFilter.h:341
otb::ImageToSIFTKeyPointSetFilter::~ImageToSIFTKeyPointSetFilter
~ImageToSIFTKeyPointSetFilter() override
Definition: otbImageToSIFTKeyPointSetFilter.h:240
otb::ImageToSIFTKeyPointSetFilter::m_MagnitudeList
ImageListPointerType m_MagnitudeList
Definition: otbImageToSIFTKeyPointSetFilter.h:363
otb::ImageToSIFTKeyPointSetFilter::ImageListType
otb::ImageList< InputImageType > ImageListType
Definition: otbImageToSIFTKeyPointSetFilter.h:203
otb::ImageToSIFTKeyPointSetFilter::m_GradientMagnitudeThreshold
PixelType m_GradientMagnitudeThreshold
Definition: otbImageToSIFTKeyPointSetFilter.h:332
otb::ImageToSIFTKeyPointSetFilter::m_LastGaussian
InputImagePointerType m_LastGaussian
Definition: otbImageToSIFTKeyPointSetFilter.h:357
otb::ImageToPointSetFilter::InputImageType
TInputImage InputImageType
Definition: otbImageToPointSetFilter.h:54
otb::ImageToSIFTKeyPointSetFilter::m_GradientFilter
GradientFilterPointerType m_GradientFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:372
otb::ImageToSIFTKeyPointSetFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImageToSIFTKeyPointSetFilter.h:122
otb::ImageToSIFTKeyPointSetFilter::OffsetType
NeighborhoodType::OffsetType OffsetType
Definition: otbImageToSIFTKeyPointSetFilter.h:211
otb::Functor::OrientationFunctor::operator()
TOutputPixel operator()(const TInputPixel &input)
Definition: otbImageToSIFTKeyPointSetFilter.h:72
otb::ImageToSIFTKeyPointSetFilter::m_Sigma0
GaussianFilterType::ScalarRealType m_Sigma0
Definition: otbImageToSIFTKeyPointSetFilter.h:335
otb::ImageToSIFTKeyPointSetFilter::OutputPointSetType
TOutputPointSet OutputPointSetType
Definition: otbImageToSIFTKeyPointSetFilter.h:136
otb::ImageToSIFTKeyPointSetFilter::PixelType
TInputImage::PixelType PixelType
Definition: otbImageToSIFTKeyPointSetFilter.h:134
otb::Functor::MagnitudeFunctor
This functor computes the magnitude of a covariant vector.
Definition: otbImageToSIFTKeyPointSetFilter.h:53
otb::ImageToSIFTKeyPointSetFilter::m_OrientationFilter
OrientationFilterPointerType m_OrientationFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:378
otb::ImageToSIFTKeyPointSetFilter::MagnitudeFilterPointerType
MagnitudeFilterType::Pointer MagnitudeFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:225
otb::ImageToSIFTKeyPointSetFilter::m_DoGList
ImageListPointerType m_DoGList
Definition: otbImageToSIFTKeyPointSetFilter.h:360
otb::ImageToSIFTKeyPointSetFilter::ImageListPointerType
ImageListType::Pointer ImageListPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:204
otb::ImageList
This class represent a list of images.
Definition: otbImageList.h:39
otb::ImageToSIFTKeyPointSetFilter::GradientFilterPointerType
GradientFilterType::Pointer GradientFilterPointerType
Definition: otbImageToSIFTKeyPointSetFilter.h:219
otb::ImageToSIFTKeyPointSetFilter::m_EdgeThreshold
double m_EdgeThreshold
Definition: otbImageToSIFTKeyPointSetFilter.h:326
otb::ImageToSIFTKeyPointSetFilter::m_DiscardedKeyPoints
unsigned int m_DiscardedKeyPoints
Definition: otbImageToSIFTKeyPointSetFilter.h:387
otb::ImageToSIFTKeyPointSetFilter::m_DifferentSamplePoints
unsigned int m_DifferentSamplePoints
Definition: otbImageToSIFTKeyPointSetFilter.h:384
otb::ImageToSIFTKeyPointSetFilter::OutputPixelType
TOutputPointSet::PixelType OutputPixelType
Definition: otbImageToSIFTKeyPointSetFilter.h:138
otb::ImageToSIFTKeyPointSetFilter::m_ShrinkFactors
unsigned int m_ShrinkFactors
Definition: otbImageToSIFTKeyPointSetFilter.h:320
otb::ImageToSIFTKeyPointSetFilter::SubtractFilterType
itk::SubtractImageFilter< InputImageType, InputImageType, InputImageType > SubtractFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:206
otb::ImageToSIFTKeyPointSetFilter::m_MagnitudeFilter
MagnitudeFilterPointerType m_MagnitudeFilter
Definition: otbImageToSIFTKeyPointSetFilter.h:375
otb::ImageToSIFTKeyPointSetFilter::MagnitudeFilterType
itk::UnaryFunctorImageFilter< GradientOutputImageType, InputImageType, Functor::MagnitudeFunctor< typename GradientOutputImageType::PixelType, typename InputImageType::PixelType > > MagnitudeFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:224
otb::ImageToSIFTKeyPointSetFilter::GradientFilterType
itk::GradientImageFilter< InputImageType, PixelType, PixelType > GradientFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:218
otb::ImageToSIFTKeyPointSetFilter::OrientationFilterType
itk::UnaryFunctorImageFilter< GradientOutputImageType, InputImageType, Functor::OrientationFunctor< typename GradientOutputImageType::PixelType, typename InputImageType::PixelType > > OrientationFilterType
Definition: otbImageToSIFTKeyPointSetFilter.h:229
otb::ImageToSIFTKeyPointSetFilter::m_ScalesNumber
unsigned int m_ScalesNumber
Definition: otbImageToSIFTKeyPointSetFilter.h:314