OTB  5.0.0
Orfeo Toolbox
otbNonMaxRemovalByDirectionFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbNonMaxRemovalByDirectionFilter_h
19 #define __otbNonMaxRemovalByDirectionFilter_h
20 
23 
24 #include "otbMath.h"
25 
26 namespace otb
27 {
28 namespace Functor
29 {
37 template <class TInput1, class TInput2, class TOutput>
39 {
40 public:
43  inline TOutput operator ()(const TInput1& itA, const TInput2& itB)
44  {
45  TOutput resp = 0;
46  if (itA.GetCenterPixel() != 0)
47  {
48  typename TInput1::OffsetType offset1, offset2;
49  offset1.Fill(0);
50  offset2.Fill(0);
51  int neighborhoodNumber;
52  if (itB.GetCenterPixel() > 0)
53  {
54  neighborhoodNumber = static_cast<int>(itB.GetCenterPixel() / (CONST_PI_4) -1);
55  }
56  else
57  {
58  neighborhoodNumber = static_cast<int>((itB.GetCenterPixel() + CONST_PI) / (CONST_PI_4) -1);
59  }
60  switch (neighborhoodNumber)
61  {
62  case 0:
63  offset1[0] = 1;
64  offset1[1] = -1;
65  offset2[0] = -1;
66  offset2[1] = 1;
67  break;
68  case 1:
69  offset1[0] = 1;
70  offset1[1] = 0;
71  offset2[0] = -1;
72  offset2[1] = 0;
73  break;
74  case 2:
75  offset1[0] = 1;
76  offset1[1] = 1;
77  offset2[0] = -1;
78  offset2[1] = -1;
79  break;
80  case 3:
81  offset1[0] = 0;
82  offset1[1] = 1;
83  offset2[0] = 0;
84  offset2[1] = -1;
85  break;
86  }
87  if ((itA.GetCenterPixel() > itA.GetPixel(offset1))
88  && (itA.GetCenterPixel() > itA.GetPixel(offset2)))
89  {
90  resp = itA.GetCenterPixel();
91  }
92  }
93  return resp;
94  }
95 };
96 }
106 template <class TInputModulus, class TInputDirection, class TOutputImage>
108  : public ModulusAndDirectionImageToImageFilter<TInputModulus, TInputDirection, TOutputImage>
109 {
110 public:
116 
118  itkNewMacro(Self);
119 
122 
128  typename TOutputImage::PixelType> FunctorType;
129  typedef otb::BinaryFunctorNeighborhoodImageFilter<TInputModulus, TInputDirection, TOutputImage,
131 
132 protected:
135 
138 
140  virtual void PrintSelf(std::ostream& os, itk::Indent indent) const
141  {
142  Superclass::PrintSelf(os, indent);
143  }
144 
146  virtual void GenerateData(void)
147  {
148  typename ComputingFilterType::Pointer filter = ComputingFilterType::New();
149  filter->SetInput1(this->GetInput());
150  filter->SetInput2(this->GetInputDirection());
151  filter->GraftOutput(this->GetOutput());
152  filter->Update();
153  this->GraftOutput(filter->GetOutput());
154  }
156 
157 private:
158  NonMaxRemovalByDirectionFilter(const Self &); //purposely not implemented
159  void operator =(const Self&); //purposely not implemented
160 };
161 } // End namespace otb
162 #endif
const double CONST_PI
Definition: otbMath.h:45
TOutput operator()(const TInput1 &itA, const TInput2 &itB)
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
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...
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:47