RTK  2.0.1
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  * http://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 template< class TInput, class TOutput>
44 {
45 public:
47  {
48  m_Threshold = itk::NumericTraits<TInput>::Zero;
49  }
50  ~SoftThreshold() = default;
51 
52  void SetThreshold( const TInput & thresh )
53  { m_Threshold = thresh; }
54 
55  bool operator!=( const SoftThreshold & other ) const
56  {
57  if( m_Threshold != other.m_Threshold )
58  {
59  return true;
60  }
61  return false;
62  }
63  bool operator==( const SoftThreshold & other ) const
64  {
65  return !(*this != other);
66  }
67 
68  inline TOutput operator()( const TInput & A ) const
69  {
70  return (itk::Math::sgn(A) * std::max((TInput)itk::Math::abs(A) - m_Threshold, (TInput)0.0));
71  }
72 
73 private:
74  TInput m_Threshold;
75 
76 };
77 }
78 
79 template <class TInputImage, class TOutputImage>
80 class ITK_EXPORT SoftThresholdImageFilter :
81  public
82 itk::UnaryFunctorImageFilter<TInputImage,TOutputImage,
83  Functor::SoftThreshold<
84  typename TInputImage::PixelType,
85  typename TOutputImage::PixelType> >
86 {
87 public:
88  ITK_DISALLOW_COPY_AND_ASSIGN(SoftThresholdImageFilter);
89 
93  <TInputImage,TOutputImage,
94  Functor::SoftThreshold< typename TInputImage::PixelType,
95  typename TOutputImage::PixelType> > Superclass;
98 
100  itkNewMacro(Self);
101 
104 
106  using InputPixelType = typename TInputImage::PixelType;
107  using OutputPixelType = typename TOutputImage::PixelType;
108 
111 
113  virtual void SetThreshold(const InputPixelType threshold);
114 
115 #ifdef ITK_USE_CONCEPT_CHECKING
116 
117  itkConceptMacro(OutputEqualityComparableCheck,
119  itkConceptMacro(InputPixelTypeComparable,
121  itkConceptMacro(InputOStreamWritableCheck,
123  itkConceptMacro(OutputOStreamWritableCheck,
125 
127 #endif
128 
129 protected:
131  ~SoftThresholdImageFilter() override = default;
132 
133 };
134 
135 } // end namespace rtk
136 
137 #ifndef ITK_MANUAL_INSTANTIATION
138 #include "rtkSoftThresholdImageFilter.hxx"
139 #endif
140 
141 #endif
TOutput operator()(const TInput &A) const
typename TOutputImage::PixelType OutputPixelType
typename TInputImage::PixelType InputPixelType
bool operator!=(const SoftThreshold &other) const
void SetThreshold(const TInput &thresh)
itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::SoftThreshold< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
#define itkConceptMacro(name, concept)
bool operator==(const SoftThreshold &other) const