RTK  2.5.0
Reconstruction Toolkit
rtkSoftThresholdImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright RTK Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef rtkSoftThresholdImageFilter_h
20 #define rtkSoftThresholdImageFilter_h
21 
23 #include "itkConceptChecking.h"
25 
26 namespace rtk
27 {
28 
40 namespace Functor
41 {
42 
43 template <class TInput, class TOutput>
44 class ITK_TEMPLATE_EXPORT SoftThreshold
45 {
46 public:
48  ~SoftThreshold() = default;
49 
50  void
51  SetThreshold(const TInput & thresh)
52  {
53  m_Threshold = thresh;
54  }
55 
56  bool
57  operator!=(const SoftThreshold & other) const
58  {
59  if (m_Threshold != other.m_Threshold)
60  {
61  return true;
62  }
63  return false;
64  }
65  bool
66  operator==(const SoftThreshold & other) const
67  {
68  return !(*this != other);
69  }
70 
71  inline TOutput
72  operator()(const TInput & A) const
73  {
74  return (itk::Math::sgn(A) * std::max((TInput)itk::Math::abs(A) - m_Threshold, (TInput)0.0));
75  }
76 
77 private:
78  TInput m_Threshold;
79 };
80 } // namespace Functor
81 
82 template <class TInputImage, class TOutputImage>
83 class ITK_TEMPLATE_EXPORT SoftThresholdImageFilter
85  TInputImage,
86  TOutputImage,
87  Functor::SoftThreshold<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
88 {
89 public:
90  ITK_DISALLOW_COPY_AND_MOVE(SoftThresholdImageFilter);
91 
95  TInputImage,
96  TOutputImage,
101 
103  itkNewMacro(Self);
104 
106 #ifdef itkOverrideGetNameOfClassMacro
107  itkOverrideGetNameOfClassMacro(SoftThresholdImageFilter);
108 #else
110 #endif
111 
112 
114  using InputPixelType = typename TInputImage::PixelType;
115  using OutputPixelType = typename TOutputImage::PixelType;
116 
119 
121  virtual void
122  SetThreshold(const InputPixelType threshold);
123 
124 #ifdef ITK_USE_CONCEPT_CHECKING
125 
126  itkConceptMacro(OutputEqualityComparableCheck, (itk::Concept::EqualityComparable<OutputPixelType>));
127  itkConceptMacro(InputPixelTypeComparable, (itk::Concept::Comparable<InputPixelType>));
130 
132 #endif
133 
134 protected:
136  ~SoftThresholdImageFilter() override = default;
137 };
138 
139 } // end namespace rtk
140 
141 #ifndef ITK_MANUAL_INSTANTIATION
142 # include "rtkSoftThresholdImageFilter.hxx"
143 #endif
144 
145 #endif
bool operator==(const SoftThreshold &other) const
bool operator!=(const SoftThreshold &other) const
bool abs(bool x)
typename TOutputImage::PixelType OutputPixelType
typename TInputImage::PixelType InputPixelType
void SetThreshold(const TInput &thresh)
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::SoftThreshold< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
#define itkConceptMacro(name, concept)
TOutput operator()(const TInput &A) const