ITK  5.4.0
Insight Toolkit
itkSigmoidImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
24namespace itk
25{
50namespace Functor
51{
52template <typename TInput, typename TOutput>
54{
55public:
57 {
58 m_Alpha = 1.0;
59 m_Beta = 0.0;
62 }
63
64 ~Sigmoid() = default;
65
66
67 bool
68 operator==(const Sigmoid & other) const
69 {
73 }
74
76
77 inline TOutput
78 operator()(const TInput & A) const
79 {
80 const double x = (static_cast<double>(A) - m_Beta) / m_Alpha;
81 const double e = 1.0 / (1.0 + std::exp(-x));
82 const double v = (m_OutputMaximum - m_OutputMinimum) * e + m_OutputMinimum;
83
84 return static_cast<TOutput>(v);
85 }
86
87 void
88 SetAlpha(double alpha)
89 {
90 m_Alpha = alpha;
91 }
92
93 void
94 SetBeta(double beta)
95 {
96 m_Beta = beta;
97 }
98
99 double
100 GetAlpha() const
101 {
102 return m_Alpha;
103 }
104
105 double
106 GetBeta() const
107 {
108 return m_Beta;
109 }
110
111 void
112 SetOutputMinimum(TOutput min)
113 {
114 m_OutputMinimum = min;
115 }
116
117 void
118 SetOutputMaximum(TOutput max)
119 {
120 m_OutputMaximum = max;
121 }
122
123 TOutput
125 {
126 return m_OutputMinimum;
127 }
128
129 TOutput
131 {
132 return m_OutputMaximum;
133 }
134
135private:
136 double m_Alpha;
137 double m_Beta;
140};
141} // namespace Functor
142
143template <typename TInputImage, typename TOutputImage>
145 : public UnaryFunctorImageFilter<TInputImage,
146 TOutputImage,
147 Functor::Sigmoid<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
148{
149public:
150 ITK_DISALLOW_COPY_AND_MOVE(SigmoidImageFilter);
151
155 UnaryFunctorImageFilter<TInputImage,
156 TOutputImage,
158
161
162 using OutputPixelType = typename TOutputImage::PixelType;
163
165 itkNewMacro(Self);
166
168 itkOverrideGetNameOfClassMacro(SigmoidImageFilter);
169
170 void
171 SetAlpha(double alpha)
172 {
173 if (Math::ExactlyEquals(alpha, this->GetFunctor().GetAlpha()))
174 {
175 return;
176 }
177 this->GetFunctor().SetAlpha(alpha);
178 this->Modified();
179 }
180
181 double
182 GetAlpha() const
183 {
184 return this->GetFunctor().GetAlpha();
185 }
186
187 void
188 SetBeta(double beta)
189 {
190 if (Math::ExactlyEquals(beta, this->GetFunctor().GetBeta()))
191 {
192 return;
193 }
194 this->GetFunctor().SetBeta(beta);
195 this->Modified();
196 }
197
198 double
199 GetBeta() const
200 {
201 return this->GetFunctor().GetBeta();
202 }
203
204 void
206 {
208 {
209 return;
210 }
211 this->GetFunctor().SetOutputMinimum(min);
212 this->Modified();
213 }
214
217 {
218 return this->GetFunctor().GetOutputMinimum();
219 }
220
221 void
223 {
225 {
226 return;
227 }
228 this->GetFunctor().SetOutputMaximum(max);
229 this->Modified();
230 }
231
234 {
235 return this->GetFunctor().GetOutputMaximum();
236 }
237
238#ifdef ITK_USE_CONCEPT_CHECKING
239 // Begin concept checking
241 itkConceptMacro(OutputAdditiveOperatorsCheck, (Concept::AdditiveOperators<OutputPixelType>));
242 itkConceptMacro(DoubleConvertibleToOutputCheck, (Concept::Convertible<double, OutputPixelType>));
244 itkConceptMacro(OutputDoubleAdditiveOperatorsCheck,
246 // End concept checking
247#endif
248
249protected:
251 ~SigmoidImageFilter() override = default;
252};
253} // end namespace itk
254
255#endif
void SetOutputMinimum(TOutput min)
TOutput GetOutputMinimum() const
void SetOutputMaximum(TOutput max)
bool operator==(const Sigmoid &other) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Sigmoid)
TOutput GetOutputMaximum() const
void SetAlpha(double alpha)
TOutput operator()(const TInput &A) const
Base class for all process objects that output image data.
static constexpr T max(const T &)
static constexpr T min(const T &)
virtual void Modified() const
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Computes the sigmoid function pixel-wise.
void SetOutputMinimum(OutputPixelType min)
OutputPixelType GetOutputMaximum() const
void SetOutputMaximum(OutputPixelType max)
~SigmoidImageFilter() override=default
OutputPixelType GetOutputMinimum() const
typename TOutputImage::PixelType OutputPixelType
Implements pixel-wise generic operation on one image.
#define itkConceptMacro(name, concept)
bool ExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Return the result of an exact comparison between two scalar values of potentially different types.
Definition: itkMath.h:726
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....