OTB  9.0.0
Orfeo Toolbox
otbConvexOrConcaveClassificationFilter.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 otbConvexOrConcaveClassificationFilter_h
22 #define otbConvexOrConcaveClassificationFilter_h
23 
24 #include "itkBinaryFunctorImageFilter.h"
25 namespace otb
26 {
27 namespace Functor
28 {
58 template <class TInput, class TOutput>
59 class ConvexOrConcaveDecisionRule
60 {
61 
62 public:
66  ConvexOrConcaveDecisionRule()
67  : m_ConvexLabel(1), m_ConcaveLabel(2), m_FlatLabel(0), m_Sigma(0.0)
68  {}
69 
73  virtual ~ConvexOrConcaveDecisionRule()
74  {
75  }
76 
83  inline TOutput operator()(const TInput& x, const TInput& xlevel)
84  {
85  TOutput resp = m_FlatLabel;
86 
87  if (static_cast<double>(x - xlevel) > m_Sigma)
88  {
89  resp = m_ConvexLabel;
90  }
91  else if (static_cast<double>(xlevel - x) > m_Sigma)
92  {
93  resp = m_ConcaveLabel;
94  }
95  return resp;
96  }
101  void SetConvexLabel(const TOutput& label)
102  {
103  m_ConvexLabel = label;
104  }
105 
110  TOutput GetConvexLabel(void)
111  {
112  return m_ConvexLabel;
113  }
114 
119  void SetConcaveLabel(const TOutput& label)
120  {
121  m_ConcaveLabel = label;
122  }
123 
128  TOutput GetConcaveLabel(void)
129  {
130  return m_ConcaveLabel;
131  }
132 
137  void SetFlatLabel(const TOutput& label)
138  {
139  m_FlatLabel = label;
140  }
141 
146  TOutput GetFlatLabel(void)
147  {
148  return m_FlatLabel;
149  }
150 
155  void SetSigma(const double& sigma)
156  {
157  m_Sigma = sigma;
158  }
159 
164  double GetSigma(void)
165  {
166  return m_Sigma;
167  }
168 
169 private:
171  TOutput m_ConvexLabel;
172 
174  TOutput m_ConcaveLabel;
175 
177  TOutput m_FlatLabel;
178 
180  double m_Sigma;
181 };
182 } // end namespace Functor
183 
194 template <class TInputImage, class TOutputImage>
195 class ITK_EXPORT ConvexOrConcaveClassificationFilter
196  : public itk::BinaryFunctorImageFilter<TInputImage, TInputImage, TOutputImage,
197  Functor::ConvexOrConcaveDecisionRule<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
198 {
199 public:
201  typedef ConvexOrConcaveClassificationFilter Self;
202  typedef itk::BinaryFunctorImageFilter<TInputImage, TInputImage, TOutputImage,
203  Functor::ConvexOrConcaveDecisionRule<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
204  Superclass;
205  typedef itk::SmartPointer<Self> Pointer;
206  typedef itk::SmartPointer<const Self> ConstPointer;
207 
209  itkNewMacro(Self);
210 
212  itkTypeMacro(ConvexOrConcaveClassificationFilter, BinaryFunctorImageFilter);
213 
215  typedef TInputImage InputImageType;
216  typedef TOutputImage OutputImageType;
217  typedef typename OutputImageType::PixelType LabelType;
218  typedef Functor::ConvexOrConcaveDecisionRule<typename TInputImage::PixelType, typename TOutputImage::PixelType> DecisionFunctorType;
219 
225  using Superclass::SetInput;
226  void SetInput(const TInputImage* image) override
227  {
228  this->SetInput1(image);
229  }
230 
236  void SetInputLeveling(const TInputImage* leveling)
237  {
238  this->SetInput2(leveling);
239  }
240 
242  itkSetMacro(ConvexLabel, LabelType);
243  itkGetMacro(ConvexLabel, LabelType);
244 
246  itkSetMacro(ConcaveLabel, LabelType);
247  itkGetMacro(ConcaveLabel, LabelType);
248 
250  itkSetMacro(FlatLabel, LabelType);
251  itkGetMacro(FlatLabel, LabelType);
252 
254  itkSetMacro(Sigma, double);
255  itkGetMacro(Sigma, double);
257 
259  void BeforeThreadedGenerateData(void) override
260  {
261  this->GetFunctor().SetConvexLabel(m_ConvexLabel);
262  this->GetFunctor().SetConcaveLabel(m_ConcaveLabel);
263  this->GetFunctor().SetFlatLabel(m_FlatLabel);
264  this->GetFunctor().SetSigma(m_Sigma);
265  }
267 
268 protected:
270  ConvexOrConcaveClassificationFilter()
271  : m_ConvexLabel(1), m_ConcaveLabel(2), m_FlatLabel(0), m_Sigma(0.0)
272  {};
273 
275  ~ConvexOrConcaveClassificationFilter() override
276  {
277  }
278 
280  void PrintSelf(std::ostream& os, itk::Indent indent) const override
281  {
282  Superclass::PrintSelf(os, indent);
283  os << indent << "ConvexLabel: " << m_ConvexLabel << std::endl;
284  os << indent << "ConcaveLabel: " << m_ConcaveLabel << std::endl;
285  os << indent << "FlatLabel: " << m_FlatLabel << std::endl;
286  os << indent << "Sigma: " << m_Sigma << std::endl;
287  }
289 
290 private:
291  ConvexOrConcaveClassificationFilter(const Self&) = delete;
292  void operator=(const Self&) = delete;
293 
295  LabelType m_ConvexLabel;
296 
298  LabelType m_ConcaveLabel;
299 
301  LabelType m_FlatLabel;
302 
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32