ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkImagePCAShapeModelEstimator.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkImagePCAShapeModelEstimator_h
00019 #define __itkImagePCAShapeModelEstimator_h
00020 
00021 #include <time.h>
00022 #include <math.h>
00023 #include <float.h>
00024 
00025 #include "vnl/vnl_vector.h"
00026 #include "vnl/vnl_matrix.h"
00027 #include "vnl/vnl_math.h"
00028 #include "vnl/algo/vnl_matrix_inverse.h"
00029 
00030 #include "itkImageRegionIterator.h"
00031 #include "itkMacro.h"
00032 
00033 #include "itkImageShapeModelEstimatorBase.h"
00034 #include "itkConceptChecking.h"
00035 #include "itkImage.h"
00036 #include "vnl/algo/vnl_generalized_eigensystem.h"
00037 #include "vnl/algo/vnl_symmetric_eigensystem.h"
00038 
00039 namespace itk
00040 {
00075 template< class TInputImage,
00076           class TOutputImage = Image< double, ::itk::GetImageDimension< TInputImage >::ImageDimension > >
00077 class ITK_EXPORT ImagePCAShapeModelEstimator:
00078   public ImageShapeModelEstimatorBase< TInputImage, TOutputImage >
00079 {
00080 public:
00082   typedef ImagePCAShapeModelEstimator                               Self;
00083   typedef ImageShapeModelEstimatorBase< TInputImage, TOutputImage > Superclass;
00084   typedef SmartPointer< Self >                                      Pointer;
00085   typedef SmartPointer< const Self >                                ConstPointer;
00086 
00088   itkNewMacro(Self);
00089 
00091   itkTypeMacro(ImagePCAShapeModelEstimator, ImageShapeModelEstimatorBase);
00092 
00094   typedef TInputImage                        InputImageType;
00095   typedef typename TInputImage::Pointer      InputImagePointer;
00096   typedef typename TInputImage::ConstPointer InputImageConstPointer;
00097 
00099   typedef typename TInputImage::PixelType InputImagePixelType;
00100 
00102   typedef ImageRegionIterator< TInputImage >      InputImageIterator;
00103   typedef ImageRegionConstIterator< TInputImage > InputImageConstIterator;
00104 
00106   itkStaticConstMacro(InputImageDimension, unsigned int,
00107                       TInputImage::ImageDimension);
00108 
00110   typedef TOutputImage                   OutputImageType;
00111   typedef typename TOutputImage::Pointer OutputImagePointer;
00112 
00114   typedef ImageRegionIterator< TOutputImage > OutputImageIterator;
00115 
00117   typedef vnl_matrix< double > MatrixOfDoubleType;
00118 
00120   typedef vnl_matrix< int > MatrixOfIntegerType;
00121 
00123   typedef vnl_vector< double > VectorOfDoubleType;
00124 
00129   virtual void SetNumberOfPrincipalComponentsRequired(unsigned int n);
00130 
00131   itkGetConstMacro(NumberOfPrincipalComponentsRequired, unsigned int);
00132 
00134   virtual void SetNumberOfTrainingImages(unsigned int n);
00135 
00136   itkGetConstMacro(NumberOfTrainingImages, unsigned int);
00137 
00139   itkGetConstMacro(EigenValues, VectorOfDoubleType);
00140 protected:
00141   ImagePCAShapeModelEstimator();
00142   ~ImagePCAShapeModelEstimator();
00143   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00145 
00149   virtual void EnlargeOutputRequestedRegion(DataObject *);
00150 
00155   virtual void GenerateInputRequestedRegion();
00156 
00158   void GenerateData();
00159 
00160 private:
00161 
00162   ImagePCAShapeModelEstimator(const Self &); //purposely not implemented
00163   void operator=(const Self &);              //purposely not implemented
00164 
00166   typedef std::vector< InputImageConstPointer >  InputImagePointerArray;
00167   typedef std::vector< InputImageConstIterator > InputImageIteratorArray;
00168 
00169   typedef typename TInputImage::SizeType ImageSizeType;
00170 
00172   typedef typename TInputImage::PixelType InputPixelType;
00173 
00182   virtual void EstimateShapeModels();
00183 
00184   void EstimatePCAShapeModelParameters();
00185 
00186   void CalculateInnerProduct();
00187 
00189   InputImageIteratorArray m_InputImageIteratorArray;
00190 
00191   VectorOfDoubleType m_Means;
00192 
00193   MatrixOfDoubleType m_InnerProduct;
00194 
00195   MatrixOfDoubleType m_EigenVectors;
00196 
00197   VectorOfDoubleType m_EigenValues;
00198 
00199   VectorOfDoubleType m_EigenVectorNormalizedEnergy;
00200 
00201   ImageSizeType m_InputImageSize;
00202 
00203   unsigned int m_NumberOfPixels;
00204 
00205   // The number of input images for PCA
00206   unsigned int m_NumberOfTrainingImages;
00207 
00208   // The number of output Pricipal Components
00209   unsigned int m_NumberOfPrincipalComponentsRequired;
00210 }; // class ImagePCAShapeModelEstimator
00211 } // namespace itk
00212 
00213 #ifndef ITK_MANUAL_INSTANTIATION
00214 #include "itkImagePCAShapeModelEstimator.hxx"
00215 #endif
00216 
00217 #endif
00218