ITK  5.0.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() = default;
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:
147  ITK_DISALLOW_COPY_AND_ASSIGN(SigmoidImageFilter);
148 
152  TInputImage, TOutputImage,
153  Functor::Sigmoid< typename TInputImage::PixelType,
154  typename TOutputImage::PixelType > >;
155 
158 
159  using OutputPixelType = typename TOutputImage::PixelType;
160 
162  itkNewMacro(Self);
163 
166 
167  void SetAlpha(double alpha)
168  {
169  if ( Math::ExactlyEquals(alpha, this->GetFunctor().GetAlpha()) )
170  {
171  return;
172  }
173  this->GetFunctor().SetAlpha(alpha);
174  this->Modified();
175  }
176 
177  double GetAlpha() const
178  {
179  return this->GetFunctor().GetAlpha();
180  }
181 
182  void SetBeta(double beta)
183  {
184  if ( Math::ExactlyEquals(beta, this->GetFunctor().GetBeta()) )
185  {
186  return;
187  }
188  this->GetFunctor().SetBeta(beta);
189  this->Modified();
190  }
191 
192  double GetBeta() const
193  {
194  return this->GetFunctor().GetBeta();
195  }
196 
198  {
199  if ( Math::ExactlyEquals(min, this->GetFunctor().GetOutputMinimum()) )
200  {
201  return;
202  }
203  this->GetFunctor().SetOutputMinimum(min);
204  this->Modified();
205  }
206 
208  {
209  return this->GetFunctor().GetOutputMinimum();
210  }
211 
213  {
214  if ( Math::ExactlyEquals(max, this->GetFunctor().GetOutputMaximum()) )
215  {
216  return;
217  }
218  this->GetFunctor().SetOutputMaximum(max);
219  this->Modified();
220  }
221 
223  {
224  return this->GetFunctor().GetOutputMaximum();
225  }
226 
227 #ifdef ITK_USE_CONCEPT_CHECKING
228  // Begin concept checking
229  itkConceptMacro( InputConvertibleToDoubleCheck,
231  itkConceptMacro( OutputAdditiveOperatorsCheck,
233  itkConceptMacro( DoubleConvertibleToOutputCheck,
235  itkConceptMacro( OutputTimesDoubleCheck,
237  itkConceptMacro( OutputDoubleAdditiveOperatorsCheck,
239  // End concept checking
240 #endif
241 
242 protected:
243  SigmoidImageFilter() = default;
244  ~SigmoidImageFilter() override = default;
245 };
246 } // end namespace itk
247 
248 #endif
void SetOutputMaximum(TOutput max)
Define numeric traits for std::vector.
typename TOutputImage::PixelType OutputPixelType
bool operator==(const Sigmoid &other) const
TOutput operator()(const TInput &A) const
TOutput GetOutputMinimum() const
void SetOutputMinimum(TOutput min)
TOutput GetOutputMaximum() const
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
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:707
Base class for all process objects that output image data.
Computes the sigmoid function pixel-wise.
void SetOutputMinimum(OutputPixelType min)
void SetAlpha(double alpha)
~SigmoidImageFilter() override=default
bool operator!=(const Sigmoid &other) const
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:718
virtual void Modified() const
Implements pixel-wise generic operation on one image.
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
void SetOutputMaximum(OutputPixelType max)
OutputPixelType GetOutputMinimum() const
#define itkConceptMacro(name, concept)