ITK  4.8.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 
23 namespace itk
24 {
47 namespace Functor
48 {
49 template< typename TInput, typename TOutput >
50 class Sigmoid
51 {
52 public:
54  {
55  m_Alpha = 1.0;
56  m_Beta = 0.0;
59  }
60 
61  ~Sigmoid() {}
62  bool operator!=(const Sigmoid & other) const
63  {
64  if ( m_Alpha != other.m_Alpha
65  || m_Beta != other.m_Beta
67  || m_OutputMinimum != other.m_OutputMinimum )
68  {
69  return true;
70  }
71  return false;
72  }
73 
74  bool operator==(const Sigmoid & other) const
75  {
76  return !( *this != other );
77  }
78 
79  inline TOutput operator()(const TInput & A) const
80  {
81  const double x = ( static_cast< double >( A ) - m_Beta ) / m_Alpha;
82  const double e = 1.0 / ( 1.0 + std::exp(-x) );
83  const double v =
85 
86  return static_cast< TOutput >( v );
87  }
88 
89  void SetAlpha(double alpha)
90  {
91  m_Alpha = alpha;
92  }
93 
94  void SetBeta(double beta)
95  {
96  m_Beta = beta;
97  }
98 
99  double GetAlpha() const
100  {
101  return m_Alpha;
102  }
103 
104  double GetBeta() const
105  {
106  return m_Beta;
107  }
108 
109  void SetOutputMinimum(TOutput min)
110  {
111  m_OutputMinimum = min;
112  }
113 
114  void SetOutputMaximum(TOutput max)
115  {
116  m_OutputMaximum = max;
117  }
118 
119  TOutput GetOutputMinimum() const
120  {
121  return m_OutputMinimum;
122  }
123 
124  TOutput GetOutputMaximum() const
125  {
126  return m_OutputMaximum;
127  }
128 
129 private:
130  double m_Alpha;
131  double m_Beta;
134 };
135 }
136 
137 template< typename TInputImage, typename TOutputImage >
139  public
140  UnaryFunctorImageFilter< TInputImage, TOutputImage,
141  Functor::Sigmoid<
142  typename TInputImage::PixelType,
143  typename TOutputImage::PixelType > >
144 {
145 public:
148  typedef UnaryFunctorImageFilter<
149  TInputImage, TOutputImage,
150  Functor::Sigmoid< typename TInputImage::PixelType,
151  typename TOutputImage::PixelType > > Superclass;
152 
155 
156  typedef typename TOutputImage::PixelType OutputPixelType;
157 
159  itkNewMacro(Self);
160 
163 
164  void SetAlpha(double alpha)
165  {
166  if ( alpha == this->GetFunctor().GetAlpha() )
167  {
168  return;
169  }
170  this->GetFunctor().SetAlpha(alpha);
171  this->Modified();
172  }
173 
174  double GetAlpha() const
175  {
176  return this->GetFunctor().GetAlpha();
177  }
178 
179  void SetBeta(double beta)
180  {
181  if ( beta == this->GetFunctor().GetBeta() )
182  {
183  return;
184  }
185  this->GetFunctor().SetBeta(beta);
186  this->Modified();
187  }
188 
189  double GetBeta() const
190  {
191  return this->GetFunctor().GetBeta();
192  }
193 
195  {
196  if ( min == this->GetFunctor().GetOutputMinimum() )
197  {
198  return;
199  }
200  this->GetFunctor().SetOutputMinimum(min);
201  this->Modified();
202  }
203 
205  {
206  return this->GetFunctor().GetOutputMinimum();
207  }
208 
210  {
211  if ( max == this->GetFunctor().GetOutputMaximum() )
212  {
213  return;
214  }
215  this->GetFunctor().SetOutputMaximum(max);
216  this->Modified();
217  }
218 
220  {
221  return this->GetFunctor().GetOutputMaximum();
222  }
223 
224 #ifdef ITK_USE_CONCEPT_CHECKING
225  // Begin concept checking
226  itkConceptMacro( InputConvertibleToDoubleCheck,
228  itkConceptMacro( OutputAdditiveOperatorsCheck,
230  itkConceptMacro( DoubleConvertibleToOutputCheck,
232  itkConceptMacro( OutputTimesDoubleCheck,
234  itkConceptMacro( OutputDoubleAdditiveOperatorsCheck,
236  // End concept checking
237 #endif
238 
239 protected:
241  virtual ~SigmoidImageFilter() {}
242 
243 private:
244  SigmoidImageFilter(const Self &); //purposely not implemented
245  void operator=(const Self &); //purposely not implemented
246 };
247 } // end namespace itk
248 
249 #endif
void SetOutputMaximum(TOutput max)
void operator=(const Self &)
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
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
Base class for all process objects that output image data.
static T min(const T &)
Computes the sigmoid function pixel-wise.
void SetOutputMinimum(OutputPixelType min)
void SetAlpha(double alpha)
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Sigmoid< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
static T max(const T &)
bool operator!=(const Sigmoid &other) const
virtual void Modified() const
TOutputImage::PixelType OutputPixelType
SmartPointer< const Self > ConstPointer
Implements pixel-wise generic operation on one image.
void SetOutputMaximum(OutputPixelType max)
OutputPixelType GetOutputMinimum() const
#define itkConceptMacro(name, concept)