00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkSigmoidImageFilter_h
00018 #define __itkSigmoidImageFilter_h
00019
00020 #include "itkUnaryFunctorImageFilter.h"
00021
00022 namespace itk
00023 {
00024
00042 namespace Function {
00043 template< class TInput, class TOutput>
00044 class Sigmoid
00045 {
00046 public:
00047 Sigmoid()
00048 {
00049 m_Alpha = 1.0;
00050 m_Beta = 0.0;
00051 m_OutputMinimum = NumericTraits< TOutput >::min();
00052 m_OutputMaximum = NumericTraits< TOutput >::max();
00053 }
00054 ~Sigmoid() {};
00055 bool operator!=( const Sigmoid & other ) const
00056 {
00057 if( m_Alpha != other.m_Alpha ||
00058 m_Beta != other.m_Beta ||
00059 m_OutputMaximum != other.m_OutputMaximum ||
00060 m_OutputMinimum != other.m_OutputMinimum )
00061 {
00062 return true;
00063 }
00064 return false;
00065 }
00066 bool operator==( const Sigmoid & other ) const
00067 {
00068 return !(*this != other);
00069 }
00070
00071 inline TOutput operator()( const TInput & A )
00072 {
00073 const double x = ( static_cast<double>(A) - m_Beta ) / m_Alpha;
00074 const double e = 1.0 / ( 1.0 + vcl_exp(- x ) );
00075 const double v =
00076 (m_OutputMaximum - m_OutputMinimum ) * e + m_OutputMinimum;
00077 return static_cast<TOutput>( v );
00078 }
00079 void SetAlpha( double alpha )
00080 {
00081 m_Alpha = alpha;
00082 }
00083 void SetBeta( double beta )
00084 {
00085 m_Beta = beta;
00086 }
00087 double GetAlpha() const
00088 {
00089 return m_Alpha;
00090 }
00091 double GetBeta() const
00092 {
00093 return m_Beta;
00094 }
00095 void SetOutputMinimum( TOutput min )
00096 {
00097 m_OutputMinimum = min;
00098 }
00099 void SetOutputMaximum( TOutput max )
00100 {
00101 m_OutputMaximum = max;
00102 }
00103 TOutput GetOutputMinimum() const
00104 {
00105 return m_OutputMinimum;
00106 }
00107 TOutput GetOutputMaximum() const
00108 {
00109 return m_OutputMaximum;
00110 }
00111
00112 private:
00113 double m_Alpha;
00114 double m_Beta;
00115 TOutput m_OutputMinimum;
00116 TOutput m_OutputMaximum;
00117 };
00118 }
00119
00120
00121 template <class TInputImage, class TOutputImage>
00122 class ITK_EXPORT SigmoidImageFilter :
00123 public
00124 UnaryFunctorImageFilter<TInputImage,TOutputImage,
00125 Function::Sigmoid<
00126 typename TInputImage::PixelType,
00127 typename TOutputImage::PixelType> >
00128 {
00129 public:
00131 typedef SigmoidImageFilter Self;
00132 typedef UnaryFunctorImageFilter<
00133 TInputImage,TOutputImage,
00134 Function::Sigmoid< typename TInputImage::PixelType,
00135 typename TOutputImage::PixelType> > Superclass;
00136 typedef SmartPointer<Self> Pointer;
00137 typedef SmartPointer<const Self> ConstPointer;
00138
00139 typedef typename TOutputImage::PixelType OutputPixelType;
00140
00142 itkNewMacro(Self);
00143
00145 itkTypeMacro( SigmoidImageFilter, UnaryFunctorImageFilter );
00146
00147 void SetAlpha( double alpha )
00148 {
00149 if( alpha == this->GetFunctor().GetAlpha() )
00150 {
00151 return;
00152 }
00153 this->GetFunctor().SetAlpha( alpha );
00154 this->Modified();
00155 }
00156
00157 void SetBeta( double beta )
00158 {
00159 if( beta == this->GetFunctor().GetBeta() )
00160 {
00161 return;
00162 }
00163 this->GetFunctor().SetBeta( beta );
00164 this->Modified();
00165 }
00166
00167 void SetOutputMinimum( OutputPixelType min )
00168 {
00169 if( min == this->GetFunctor().GetOutputMinimum() )
00170 {
00171 return;
00172 }
00173 this->GetFunctor().SetOutputMinimum( min );
00174 this->Modified();
00175 }
00176
00177 void SetOutputMaximum( OutputPixelType max )
00178 {
00179 if( max == this->GetFunctor().GetOutputMaximum() )
00180 {
00181 return;
00182 }
00183 this->GetFunctor().SetOutputMaximum( max );
00184 this->Modified();
00185 }
00186
00187 #ifdef ITK_USE_CONCEPT_CHECKING
00188
00189 itkConceptMacro(InputConvertibleToDoubleCheck,
00190 (Concept::Convertible<typename TInputImage::PixelType, double>));
00191 itkConceptMacro(OutputAdditiveOperatorsCheck,
00192 (Concept::AdditiveOperators<OutputPixelType>));
00193 itkConceptMacro(DoubleConvertibleToOutputCheck,
00194 (Concept::Convertible<double, OutputPixelType>));
00195 itkConceptMacro(OutputTimesDoubleCheck,
00196 (Concept::MultiplyOperator<OutputPixelType, double>));
00197 itkConceptMacro(OutputDoubleAdditiveOperatorsCheck,
00198 (Concept::AdditiveOperators<OutputPixelType, OutputPixelType, double>));
00199
00201 #endif
00202
00203 protected:
00204 SigmoidImageFilter() {}
00205 virtual ~SigmoidImageFilter() {}
00206
00207 private:
00208 SigmoidImageFilter(const Self&);
00209 void operator=(const Self&);
00210
00211 };
00212
00213 }
00214
00215
00216 #endif
00217