21 #ifndef otbConvexOrConcaveClassificationFilter_h
22 #define otbConvexOrConcaveClassificationFilter_h
24 #include "itkBinaryFunctorImageFilter.h"
58 template <
class TInput,
class TOutput>
59 class ConvexOrConcaveDecisionRule
66 ConvexOrConcaveDecisionRule()
67 : m_ConvexLabel(1), m_ConcaveLabel(2), m_FlatLabel(0), m_Sigma(0.0)
73 virtual ~ConvexOrConcaveDecisionRule()
83 inline TOutput operator()(
const TInput& x,
const TInput& xlevel)
85 TOutput resp = m_FlatLabel;
87 if (
static_cast<double>(x - xlevel) > m_Sigma)
91 else if (
static_cast<double>(xlevel - x) > m_Sigma)
93 resp = m_ConcaveLabel;
101 void SetConvexLabel(
const TOutput& label)
103 m_ConvexLabel = label;
110 TOutput GetConvexLabel(
void)
112 return m_ConvexLabel;
119 void SetConcaveLabel(
const TOutput& label)
121 m_ConcaveLabel = label;
128 TOutput GetConcaveLabel(
void)
130 return m_ConcaveLabel;
137 void SetFlatLabel(
const TOutput& label)
146 TOutput GetFlatLabel(
void)
155 void SetSigma(
const double& sigma)
164 double GetSigma(
void)
171 TOutput m_ConvexLabel;
174 TOutput m_ConcaveLabel;
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>>
201 typedef ConvexOrConcaveClassificationFilter Self;
202 typedef itk::BinaryFunctorImageFilter<TInputImage, TInputImage, TOutputImage,
203 Functor::ConvexOrConcaveDecisionRule<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
205 typedef itk::SmartPointer<Self> Pointer;
206 typedef itk::SmartPointer<const Self> ConstPointer;
212 itkTypeMacro(ConvexOrConcaveClassificationFilter, BinaryFunctorImageFilter);
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;
225 using Superclass::SetInput;
226 void SetInput(
const TInputImage* image)
override
228 this->SetInput1(image);
236 void SetInputLeveling(
const TInputImage* leveling)
238 this->SetInput2(leveling);
242 itkSetMacro(ConvexLabel, LabelType);
243 itkGetMacro(ConvexLabel, LabelType);
246 itkSetMacro(ConcaveLabel, LabelType);
247 itkGetMacro(ConcaveLabel, LabelType);
250 itkSetMacro(FlatLabel, LabelType);
251 itkGetMacro(FlatLabel, LabelType);
254 itkSetMacro(Sigma,
double);
255 itkGetMacro(Sigma,
double);
259 void BeforeThreadedGenerateData(
void)
override
261 this->GetFunctor().SetConvexLabel(m_ConvexLabel);
262 this->GetFunctor().SetConcaveLabel(m_ConcaveLabel);
263 this->GetFunctor().SetFlatLabel(m_FlatLabel);
264 this->GetFunctor().SetSigma(m_Sigma);
270 ConvexOrConcaveClassificationFilter()
271 : m_ConvexLabel(1), m_ConcaveLabel(2), m_FlatLabel(0), m_Sigma(0.0)
275 ~ConvexOrConcaveClassificationFilter()
override
280 void PrintSelf(std::ostream& os, itk::Indent indent)
const override
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;
291 ConvexOrConcaveClassificationFilter(
const Self&) =
delete;
292 void operator=(
const Self&) =
delete;
295 LabelType m_ConvexLabel;
298 LabelType m_ConcaveLabel;
301 LabelType m_FlatLabel;