otbWindowedSincInterpolateImageBlackmanFunction.h 4.87 KB
Newer Older
1
/*
Julien Michel's avatar
Julien Michel committed
2
 * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20

21 22
#ifndef otbWindowedSincInterpolateImageBlackmanFunction_h
#define otbWindowedSincInterpolateImageBlackmanFunction_h
23 24 25 26 27 28

#include "otbWindowedSincInterpolateImageFunctionBase.h"
#include "vnl/vnl_math.h"

namespace otb
{
29 30 31

namespace Function
{
32 33 34 35 36
/**
 * \class BlackmanWindowFunction
 * \brief Window function for sinc interpolation.
 * \f[ w(x) = 0.42 + 0.5 cos(\frac{\pi x}{m}) + 0.08 cos(\frac{2 \pi x}{m}) \f]
 * \sa WindowedSincInterpolateImageBlackmanFunction
37 38
 *
 * \ingroup OTBInterpolation
39
 */
OTB Bot's avatar
STYLE  
OTB Bot committed
40
template<class TInput = double, class TOutput = double>
41
class BlackmanWindowFunction
42 43
{
public:
44
  BlackmanWindowFunction(): m_Radius(1), m_Factor1(CONST_PI), m_Factor2(2.0 * CONST_PI) {} // default radius is 1 at construction
45 46 47
  void SetRadius(unsigned int radius)
  {
    m_Radius = radius;
48 49
    m_Factor1 = CONST_PI / static_cast<double>(radius);
    m_Factor2 = 2.0 * CONST_PI / static_cast<double>(radius);
50 51 52 53
  }
  unsigned int  GetRadius() const
  {
    return m_Radius;
OTB Bot's avatar
STYLE  
OTB Bot committed
54
  }
55
  double GetFactor1()
56
  {
57
    return m_Factor1;
OTB Bot's avatar
STYLE  
OTB Bot committed
58
  }
59 60 61
  double GetFactor2()
  {
    return m_Factor2;
OTB Bot's avatar
STYLE  
OTB Bot committed
62
  }
63

OTB Bot's avatar
STYLE  
OTB Bot committed
64
  inline TOutput operator ()(const TInput& A) const
65 66
  {
    double x = static_cast<double>(A);
67
    double px = CONST_PI * x;
68 69
    double temp = 0.42 + 0.5 * std::cos(x * m_Factor1) + 0.08 * std::cos(x * m_Factor2);
    return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px);
70 71 72 73 74 75 76 77
  }
private:
  unsigned int m_Radius;
  // Equal to \f$ \frac{\pi}{m} \f$
  double m_Factor1;
  // Equal to \f$ \frac{2 \pi}{m} \f$
  double m_Factor2;
};
OTB Bot's avatar
STYLE  
OTB Bot committed
78
} //namespace Function
79 80 81 82 83 84

/**
 * \class WindowedSincInterpolateImageBlackmanFunction
 * \brief Use the WindowedSincInterpolateImageFunctionBase with a Blackman Function.
 *
 * \sa GenericInterpolatorImageFunction
85 86 87
 * \sa Function::GaussianWindowFunction
 * \sa Function::HammingWindowFunction
 * \sa Function::CosineWindowFunction
88
 * \sa Function::WelchWindowFunction
89
 * \sa Function::LanczosWindowFunction
90 91
 * \sa Function::BlackmanWindowFunction
 * \ingroup ImageFunctionBases ImageInterpolators
92 93
 *
 * \ingroup OTBInterpolation
94
 */
OTB Bot's avatar
STYLE  
OTB Bot committed
95
template<class TInputImage, class TBoundaryCondition = itk::ConstantBoundaryCondition<TInputImage>, class TCoordRep =
OTB Bot's avatar
STYLE  
OTB Bot committed
96
      double, class TInputInterpolator = double, class TOutputInterpolator = double>
97
class ITK_EXPORT WindowedSincInterpolateImageBlackmanFunction :
OTB Bot's avatar
STYLE  
OTB Bot committed
98
  public WindowedSincInterpolateImageFunctionBase<TInputImage,
99
      typename Function::BlackmanWindowFunction<TInputInterpolator, TOutputInterpolator>,
OTB Bot's avatar
STYLE  
OTB Bot committed
100 101
      TBoundaryCondition,
      TCoordRep>
102 103 104
{
public:
  /** Standard class typedefs. */
OTB Bot's avatar
STYLE  
OTB Bot committed
105
  typedef WindowedSincInterpolateImageBlackmanFunction Self;
106
  typedef WindowedSincInterpolateImageFunctionBase<TInputImage,
107
      typename Function::BlackmanWindowFunction<TInputInterpolator,
OTB Bot's avatar
STYLE  
OTB Bot committed
108 109 110
          TOutputInterpolator>,
      TBoundaryCondition,
      TCoordRep>
OTB Bot's avatar
STYLE  
OTB Bot committed
111 112 113
  Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;
114 115 116 117 118 119 120 121 122 123 124 125

  /** Run-time type information (and related methods). */
  itkTypeMacro(WindowedSincInterpolateImageBlackmanFunction, WindowedSincInterpolateImageFunctionBase);

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Input and output images typedef definition. */
  typedef typename Superclass::InputImageType InputImageType;
  typedef typename Superclass::OutputType     OutputType;

  /** Dimension underlying input image. */
OTB Bot's avatar
STYLE  
OTB Bot committed
126
  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
127 128

  /** Superclass typedef inheritance. */
OTB Bot's avatar
STYLE  
OTB Bot committed
129 130 131 132 133
  typedef typename Superclass::IndexType           IndexType;
  typedef typename Superclass::SizeType            SizeType;
  typedef typename Superclass::RealType            RealType;
  typedef typename Superclass::IteratorType        IteratorType;
  typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
134 135 136

protected:
  WindowedSincInterpolateImageBlackmanFunction() {};
137 138
  ~WindowedSincInterpolateImageBlackmanFunction() override {}
  void PrintSelf(std::ostream& os, itk::Indent indent) const override
139
  {
OTB Bot's avatar
STYLE  
OTB Bot committed
140 141
    Superclass::PrintSelf(os, indent);
  }
142

143
private:
144 145
  WindowedSincInterpolateImageBlackmanFunction(const Self &) = delete;
  void operator =(const Self&) = delete;
146 147
};

148 149 150
} // end namespace otb

#endif