00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _itkImagePCAShapeModelEstimator_h
00018 #define _itkImagePCAShapeModelEstimator_h
00019
00020 #include <time.h>
00021 #include <math.h>
00022 #include <float.h>
00023
00024 #include "vnl/vnl_vector.h"
00025 #include "vnl/vnl_matrix.h"
00026 #include "vnl/vnl_math.h"
00027 #include "vnl/algo/vnl_matrix_inverse.h"
00028
00029 #include "itkImageRegionIterator.h"
00030 #include "itkImageRegionConstIterator.h"
00031 #include "itkExceptionObject.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 {
00041
00070 template <class TInputImage,
00071 class TOutputImage= Image<double, ::itk::GetImageDimension<TInputImage>::ImageDimension> >
00072 class ITK_EXPORT ImagePCAShapeModelEstimator:
00073 public ImageShapeModelEstimatorBase<TInputImage, TOutputImage>
00074 {
00075 public:
00077 typedef ImagePCAShapeModelEstimator Self;
00078 typedef ImageShapeModelEstimatorBase<TInputImage, TOutputImage> Superclass;
00079 typedef SmartPointer<Self> Pointer;
00080 typedef SmartPointer<const Self> ConstPointer;
00081
00083 itkNewMacro(Self);
00084
00086 itkTypeMacro(ImagePCAShapeModelEstimator, ImageShapeModelEstimatorBase);
00087
00089 typedef TInputImage InputImageType;
00090 typedef typename TInputImage::Pointer InputImagePointer;
00091 typedef typename TInputImage::ConstPointer InputImageConstPointer;
00092
00094 typedef typename TInputImage::PixelType InputImagePixelType;
00095
00097 typedef
00098 ImageRegionIterator<TInputImage> InputImageIterator;
00099
00100 typedef
00101 ImageRegionConstIterator<TInputImage> InputImageConstIterator;
00102
00104 itkStaticConstMacro(InputImageDimension, unsigned int,
00105 TInputImage::ImageDimension);
00106
00108 typedef TOutputImage OutputImageType;
00109 typedef typename TOutputImage::Pointer OutputImagePointer;
00110
00112 typedef
00113 ImageRegionIterator<TOutputImage> OutputImageIterator;
00114
00116 typedef vnl_matrix<double> MatrixOfDoubleType;
00117
00119 typedef vnl_matrix<int> MatrixOfIntegerType;
00120
00122 typedef vnl_vector<double> VectorOfDoubleType;
00123
00128 void SetNumberOfPrincipalComponentsRequired( unsigned int n );
00129 itkGetMacro( NumberOfPrincipalComponentsRequired, unsigned int );
00130
00132 itkSetMacro(NumberOfTrainingImages, unsigned int);
00133 itkGetMacro(NumberOfTrainingImages, unsigned int);
00134
00136 itkGetMacro(EigenValues, VectorOfDoubleType);
00137
00139
00140
00141 protected:
00142 ImagePCAShapeModelEstimator();
00143 ~ImagePCAShapeModelEstimator();
00144 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&);
00163 void operator=(const Self&);
00164
00166 typedef
00167 std::vector<InputImageConstPointer> InputImagePointerArray;
00168 typedef
00169 std::vector< InputImageConstIterator > InputImageIteratorArray;
00170
00171 typedef typename TInputImage::SizeType ImageSizeType;
00172
00174 typedef typename TInputImage::PixelType InputPixelType;
00175
00184 virtual void EstimateShapeModels();
00185
00186 void EstimatePCAShapeModelPrameters();
00187
00188 void CalculateInnerProduct();
00189
00191 InputImageIteratorArray m_InputImageIteratorArray;
00192
00193 VectorOfDoubleType m_Means;
00194
00195 MatrixOfDoubleType m_InnerProduct;
00196
00197 MatrixOfDoubleType m_EigenVectors;
00198
00199 VectorOfDoubleType m_EigenValues;
00200
00201 VectorOfDoubleType m_EigenVectorNormalizedEnergy;
00202
00203 ImageSizeType m_InputImageSize;
00204
00205 unsigned int m_NumberOfPixels;
00206
00207
00208 unsigned int m_NumberOfTrainingImages;
00209
00210
00211 unsigned int m_NumberOfPrincipalComponentsRequired;
00212
00213 };
00214
00215
00216 }
00217
00218 #ifndef ITK_MANUAL_INSTANTIATION
00219 #include "itkImagePCAShapeModelEstimator.txx"
00220 #endif
00221
00222
00223
00224 #endif