ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkImageKmeansModelEstimator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 "vnl/vnl_math.h"
28 #include "vnl/algo/vnl_matrix_inverse.h"
29 
30 #include "itkImageRegionIterator.h"
31 #include "itkMacro.h"
32 
34 
35 #define ONEBAND 1
36 #define GLA_CONVERGED 1
37 #define GLA_NOT_CONVERGED 2
38 #define LBG_COMPLETED 3
39 
40 namespace itk
41 {
129 template< typename TInputImage,
130  typename TMembershipFunction >
132  public ImageModelEstimatorBase< TInputImage, TMembershipFunction >
133 {
134 public:
139 
142 
144  itkNewMacro(Self);
145 
148 
150  typedef TInputImage InputImageType;
151  typedef typename TInputImage::Pointer InputImagePointer;
152  typedef typename TInputImage::ConstPointer InputImageConstPointer;
153 
156  typedef typename TInputImage::PixelType::VectorType InputImageVectorType;
157 
159  typedef typename TInputImage::PixelType InputImagePixelType;
160 
163 
165 
167  typedef typename TMembershipFunction::Pointer MembershipFunctionPointer;
168 
170  typedef vnl_matrix< double > CodebookMatrixOfDoubleType;
171 
173  typedef vnl_matrix< int > CodebookMatrixOfIntegerType;
174 
176  void SetCodebook(CodebookMatrixOfDoubleType InCodebook);
177 
179  itkGetConstMacro(Codebook, CodebookMatrixOfDoubleType);
180 
183 
185  itkSetMacro(Threshold, double);
186 
188  itkGetConstMacro(Threshold, double);
189 
191  itkSetMacro(OffsetAdd, double);
192 
194  itkGetConstMacro(OffsetAdd, double);
195 
197  itkSetMacro(OffsetMultiply, double);
198 
200  itkGetConstMacro(OffsetMultiply, double);
201 
203  itkSetMacro(MaxSplitAttempts, int);
204 
206  itkGetConstMacro(MaxSplitAttempts, int);
207 
210 
211 protected:
214  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
215 
217  void GenerateData() ITK_OVERRIDE;
218 
220  void Allocate();
221 
224 
225 private:
226  ImageKmeansModelEstimator(const Self &) ITK_DELETE_FUNCTION;
227  void operator=(const Self &) ITK_DELETE_FUNCTION;
228 
235  virtual void EstimateModels() ITK_OVERRIDE;
236 
238 
239  typedef typename TInputImage::SizeType ImageSizeType;
240 
242  typedef typename TInputImage::PixelType::VectorType InputPixelVectorType;
243 
244  void Reallocate(int oldSize, int newSize);
245 
246  //Local functions
247  int WithCodebookUseGLA(); // GLA stands for the Generalized Lloyd Algorithm
248 
249  int WithoutCodebookUseLBG(); //LBG stands for the Lindo Buzo Gray Algorithm
250 
251  void NearestNeighborSearchBasic(double *distortion);
252 
253  void SplitCodewords(int currentSize,
254  int numDesired,
255  int scale);
256 
257  void Perturb(double *oldCodeword,
258  int scale,
259  double *newCodeword);
260 
262 
263  // Buffer for K-means calcualtions
265 
266  double m_Threshold;
267  double m_OffsetAdd;
270 
275 
279 
282 }; // class ImageKmeansModelEstimator
283 
284 } // namespace itk
285 
286 #ifndef ITK_MANUAL_INSTANTIATION
287 #include "itkImageKmeansModelEstimator.hxx"
288 #endif
289 
290 #endif
void Perturb(double *oldCodeword, int scale, double *newCodeword)
Base class for ImageKmeansModelEstimator object.
Light weight base class for most itk classes.
void Reallocate(int oldSize, int newSize)
ImageRegionIterator< TInputImage > InputImageIterator
CodebookMatrixOfDoubleType GetOutCodebook()
CodebookMatrixOfIntegerType m_CodewordHistogram
TMembershipFunction::Pointer MembershipFunctionPointer
void SetCodebook(CodebookMatrixOfDoubleType InCodebook)
void NearestNeighborSearchBasic(double *distortion)
TInputImage::PixelType::VectorType InputPixelVectorType
Base class for model estimation from images used for classification.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void SplitCodewords(int currentSize, int numDesired, int scale)
ImageModelEstimatorBase< TInputImage, TMembershipFunction > Superclass
ImageRegionConstIterator< TInputImage > InputImageConstIterator
virtual void PrintSelf(std::ostream &os, Indent indent) const override
A multi-dimensional iterator templated over image type that walks a region of pixels.
virtual void EstimateModels() override
CodebookMatrixOfDoubleType m_CodewordDistortion
CodebookMatrixOfDoubleType GetKmeansResults(void)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
TInputImage::PixelType::VectorType InputImageVectorType
TInputImage::ConstPointer InputImageConstPointer
A multi-dimensional iterator templated over image type that walks a region of pixels.