ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
48
49namespace Functor
50{
51template <typename TInput, typename TOutput>
53{
54public:
56 : m_OutputMinimum(NumericTraits<TOutput>::min())
57 , m_OutputMaximum(NumericTraits<TOutput>::max())
58 {}
59
60 ~Sigmoid() = default;
61
62
63 bool
70
72
73 inline TOutput
74 operator()(const TInput & A) const
75 {
76 const double x = (static_cast<double>(A) - m_Beta) / m_Alpha;
77 const double e = 1.0 / (1.0 + std::exp(-x));
78 const double v = (m_OutputMaximum - m_OutputMinimum) * e + m_OutputMinimum;
79
80 return static_cast<TOutput>(v);
81 }
82
83 void
84 SetAlpha(double alpha)
85 {
86 m_Alpha = alpha;
87 }
88
89 void
90 SetBeta(double beta)
91 {
92 m_Beta = beta;
93 }
94
95 [[nodiscard]] double
96 GetAlpha() const
97 {
98 return m_Alpha;
99 }
100
101 [[nodiscard]] double
102 GetBeta() const
103 {
104 return m_Beta;
105 }
106
107 void
108 SetOutputMinimum(TOutput min)
109 {
110 m_OutputMinimum = min;
111 }
112
113 void
114 SetOutputMaximum(TOutput max)
115 {
116 m_OutputMaximum = max;
117 }
118
119 [[nodiscard]] TOutput
121 {
122 return m_OutputMinimum;
123 }
124
125 [[nodiscard]] TOutput
127 {
128 return m_OutputMaximum;
129 }
130
131private:
132 double m_Alpha{ 1.0 };
133 double m_Beta{ 0.0 };
136};
137} // namespace Functor
138
139template <typename TInputImage, typename TOutputImage>
141 : public UnaryFunctorImageFilter<TInputImage,
142 TOutputImage,
143 Functor::Sigmoid<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
144{
145public:
146 ITK_DISALLOW_COPY_AND_MOVE(SigmoidImageFilter);
147
151 UnaryFunctorImageFilter<TInputImage,
152 TOutputImage,
154
157
158 using OutputPixelType = typename TOutputImage::PixelType;
159
161 itkNewMacro(Self);
162
164 itkOverrideGetNameOfClassMacro(SigmoidImageFilter);
165
166 void
167 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 [[nodiscard]] double
178 GetAlpha() const
179 {
180 return this->GetFunctor().GetAlpha();
181 }
182
183 void
184 SetBeta(double beta)
185 {
186 if (Math::ExactlyEquals(beta, this->GetFunctor().GetBeta()))
187 {
188 return;
189 }
190 this->GetFunctor().SetBeta(beta);
191 this->Modified();
192 }
193
194 [[nodiscard]] double
195 GetBeta() const
196 {
197 return this->GetFunctor().GetBeta();
198 }
199
200 void
202 {
204 {
205 return;
206 }
207 this->GetFunctor().SetOutputMinimum(min);
208 this->Modified();
209 }
210
213 {
214 return this->GetFunctor().GetOutputMinimum();
215 }
216
217 void
219 {
221 {
222 return;
223 }
224 this->GetFunctor().SetOutputMaximum(max);
225 this->Modified();
226 }
227
230 {
231 return this->GetFunctor().GetOutputMaximum();
232 }
233
235 itkConceptMacro(OutputAdditiveOperatorsCheck, (Concept::AdditiveOperators<OutputPixelType>));
236 itkConceptMacro(DoubleConvertibleToOutputCheck, (Concept::Convertible<double, OutputPixelType>));
238 itkConceptMacro(OutputDoubleAdditiveOperatorsCheck,
240
241protected:
243 ~SigmoidImageFilter() override = default;
244};
245} // end namespace itk
246
247#endif
void SetOutputMinimum(TOutput min)
void SetOutputMaximum(TOutput max)
bool operator==(const Sigmoid &other) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(Sigmoid)
void SetAlpha(double alpha)
TOutput operator()(const TInput &A) const
Define additional traits for native types such as int or float.
virtual void Modified() const
void SetOutputMinimum(OutputPixelType min)
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::Sigmoid< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
OutputPixelType GetOutputMaximum() const
SmartPointer< const Self > ConstPointer
void SetOutputMaximum(OutputPixelType max)
~SigmoidImageFilter() override=default
OutputPixelType GetOutputMinimum() const
typename TOutputImage::PixelType OutputPixelType
Implements transparent reference counting.
#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:716
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....