ITK  4.2.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< class TInput, class 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 + vcl_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< class TInputImage, class TOutputImage >
138 class ITK_EXPORT SigmoidImageFilter:
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  void SetBeta(double beta)
175  {
176  if ( beta == this->GetFunctor().GetBeta() )
177  {
178  return;
179  }
180  this->GetFunctor().SetBeta(beta);
181  this->Modified();
182  }
183 
184  void SetOutputMinimum(OutputPixelType min)
185  {
186  if ( min == this->GetFunctor().GetOutputMinimum() )
187  {
188  return;
189  }
190  this->GetFunctor().SetOutputMinimum(min);
191  this->Modified();
192  }
193 
194  void SetOutputMaximum(OutputPixelType max)
195  {
196  if ( max == this->GetFunctor().GetOutputMaximum() )
197  {
198  return;
199  }
200  this->GetFunctor().SetOutputMaximum(max);
201  this->Modified();
202  }
203 
204 #ifdef ITK_USE_CONCEPT_CHECKING
205 
206  itkConceptMacro( InputConvertibleToDoubleCheck,
208  itkConceptMacro( OutputAdditiveOperatorsCheck,
210  itkConceptMacro( DoubleConvertibleToOutputCheck,
212  itkConceptMacro( OutputTimesDoubleCheck,
214  itkConceptMacro( OutputDoubleAdditiveOperatorsCheck,
216 
218 #endif
219 protected:
221  virtual ~SigmoidImageFilter() {}
222 private:
223  SigmoidImageFilter(const Self &); //purposely not implemented
224  void operator=(const Self &); //purposely not implemented
225 };
226 } // end namespace itk
228 
229 #endif
230