ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkSigmoidImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software 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 #ifndef itkSigmoidImageFilter_h
19 #define itkSigmoidImageFilter_h
20 
22 #include "itkMath.h"
23 
24 namespace itk
25 {
48 namespace Functor
49 {
50 template< typename TInput, typename TOutput >
51 class Sigmoid
52 {
53 public:
55  {
56  m_Alpha = 1.0;
57  m_Beta = 0.0;
60  }
61 
62  ~Sigmoid() {}
63  bool operator!=(const Sigmoid & other) const
64  {
69  {
70  return true;
71  }
72  return false;
73  }
74 
75  bool operator==(const Sigmoid & other) const
76  {
77  return !( *this != other );
78  }
79 
80  inline TOutput operator()(const TInput & A) const
81  {
82  const double x = ( static_cast< double >( A ) - m_Beta ) / m_Alpha;
83  const double e = 1.0 / ( 1.0 + std::exp(-x) );
84  const double v =
86 
87  return static_cast< TOutput >( v );
88  }
89 
90  void SetAlpha(double alpha)
91  {
92  m_Alpha = alpha;
93  }
94 
95  void SetBeta(double beta)
96  {
97  m_Beta = beta;
98  }
99 
100  double GetAlpha() const
101  {
102  return m_Alpha;
103  }
104 
105  double GetBeta() const
106  {
107  return m_Beta;
108  }
109 
110  void SetOutputMinimum(TOutput min)
111  {
112  m_OutputMinimum = min;
113  }
114 
115  void SetOutputMaximum(TOutput max)
116  {
117  m_OutputMaximum = max;
118  }
119 
120  TOutput GetOutputMinimum() const
121  {
122  return m_OutputMinimum;
123  }
124 
125  TOutput GetOutputMaximum() const
126  {
127  return m_OutputMaximum;
128  }
129 
130 private:
131  double m_Alpha;
132  double m_Beta;
135 };
136 }
137 
138 template< typename TInputImage, typename TOutputImage >
140  public
141  UnaryFunctorImageFilter< TInputImage, TOutputImage,
142  Functor::Sigmoid<
143  typename TInputImage::PixelType,
144  typename TOutputImage::PixelType > >
145 {
146 public:
149  typedef UnaryFunctorImageFilter<
150  TInputImage, TOutputImage,
151  Functor::Sigmoid< typename TInputImage::PixelType,
152  typename TOutputImage::PixelType > > Superclass;
153 
156 
157  typedef typename TOutputImage::PixelType OutputPixelType;
158 
160  itkNewMacro(Self);
161 
164 
165  void SetAlpha(double alpha)
166  {
167  if ( Math::ExactlyEquals(alpha, this->GetFunctor().GetAlpha()) )
168  {
169  return;
170  }
171  this->GetFunctor().SetAlpha(alpha);
172  this->Modified();
173  }
174 
175  double GetAlpha() const
176  {
177  return this->GetFunctor().GetAlpha();
178  }
179 
180  void SetBeta(double beta)
181  {
182  if ( Math::ExactlyEquals(beta, this->GetFunctor().GetBeta()) )
183  {
184  return;
185  }
186  this->GetFunctor().SetBeta(beta);
187  this->Modified();
188  }
189 
190  double GetBeta() const
191  {
192  return this->GetFunctor().GetBeta();
193  }
194 
196  {
197  if ( Math::ExactlyEquals(min, this->GetFunctor().GetOutputMinimum()) )
198  {
199  return;
200  }
201  this->GetFunctor().SetOutputMinimum(min);
202  this->Modified();
203  }
204 
206  {
207  return this->GetFunctor().GetOutputMinimum();
208  }
209 
211  {
212  if ( Math::ExactlyEquals(max, this->GetFunctor().GetOutputMaximum()) )
213  {
214  return;
215  }
216  this->GetFunctor().SetOutputMaximum(max);
217  this->Modified();
218  }
219 
221  {
222  return this->GetFunctor().GetOutputMaximum();
223  }
224 
225 #ifdef ITK_USE_CONCEPT_CHECKING
226  // Begin concept checking
227  itkConceptMacro( InputConvertibleToDoubleCheck,
229  itkConceptMacro( OutputAdditiveOperatorsCheck,
231  itkConceptMacro( DoubleConvertibleToOutputCheck,
233  itkConceptMacro( OutputTimesDoubleCheck,
235  itkConceptMacro( OutputDoubleAdditiveOperatorsCheck,
237  // End concept checking
238 #endif
239 
240 protected:
242  virtual ~SigmoidImageFilter() ITK_OVERRIDE {}
243 
244 private:
245  ITK_DISALLOW_COPY_AND_ASSIGN(SigmoidImageFilter);
246 };
247 } // end namespace itk
248 
249 #endif
void SetOutputMaximum(TOutput max)
bool operator==(const Sigmoid &other) const
SmartPointer< Self > Pointer
TOutput operator()(const TInput &A) const
TOutput GetOutputMinimum() const
void SetOutputMinimum(TOutput min)
TOutput GetOutputMaximum() const
OutputPixelType GetOutputMaximum() const
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potetially different types...
Definition: itkMath.h:710
Base class for all process objects that output image data.
Computes the sigmoid function pixel-wise.
void SetOutputMinimum(OutputPixelType min)
void SetAlpha(double alpha)
static ITK_CONSTEXPR_FUNC T max(const T &)
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Sigmoid< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
virtual ~SigmoidImageFilter() override
bool operator!=(const Sigmoid &other) const
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:721
virtual void Modified() const
TOutputImage::PixelType OutputPixelType
SmartPointer< const Self > ConstPointer
static ITK_CONSTEXPR_FUNC T min(const T &)
Implements pixel-wise generic operation on one image.
void SetOutputMaximum(OutputPixelType max)
OutputPixelType GetOutputMinimum() const
static ITK_CONSTEXPR_VAR double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:56
#define itkConceptMacro(name, concept)