OTB  6.1.0
Orfeo Toolbox
otbNonMaxRemovalByDirectionFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2017 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 otbNonMaxRemovalByDirectionFilter_h
22 #define otbNonMaxRemovalByDirectionFilter_h
23 
26 
27 #include "otbMath.h"
28 
29 namespace otb
30 {
31 namespace Functor
32 {
40 template <class TInput1, class TInput2, class TOutput>
42 {
43 public:
46  inline TOutput operator ()(const TInput1& itA, const TInput2& itB)
47  {
48  TOutput resp = 0;
49  if (itA.GetCenterPixel() != 0)
50  {
51  typename TInput1::OffsetType offset1, offset2;
52  offset1.Fill(0);
53  offset2.Fill(0);
54  int neighborhoodNumber;
55  if (itB.GetCenterPixel() > 0)
56  {
57  neighborhoodNumber = static_cast<int>(itB.GetCenterPixel() / (CONST_PI_4) -1);
58  }
59  else
60  {
61  neighborhoodNumber = static_cast<int>((itB.GetCenterPixel() + CONST_PI) / (CONST_PI_4) -1);
62  }
63  switch (neighborhoodNumber)
64  {
65  case 0:
66  offset1[0] = 1;
67  offset1[1] = -1;
68  offset2[0] = -1;
69  offset2[1] = 1;
70  break;
71  case 1:
72  offset1[0] = 1;
73  offset1[1] = 0;
74  offset2[0] = -1;
75  offset2[1] = 0;
76  break;
77  case 2:
78  offset1[0] = 1;
79  offset1[1] = 1;
80  offset2[0] = -1;
81  offset2[1] = -1;
82  break;
83  case 3:
84  offset1[0] = 0;
85  offset1[1] = 1;
86  offset2[0] = 0;
87  offset2[1] = -1;
88  break;
89  }
90  if ((itA.GetCenterPixel() > itA.GetPixel(offset1))
91  && (itA.GetCenterPixel() > itA.GetPixel(offset2)))
92  {
93  resp = itA.GetCenterPixel();
94  }
95  }
96  return resp;
97  }
98 };
99 }
109 template <class TInputModulus, class TInputDirection, class TOutputImage>
111  : public ModulusAndDirectionImageToImageFilter<TInputModulus, TInputDirection, TOutputImage>
112 {
113 public:
119 
121  itkNewMacro(Self);
122 
125 
131  typename TOutputImage::PixelType> FunctorType;
132  typedef otb::BinaryFunctorNeighborhoodImageFilter<TInputModulus, TInputDirection, TOutputImage,
134 
135 protected:
138 
141 
143  void PrintSelf(std::ostream& os, itk::Indent indent) const ITK_OVERRIDE
144  {
145  Superclass::PrintSelf(os, indent);
146  }
147 
149  void GenerateData(void) ITK_OVERRIDE
150  {
151  typename ComputingFilterType::Pointer filter = ComputingFilterType::New();
152  filter->SetInput1(this->GetInput());
153  filter->SetInput2(this->GetInputDirection());
154  filter->GraftOutput(this->GetOutput());
155  filter->Update();
156  this->GraftOutput(filter->GetOutput());
157  }
159 
160 private:
161  NonMaxRemovalByDirectionFilter(const Self &); //purposely not implemented
162  void operator =(const Self&); //purposely not implemented
163 };
164 } // End namespace otb
165 #endif
const double CONST_PI
Definition: otbMath.h:48
TOutput operator()(const TInput1 &itA, const TInput2 &itB)
This functor is used by the NonMaxRemovalByDirectionFilter.
Base class for modulus and direction image filters.
Implements neighborhood-wise generic operation of two images.
ModulusAndDirectionImageToImageFilter< TInputModulus, TInputDirection, TOutputImage > Superclass
This filters removes (sets to null intensity) pixels which are not the maxima of the scalar product m...
void PrintSelf(std::ostream &os, itk::Indent indent) const ITK_OVERRIDE
Functor::NonMaxRemovalByDirectionFunctor< typename itk::ConstNeighborhoodIterator< TInputModulus >, typename itk::ConstNeighborhoodIterator< TInputDirection >, typename TOutputImage::PixelType > FunctorType
otb::BinaryFunctorNeighborhoodImageFilter< TInputModulus, TInputDirection, TOutputImage, FunctorType > ComputingFilterType
const double CONST_PI_4
Definition: otbMath.h:50