OTB  7.4.0
Orfeo Toolbox
otbImageToSIFTKeyPointSetFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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;
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 
347  ExpandFilterPointerType m_ExpandFilter;
348 
350  ShrinkFilterPointerType m_ShrinkFilter;
351 
353  GaussianFilterPointerType m_XGaussianFilter;
354  GaussianFilterPointerType m_YGaussianFilter;
355 
357  InputImagePointerType m_LastGaussian;
358 
360  ImageListPointerType m_DoGList;
361 
363  ImageListPointerType m_MagnitudeList;
364 
366  ImageListPointerType m_OrientationList;
367 
369  SubtractFilterPointerType m_SubtractFilter;
370 
372  GradientFilterPointerType m_GradientFilter;
373 
375  MagnitudeFilterPointerType m_MagnitudeFilter;
376 
378  OrientationFilterPointerType m_OrientationFilter;
379 
381  OutputPointIdentifierType m_ValidatedKeyPoints;
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
itk::ShrinkImageFilter< InputImageType, InputImageType > ShrinkFilterType
itk::SubtractImageFilter< InputImageType, InputImageType, InputImageType > SubtractFilterType
itk::SmartPointer< Self > Pointer
Definition: otbImageList.h:45
itk::RecursiveGaussianImageFilter< InputImageType, InputImageType > GaussianFilterType
itk::UnaryFunctorImageFilter< GradientOutputImageType, InputImageType, Functor::OrientationFunctor< typename GradientOutputImageType::PixelType, typename InputImageType::PixelType > > OrientationFilterType
TOutputPixel operator()(const TInputPixel &input)
itk::UnaryFunctorImageFilter< GradientOutputImageType, InputImageType, Functor::MagnitudeFunctor< typename GradientOutputImageType::PixelType, typename InputImageType::PixelType > > MagnitudeFilterType
GradientFilterType::Pointer GradientFilterPointerType
GaussianFilterType::ScalarRealType m_Sigma0
constexpr double CONST_2PI
Definition: otbMath.h:55
MinimumMaximumCalculatorType::Pointer MinimumMaximumCalculatorPointerType
Base class to output PointSet data with image data as input.
itk::ImageRegionConstIterator< InputImageType > RegionIteratorType
itk::MinimumMaximumImageCalculator< InputImageType > MinimumMaximumCalculatorType
NeighborhoodIteratorType::NeighborhoodType NeighborhoodType
GradientFilterType::OutputImageType GradientOutputImageType
This class extracts key points from an input image, trough a pyramidal decomposition.
TOutputPixel operator()(const TInputPixel &input)
OrientationFilterType::Pointer OrientationFilterPointerType
This class represent a list of images.
Definition: otbImageList.h:39
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
TOutputPointSet::PointIdentifier OutputPointIdentifierType
This functor computes the magnitude of a covariant vector.
GaussianFilterType::Pointer GaussianFilterPointerType
This functor computes the orientation of a cavariant vector Orientation values lies between 0 and 2*...
itk::GradientImageFilter< InputImageType, PixelType, PixelType > GradientFilterType
itk::ConstNeighborhoodIterator< InputImageType > NeighborhoodIteratorType
SubtractFilterType::Pointer SubtractFilterPointerType
itk::ExpandImageFilter< TInputImage, TInputImage > ExpandFilterType
MagnitudeFilterType::Pointer MagnitudeFilterPointerType
otb::ImageList< InputImageType > ImageListType
VectorImageType::PointType PointType
Definition: mvdTypes.h:183
itk::SmartPointer< const Self > ConstPointer
ImageToPointSetFilter< TInputImage, TOutputPointSet > Superclass