ITK  6.0.0
Insight Toolkit
itkCompositeValleyFunction.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 itkCompositeValleyFunction_h
19#define itkCompositeValleyFunction_h
20
22#include "ITKBiasCorrectionExport.h"
23#include <vector>
24
25namespace itk
26{
74class TargetClass
75{
76public:
77
79 TargetClass(double mean, double sigma)
80 {
81 m_Mean = mean;
82 m_Sigma = sigma;
83 }
84
86 void
87 SetMean(double mean)
88 {
89 m_Mean = mean;
90 }
91 double
92 GetMean() const
93 {
94 return m_Mean;
95 }
99 void
100 SetSigma(double sigma)
101 {
102 m_Sigma = sigma;
103 }
104 double
105 GetSigma() const
106 {
107 return m_Sigma;
108 }
111private:
112 double m_Mean;
113 double m_Sigma;
114}; // end of class
115
116class ITKBiasCorrection_EXPORT CompositeValleyFunction : public CacheableScalarFunction
117{
118public:
120 using Superclass = CacheableScalarFunction;
121
123 using MeasureType = Superclass::MeasureType;
124 using MeasureArrayType = Superclass::MeasureArrayType;
125
127 CompositeValleyFunction(const MeasureArrayType & classMeans, const MeasureArrayType & classSigmas);
128
130 ~CompositeValleyFunction() override;
131
133 double
134 GetUpperBound() const
135 {
136 return m_UpperBound;
137 }
138
140 double
141 GetLowerBound() const
142 {
143 return m_LowerBound;
144 }
145
148 MeasureType
149 operator()(MeasureType x)
150 {
151 if (x > m_UpperBound || x < m_LowerBound)
152 {
153 return 1;
154 }
155
156 if (!this->IsCacheAvailable())
157 {
158 return this->Evaluate(x);
159 }
160
161 return GetCachedValue(x);
162 }
163
165 MeasureType
166 Evaluate(MeasureType x) override;
167
169 inline MeasureType
170 valley(MeasureType d)
171 {
172 return 1 - 1 / (1 + d * d / 3);
173 }
174
175protected:
176 void
177 AddNewClass(double mean, double sigma)
178 {
179 const TargetClass aClass(mean, sigma);
180
181 m_Targets.push_back(aClass);
182 }
183
185 void
186 Initialize();
187
188private:
190 std::vector<TargetClass> m_Targets{};
191
194 double m_UpperBound{};
195
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....