ITK  5.4.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 
25 namespace itk
26 {
74 class TargetClass
75 {
76 public:
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  }
111 private:
112  double m_Mean;
113  double m_Sigma;
114 }; // end of class
115 
116 class ITKBiasCorrection_EXPORT CompositeValleyFunction : public CacheableScalarFunction
117 {
118 public:
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  else
161  {
162  return GetCachedValue(x);
163  }
164  }
165 
167  MeasureType
168  Evaluate(MeasureType x) override;
169 
171  inline MeasureType
172  valley(MeasureType d)
173  {
174  return 1 - 1 / (1 + d * d / 3);
175  }
176 
177 protected:
178  void
179  AddNewClass(double mean, double sigma)
180  {
181  TargetClass aClass(mean, sigma);
182 
183  m_Targets.push_back(aClass);
184  }
185 
187  void
188  Initialize();
189 
190 private:
192  std::vector<TargetClass> m_Targets{};
193 
196  double m_UpperBound{};
197 
itkCacheableScalarFunction.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
Superclass
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
Definition: itkAddImageFilter.h:90