ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageKmeansModelEstimator.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 itkImageKmeansModelEstimator_h
19#define itkImageKmeansModelEstimator_h
20
21#include <ctime>
22#include <cmath>
23#include <cfloat>
24
25#include "vnl/vnl_vector.h"
26#include "vnl/vnl_matrix.h"
27#include "itkMath.h"
28
30#include "itkMacro.h"
31#if !defined(ITK_LEGACY_REMOVE) && !defined(ITK_FUTURE_LEGACY_REMOVE)
32# include "vnl/algo/vnl_matrix_inverse.h" // transitional transitive include; dropped on ITK legacy removal
33#endif
34
36
37constexpr int8_t ONEBAND{ 1 };
38constexpr int8_t GLA_CONVERGED{ 1 };
39constexpr int8_t GLA_NOT_CONVERGED{ 2 };
40constexpr int8_t LBG_COMPLETED{ 3 };
41
42namespace itk
43{
130template <typename TInputImage, typename TMembershipFunction>
131class ITK_TEMPLATE_EXPORT ImageKmeansModelEstimator : public ImageModelEstimatorBase<TInputImage, TMembershipFunction>
132{
133public:
134 ITK_DISALLOW_COPY_AND_MOVE(ImageKmeansModelEstimator);
135
139
142
144 itkNewMacro(Self);
145
147 itkOverrideGetNameOfClassMacro(ImageKmeansModelEstimator);
148
150 using InputImageType = TInputImage;
151 using InputImagePointer = typename TInputImage::Pointer;
152 using InputImageConstPointer = typename TInputImage::ConstPointer;
153
156 using InputImageVectorType = typename TInputImage::PixelType::VectorType;
157
159 using InputImagePixelType = typename TInputImage::PixelType;
160
163
165
167 using MembershipFunctionPointer = typename TMembershipFunction::Pointer;
168
170 using CodebookMatrixOfDoubleType = vnl_matrix<double>;
171
173 using CodebookMatrixOfIntegerType = vnl_matrix<int>;
174
176 void
178
180 itkGetConstMacro(Codebook, CodebookMatrixOfDoubleType);
181
185 {
186 return m_Codebook;
187 }
188
191 itkSetMacro(Threshold, double);
192 itkGetConstMacro(Threshold, double);
196 itkSetMacro(OffsetAdd, double);
197 itkGetConstMacro(OffsetAdd, double);
201 itkSetMacro(OffsetMultiply, double);
202 itkGetConstMacro(OffsetMultiply, double);
206 itkSetMacro(MaxSplitAttempts, int);
207 itkGetConstMacro(MaxSplitAttempts, int);
212 {
213 return m_Centroid;
214 }
215
216protected:
218 ~ImageKmeansModelEstimator() override = default;
219 void
220 PrintSelf(std::ostream & os, Indent indent) const override;
221
223 void
224 GenerateData() override;
225
227 void
229
231 void
233
234private:
243 void
244 EstimateModels() override;
245
247 void
249
250 using ImageSizeType = typename TInputImage::SizeType;
251
253 using InputPixelVectorType = typename TInputImage::PixelType::VectorType;
254
256 void
257 Reallocate(int oldSize, int newSize);
258
259 int
261
262 int
264
265 void
266 NearestNeighborSearchBasic(double * distortion);
267
268 void
269 SplitCodewords(int currentSize, int numDesired, int scale);
270
271 void
272 Perturb(double * oldCodeword, int scale, double * newCodeword);
273
275
276 // Buffer for K-means calculations
278
279 double m_Threshold{};
280 double m_OffsetAdd{};
283
288
292
295}; // class ImageKmeansModelEstimator
296
297} // end namespace itk
298
299#ifndef ITK_MANUAL_INSTANTIATION
300# include "itkImageKmeansModelEstimator.hxx"
301#endif
302
303#endif
void Reallocate(int oldSize, int newSize)
ImageRegionConstIterator< TInputImage > InputImageConstIterator
typename TInputImage::Pointer InputImagePointer
typename TInputImage::PixelType::VectorType InputPixelVectorType
typename TMembershipFunction::Pointer MembershipFunctionPointer
~ImageKmeansModelEstimator() override=default
typename TInputImage::ConstPointer InputImageConstPointer
void NearestNeighborSearchBasic(double *distortion)
void PrintSelf(std::ostream &os, Indent indent) const override
CodebookMatrixOfIntegerType m_CodewordHistogram
void SplitCodewords(int currentSize, int numDesired, int scale)
CodebookMatrixOfDoubleType m_CodewordDistortion
typename TInputImage::PixelType InputImagePixelType
void SetCodebook(CodebookMatrixOfDoubleType inCodebook)
ImageRegionIterator< TInputImage > InputImageIterator
CodebookMatrixOfDoubleType GetKmeansResults()
void Perturb(double *oldCodeword, int scale, double *newCodeword)
typename TInputImage::PixelType::VectorType InputImageVectorType
ImageModelEstimatorBase< TInputImage, TMembershipFunction > Superclass
typename TInputImage::SizeType ImageSizeType
CodebookMatrixOfDoubleType GetOutCodebook()
A multi-dimensional iterator templated over image type that walks a region of pixels.
A multi-dimensional iterator templated over image type that walks a region of pixels.
Control indentation during Print() invocation.
Definition itkIndent.h:51
Implements transparent reference counting.
constexpr int8_t GLA_NOT_CONVERGED
constexpr int8_t LBG_COMPLETED
constexpr int8_t ONEBAND
constexpr int8_t GLA_CONVERGED
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86