OTB  9.0.0
Orfeo Toolbox
otbSobelVectorImageFilter.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 otbSobelVectorImageFilter_h
22 #define otbSobelVectorImageFilter_h
23 
25 
26 #include <vnl/vnl_math.h>
27 
28 namespace otb
29 {
30 
31 namespace Functor
32 {
38 template <class TInput, class TOutput>
40 {
41 public:
43  {
44  }
45  virtual ~SobelOperator()
46  {
47  }
48 
49  TOutput operator()(const TInput& input)
50  {
51  unsigned int length = input.GetPixel(0).Size();
52  TOutput output(length);
53  for (unsigned int i = 0; i < length; ++i)
54  {
55  double hori = static_cast<double>((input.GetPixel(0)[i] - input.GetPixel(2)[i]) + 2 * (input.GetPixel(3)[i] - input.GetPixel(5)[i]) +
56  (input.GetPixel(6)[i] - input.GetPixel(8)[i]));
57  double vert = static_cast<double>((input.GetPixel(0)[i] - input.GetPixel(6)[i]) + 2 * (input.GetPixel(1)[i] - input.GetPixel(7)[i]) +
58  (input.GetPixel(2)[i] - input.GetPixel(8)[i]));
59 
60  output[i] = static_cast<typename TOutput::ValueType>(std::sqrt(std::pow(hori, 2.) + std::pow(vert, 2.)));
61  }
62  return output;
63  }
64 }; // end of functor class
65 
66 } // end of namespace Functor
67 
73 template <class TInputImage, class TOutputImage>
74 class ITK_EXPORT SobelVectorImageFilter
76  TInputImage, TOutputImage, Functor::SobelOperator<typename itk::ConstNeighborhoodIterator<TInputImage>, typename TOutputImage::PixelType>>
77 {
78 public:
82  TInputImage, TOutputImage, Functor::SobelOperator<typename itk::ConstNeighborhoodIterator<TInputImage>, typename TOutputImage::PixelType>>
84  typedef itk::SmartPointer<Self> Pointer;
85  typedef itk::SmartPointer<const Self> ConstPointer;
86 
88  itkNewMacro(Self);
89 
91  itkTypeMacro(SobelVectorImageFilter, ImageToImageFilter);
92 
93 protected:
95  {
96  typename Superclass::RadiusType radius = {{1, 1}};
97  this->SetRadius(radius);
98  }
100  {
101  }
102 
103 private:
104  SobelVectorImageFilter(const Self&); // Not implemented
105  void operator=(const Self&); // Not implemented
106 }; // end of class
107 
108 } // end of namespace otb
109 
110 
111 #endif // otbSobelVectorImageFilter_h
otb::SobelVectorImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSobelVectorImageFilter.h:85
otb::SobelVectorImageFilter::SobelVectorImageFilter
SobelVectorImageFilter()
Definition: otbSobelVectorImageFilter.h:94
otb::SobelVectorImageFilter::Self
SobelVectorImageFilter Self
Definition: otbSobelVectorImageFilter.h:80
otb::UnaryFunctorNeighborhoodVectorImageFilter::RadiusType
NeighborhoodIteratorType::RadiusType RadiusType
Definition: otbUnaryFunctorNeighborhoodVectorImageFilter.h:98
otb::SobelVectorImageFilter::~SobelVectorImageFilter
~SobelVectorImageFilter() override
Definition: otbSobelVectorImageFilter.h:99
otb::Functor::SobelOperator::operator()
TOutput operator()(const TInput &input)
Definition: otbSobelVectorImageFilter.h:49
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::SobelOperator
Performs the calculation of Sobel derivation.
Definition: otbSobelVectorImageFilter.h:39
otb::Functor::SobelOperator::SobelOperator
SobelOperator()
Definition: otbSobelVectorImageFilter.h:42
otb::SobelVectorImageFilter::Superclass
UnaryFunctorNeighborhoodVectorImageFilter< TInputImage, TOutputImage, Functor::SobelOperator< typename itk::ConstNeighborhoodIterator< TInputImage >, typename TOutputImage::PixelType > > Superclass
Definition: otbSobelVectorImageFilter.h:83
otb::Functor::SobelOperator::~SobelOperator
virtual ~SobelOperator()
Definition: otbSobelVectorImageFilter.h:45
otb::UnaryFunctorNeighborhoodVectorImageFilter
Implements neighborhood-wise generic operation of one vector image.
Definition: otbUnaryFunctorNeighborhoodVectorImageFilter.h:42
otb::SobelVectorImageFilter
Implements the Sobel Gradient to be processed on a vector image.
Definition: otbSobelVectorImageFilter.h:74
otbUnaryFunctorNeighborhoodVectorImageFilter.h
otb::SobelVectorImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSobelVectorImageFilter.h:84