ITK  5.2.0
Insight Toolkit
itkImagePCAShapeModelEstimator.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  * 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 itkImagePCAShapeModelEstimator_h
19 #define itkImagePCAShapeModelEstimator_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 #include "vnl/algo/vnl_matrix_inverse.h"
29 
30 #include "itkImageRegionIterator.h"
31 #include "itkMacro.h"
32 
34 #include "itkConceptChecking.h"
35 #include "itkImage.h"
36 #include "vnl/algo/vnl_generalized_eigensystem.h"
37 #include "vnl/algo/vnl_symmetric_eigensystem.h"
38 
39 namespace itk
40 {
75 template <typename TInputImage, typename TOutputImage = Image<double, TInputImage::ImageDimension>>
76 class ITK_TEMPLATE_EXPORT ImagePCAShapeModelEstimator : public ImageShapeModelEstimatorBase<TInputImage, TOutputImage>
77 {
78 public:
79  ITK_DISALLOW_COPY_AND_ASSIGN(ImagePCAShapeModelEstimator);
80 
86 
88  itkNewMacro(Self);
89 
92 
94  using InputImageType = TInputImage;
95  using InputImagePointer = typename TInputImage::Pointer;
96  using InputImageConstPointer = typename TInputImage::ConstPointer;
97 
99  using InputImagePixelType = typename TInputImage::PixelType;
100 
104 
106  static constexpr unsigned int InputImageDimension = TInputImage::ImageDimension;
107 
109  using OutputImageType = TOutputImage;
110  using OutputImagePointer = typename TOutputImage::Pointer;
111 
114 
116  using MatrixOfDoubleType = vnl_matrix<double>;
117 
119  using MatrixOfIntegerType = vnl_matrix<int>;
120 
122  using VectorOfDoubleType = vnl_vector<double>;
123 
128  virtual void
129  SetNumberOfPrincipalComponentsRequired(unsigned int n);
130 
131  itkGetConstMacro(NumberOfPrincipalComponentsRequired, unsigned int);
132 
134  virtual void
135  SetNumberOfTrainingImages(unsigned int n);
136 
137  itkGetConstMacro(NumberOfTrainingImages, unsigned int);
138 
140  itkGetConstMacro(EigenValues, VectorOfDoubleType);
141 
142 protected:
144  ~ImagePCAShapeModelEstimator() override = default;
145  void
146  PrintSelf(std::ostream & os, Indent indent) const override;
147 
151  void
152  EnlargeOutputRequestedRegion(DataObject *) override;
153 
158  void
159  GenerateInputRequestedRegion() override;
160 
162  void
163  GenerateData() override;
164 
165 private:
167  using InputImagePointerArray = std::vector<InputImageConstPointer>;
168  using InputImageIteratorArray = std::vector<InputImageConstIterator>;
169 
171 
173  using InputPixelType = typename TInputImage::PixelType;
174 
183  void
184  EstimateShapeModels() override;
185 
186  void
187  EstimatePCAShapeModelParameters();
188 
189  void
190  CalculateInnerProduct();
191 
194 
196 
198 
200 
202 
204 
206 
207  unsigned int m_NumberOfPixels{ 0 };
208 
209  // The number of input images for PCA
210  unsigned int m_NumberOfTrainingImages{ 0 };
211 
212  // The number of output Principal Components
214 }; // class ImagePCAShapeModelEstimator
215 } // namespace itk
216 
217 #ifndef ITK_MANUAL_INSTANTIATION
218 # include "itkImagePCAShapeModelEstimator.hxx"
219 #endif
220 
221 #endif
itk::ImageSource::OutputImagePointer
typename OutputImageType::Pointer OutputImagePointer
Definition: itkImageSource.h:91
itk::ImagePCAShapeModelEstimator::m_InnerProduct
MatrixOfDoubleType m_InnerProduct
Definition: itkImagePCAShapeModelEstimator.h:197
itk::ImagePCAShapeModelEstimator::m_EigenValues
VectorOfDoubleType m_EigenValues
Definition: itkImagePCAShapeModelEstimator.h:201
itk::ImagePCAShapeModelEstimator::InputImageIteratorArray
std::vector< InputImageConstIterator > InputImageIteratorArray
Definition: itkImagePCAShapeModelEstimator.h:168
itkConceptChecking.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::ImagePCAShapeModelEstimator::MatrixOfIntegerType
vnl_matrix< int > MatrixOfIntegerType
Definition: itkImagePCAShapeModelEstimator.h:119
itkImage.h
itk::ImagePCAShapeModelEstimator::ImageSizeType
typename TInputImage::SizeType ImageSizeType
Definition: itkImagePCAShapeModelEstimator.h:170
itk::SmartPointer< Self >
itkImageRegionIterator.h
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ImagePCAShapeModelEstimator
Base class for ImagePCAShapeModelEstimator object.
Definition: itkImagePCAShapeModelEstimator.h:76
itk::ImageToImageFilter::InputImagePixelType
typename InputImageType::PixelType InputImagePixelType
Definition: itkImageToImageFilter.h:133
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:78
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::ImagePCAShapeModelEstimator::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkImagePCAShapeModelEstimator.h:173
itk::ImageToImageFilter::InputImagePointer
typename InputImageType::Pointer InputImagePointer
Definition: itkImageToImageFilter.h:130
itkMacro.h
itkImageShapeModelEstimatorBase.h
itk::ImagePCAShapeModelEstimator::VectorOfDoubleType
vnl_vector< double > VectorOfDoubleType
Definition: itkImagePCAShapeModelEstimator.h:122
itk::ImagePCAShapeModelEstimator::m_EigenVectorNormalizedEnergy
VectorOfDoubleType m_EigenVectorNormalizedEnergy
Definition: itkImagePCAShapeModelEstimator.h:203
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk::ImagePCAShapeModelEstimator::m_Means
VectorOfDoubleType m_Means
Definition: itkImagePCAShapeModelEstimator.h:195
itk::ImagePCAShapeModelEstimator::m_InputImageIteratorArray
InputImageIteratorArray m_InputImageIteratorArray
Definition: itkImagePCAShapeModelEstimator.h:193
itk::ImagePCAShapeModelEstimator::MatrixOfDoubleType
vnl_matrix< double > MatrixOfDoubleType
Definition: itkImagePCAShapeModelEstimator.h:116
itk::ImageShapeModelEstimatorBase
Base class for statistical shape model estimation.
Definition: itkImageShapeModelEstimatorBase.h:48
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::ImagePCAShapeModelEstimator::m_NumberOfPrincipalComponentsRequired
unsigned int m_NumberOfPrincipalComponentsRequired
Definition: itkImagePCAShapeModelEstimator.h:213
itk::ImagePCAShapeModelEstimator::m_EigenVectors
MatrixOfDoubleType m_EigenVectors
Definition: itkImagePCAShapeModelEstimator.h:199
itk::ImageRegionConstIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionConstIterator.h:107
itk::ImagePCAShapeModelEstimator::InputImagePointerArray
std::vector< InputImageConstPointer > InputImagePointerArray
Definition: itkImagePCAShapeModelEstimator.h:167
itk::ImagePCAShapeModelEstimator::m_InputImageSize
ImageSizeType m_InputImageSize
Definition: itkImagePCAShapeModelEstimator.h:205
itkMath.h
itk::ImageToImageFilter::InputImageConstPointer
typename InputImageType::ConstPointer InputImageConstPointer
Definition: itkImageToImageFilter.h:131
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293