Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkActiveShapeModelCalculator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkActiveShapeModelCalculator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2004/10/09 01:46:37 $
00007   Version:   $Revision: 1.1 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef _itkActiveShapeModelCalculator_h
00018 #define _itkActiveShapeModelCalculator_h
00019 
00020 #include <time.h>
00021 #include <math.h>
00022 
00023 #include "vnl/vnl_vector.h"
00024 #include "vnl/vnl_matrix.h"
00025 #include "vnl/vnl_math.h"
00026 #include "vnl/algo/vnl_matrix_inverse.h"
00027 #include <vnl/algo/vnl_generalized_eigensystem.h>
00028 #include <vnl/algo/vnl_symmetric_eigensystem.h>
00029 
00030 #include "itkImageSliceConstIteratorWithIndex.h"
00031 #include "itkImageRegionConstIterator.h"
00032 #include "itkImageLinearIteratorWithIndex.h"
00033 #include "itkRescaleIntensityImageFilter.h"
00034 #include "itkGradientMagnitudeImageFilter.h"
00035 #include "itkBinaryThresholdImageFilter.h"
00036 #include "itkDanielssonDistanceMapImageFilter.h"
00037 #include "itkBinaryThinningImageFilter.h"
00038 #include "itkBinaryPruningImageFilter.h"
00039 #include "itkPointSet.h"
00040 #include "itkVector.h"
00041 #include "itkListSample.h"
00042 #include "itkExceptionObject.h"
00043 
00044 #include "itkConceptChecking.h"
00045 
00046 #include <vector>
00047 #include <list>
00048 
00049 namespace itk{
00050 
00076 template < class TImage >
00077 class ITK_EXPORT ActiveShapeModelCalculator : public Object
00078 {
00079 public:
00081   typedef ActiveShapeModelCalculator<TImage>                              Self;
00082   typedef Object                                                          Superclass;
00083   typedef SmartPointer<Self>                                              Pointer;
00084   typedef SmartPointer<const Self>                                        ConstPointer;
00085 
00087   itkNewMacro(Self);
00088 
00090   itkTypeMacro(ActiveShapeModelCalculator, Object);
00091 
00097   typedef float                                                           PixelType;
00098   typedef unsigned char                                                   Pixel8bitsType;
00099 
00101   typedef Vector< double, 2 >                                             Vector2DType;
00102   typedef Vector< double, 3 >                                             Vector3DType;
00103   typedef Vector< unsigned int, 2 >                                       MeasurementVectorType ;
00104   typedef std::vector< unsigned int>                                      VectorType;
00105   typedef vnl_vector<double>                                              VectorOfDoubleType;
00106 
00107   
00110   typedef vnl_matrix<double>                                              MatrixOfDoubleType;
00111   typedef vnl_matrix<int>                                                 MatrixOfIntegerType;
00112 
00114   typedef TImage                                                          Image3DType;
00115   typedef Image< PixelType, 2 >                                           Image2DType;
00116   typedef Image< Pixel8bitsType, 2 >                                      Image2D8bitsType;
00117   typedef Image< Pixel8bitsType, 3 >                                      Image3D8bitsType;
00118 
00120   typedef typename Image2D8bitsType::IndexType                            IndexType;
00121   typedef typename Image3DType::IndexType                                 Index3DType;
00122 
00124   typedef typename Image2DType::Pointer                                   Image2DPointer;
00125   typedef typename Image3DType::ConstPointer                              Image3DConstPointer;
00126 
00128   typedef PointSet< unsigned short, 2 >                                   PointSetType;
00129   typedef typename PointSetType::PointType                                PointType;
00130 
00132   typedef typename PointSetType::PointsContainer                          PointsContainer;
00133   typedef typename PointSetType::PointDataContainer                       PointDataContainer;
00134 
00136   typedef std::list<IndexType>                                            List2DType;
00137   typedef Statistics::ListSample< MeasurementVectorType >                 SampleType;
00138 
00140   typedef ImageLinearIteratorWithIndex< Image2DType >                     LinearIteratorType;
00141   typedef ImageSliceConstIteratorWithIndex< Image3DType >                 SliceIteratorType;
00142   typedef ImageRegionConstIterator< Image3D8bitsType  >                   ConstIteratorType;
00143   typedef ImageRegionIterator< Image2D8bitsType >                         IteratorType;
00144   typedef NeighborhoodIterator< Image2D8bitsType >                        NeighborIteratorType;
00145   typedef typename PointsContainer::Iterator                              PointsIterator;
00146 
00148   typedef GradientMagnitudeImageFilter< Image3DType, Image3DType >        GradientFilterType;
00149   typedef BinaryThresholdImageFilter<Image3DType, Image3DType >           BinaryFilterType;
00150   typedef BinaryThresholdImageFilter<Image2DType, Image2D8bitsType >      BinaryFilterType1;
00151   typedef BinaryThresholdImageFilter<Image3DType, Image3D8bitsType >      BinaryFilterType2;
00152   typedef DanielssonDistanceMapImageFilter< Image3DType, Image3DType >    DistanceMapFilterType;
00153   typedef BinaryThinningImageFilter< Image2D8bitsType, Image2D8bitsType > ThinFilterType;
00154   typedef BinaryPruningImageFilter< Image2D8bitsType, Image2D8bitsType >  PruneFilterType;
00155 
00157   virtual void SetImage( const Image3DType * image )
00158     {
00159     if ( m_Image != image )
00160       {
00161       m_Image = image;
00162       this->Modified();
00163       m_Valid = false;
00164       }
00165     }
00166 
00170   void SetLowerThresholdGradient(const double &lt)
00171   { m_LowerThreshold = lt; }
00172   const double &GetLowerThresholdGradient() const
00173   { return m_LowerThreshold; }
00174 
00178   void SetUpperThresholdMeanDistance(const double &ut1)
00179   { m_UpperThreshold1 = ut1; }
00180   const double &GetUpperThresholdMeanDistance() const
00181   { return m_UpperThreshold1; }
00182 
00186   void SetUpperThresholdDistance(const double &ut2)
00187   { m_UpperThreshold2 = ut2; }
00188   const double &GetUpperThresholdDistance() const
00189   { return m_UpperThreshold2; }
00190 
00192   void SetTolerance(const double &t)
00193   { m_Tolerance = t; }
00194   const double &GetTolerance() const
00195   { return m_Tolerance; }
00196 
00198   void SetPruneIteration(const unsigned int &t)
00199   { m_PruneIteration = t; }
00200   const unsigned int &GetPruneIteration() const
00201   { return m_PruneIteration; }
00202 
00204   const unsigned int &GetNumberOfTrainingImages() const
00205   { return m_NumberOfTrainingImages; }
00206 
00207 
00208 
00214   void GenerateData( );
00215 
00217   VectorOfDoubleType  GetMeanShape();
00218 
00220   VectorOfDoubleType  GetEigenvalues();
00221 
00223   MatrixOfDoubleType  GetEigenvector();
00224 
00225 protected:
00226 
00227   ActiveShapeModelCalculator(): m_NumberOfTrainingImages(0)
00228   {
00229     m_LowerThreshold      = 10.0; // default value
00230     m_UpperThreshold1     = 1.0;  // default value
00231     m_UpperThreshold2     = 1.0;  // default value
00232     m_Tolerance           = 2.0;  // default value
00233     m_PruneIteration      = 3;    // default value
00234     m_NumberOfTrainingImages = 0;
00235     m_EigenVectors.set_size(0,0);
00236     m_EigenValues.set_size(0);
00237     m_Means.set_size(0);
00238     m_Valid = false;
00239     m_Image = NULL;
00240   }
00241 
00242   ~ActiveShapeModelCalculator() {}
00243 
00244   void PrintSelf(std::ostream& os, Indent indent) const
00245   {
00246     Superclass::PrintSelf(os,indent);
00247     os << indent << "LowerThreshold: " << m_LowerThreshold << std::endl;
00248     os << indent << "UpperThreshold1: " << m_UpperThreshold1 << std::endl;
00249     os << indent << "UpperThreshold2: " << m_UpperThreshold2 << std::endl;
00250     os << indent << "Tolerance: " << m_Tolerance << std::endl;
00251     os << indent << "Number of training images: " << m_NumberOfTrainingImages << std::endl;
00252     os << indent << "Number of iteration for Prunig filter: " << m_PruneIteration << std::endl;
00253     itkDebugMacro(<<"                                    ");
00254     itkDebugMacro(<<"Results of the shape model");
00255     itkDebugMacro(<<"====================================");
00256 
00257     itkDebugMacro(<< "The mean shape: ");
00258     
00259     itkDebugMacro(<< m_Means);
00260 
00261     itkDebugMacro(<< " ");
00262     itkDebugMacro(<< "==================   ");
00263 
00264     itkDebugMacro(<< "The eigen values: ");
00265     
00266     itkDebugMacro(<< m_EigenValues);
00267 
00268     itkDebugMacro(<< " ");
00269     itkDebugMacro(<< "==================   ");
00270 
00271     itkDebugMacro(<< "The eigen vectors: ");
00272 
00273 
00274     for(unsigned int i = 0; i < m_Means.size(); i++) 
00275     {
00276     itkDebugMacro(<< m_EigenVectors.get_row(i));
00277     }  
00278 
00279     itkDebugMacro(<< " ");
00280     itkDebugMacro(<< "+++++++++++++++++++++++++");
00281   }// end PrintSelf
00282 
00283 
00284 private:
00285   ActiveShapeModelCalculator(const Self&); //purposely not implemented
00286   void operator=(const Self&); //purposely not implemented
00287 
00288   bool                  m_Valid;                      // Have parameters been computed yet?
00289   float                 m_LowerThreshold;
00290   float                 m_UpperThreshold1;
00291   float                 m_UpperThreshold2;
00292   float                 m_Tolerance;
00293   VectorOfDoubleType    m_Means; 
00294   MatrixOfDoubleType    m_EigenVectors;
00295   VectorOfDoubleType    m_EigenValues;
00296   unsigned int          m_NumberOfTrainingImages;
00297   unsigned int          m_PruneIteration;
00298   Image3DConstPointer   m_Image;
00299 
00300 }; // class ActiveShapeModelCalculator
00301   
00302 } // end of namespace itk
00303 
00304 #ifndef ITK_MANUAL_INSTANTIATION
00305 #include "itkActiveShapeModelCalculator.txx"
00306 #endif
00307 
00308 #endif

Generated at Wed May 24 22:45:03 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000