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     }
00167 
00171   void SetLowerThresholdGradient(const double &lt)
00172   { m_LowerThreshold = lt; }
00173   const double &GetLowerThresholdGradient() const
00174   { return m_LowerThreshold; }
00176 
00180   void SetUpperThresholdMeanDistance(const double &ut1)
00181   { m_UpperThreshold1 = ut1; }
00182   const double &GetUpperThresholdMeanDistance() const
00183   { return m_UpperThreshold1; }
00185 
00189   void SetUpperThresholdDistance(const double &ut2)
00190   { m_UpperThreshold2 = ut2; }
00191   const double &GetUpperThresholdDistance() const
00192   { return m_UpperThreshold2; }
00194 
00196   void SetTolerance(const double &t)
00197   { m_Tolerance = t; }
00198   const double &GetTolerance() const
00199   { return m_Tolerance; }
00201 
00203   void SetPruneIteration(const unsigned int &t)
00204   { m_PruneIteration = t; }
00205   const unsigned int &GetPruneIteration() const
00206   { return m_PruneIteration; }
00208 
00210   const unsigned int &GetNumberOfTrainingImages() const
00211   { return m_NumberOfTrainingImages; }
00212 
00213 
00214 
00220   void GenerateData( );
00221 
00223   VectorOfDoubleType  GetMeanShape();
00224 
00226   VectorOfDoubleType  GetEigenvalues();
00227 
00229   MatrixOfDoubleType  GetEigenvector();
00230 
00231 protected:
00232 
00233   ActiveShapeModelCalculator(): m_NumberOfTrainingImages(0)
00234   {
00235     m_LowerThreshold      = 10.0; // default value
00236     m_UpperThreshold1     = 1.0;  // default value
00237     m_UpperThreshold2     = 1.0;  // default value
00238     m_Tolerance           = 2.0;  // default value
00239     m_PruneIteration      = 3;    // default value
00240     m_NumberOfTrainingImages = 0;
00241     m_EigenVectors.set_size(0,0);
00242     m_EigenValues.set_size(0);
00243     m_Means.set_size(0);
00244     m_Valid = false;
00245     m_Image = NULL;
00246   }
00247 
00248   ~ActiveShapeModelCalculator() {}
00249 
00250   void PrintSelf(std::ostream& os, Indent indent) const
00251   {
00252     Superclass::PrintSelf(os,indent);
00253     os << indent << "LowerThreshold: " << m_LowerThreshold << std::endl;
00254     os << indent << "UpperThreshold1: " << m_UpperThreshold1 << std::endl;
00255     os << indent << "UpperThreshold2: " << m_UpperThreshold2 << std::endl;
00256     os << indent << "Tolerance: " << m_Tolerance << std::endl;
00257     os << indent << "Number of training images: " << m_NumberOfTrainingImages << std::endl;
00258     os << indent << "Number of iteration for Prunig filter: " << m_PruneIteration << std::endl;
00259     itkDebugMacro(<<"                                    ");
00260     itkDebugMacro(<<"Results of the shape model");
00261     itkDebugMacro(<<"====================================");
00262 
00263     itkDebugMacro(<< "The mean shape: ");
00264     
00265     itkDebugMacro(<< m_Means);
00266 
00267     itkDebugMacro(<< " ");
00268     itkDebugMacro(<< "==================   ");
00269 
00270     itkDebugMacro(<< "The eigen values: ");
00271     
00272     itkDebugMacro(<< m_EigenValues);
00273 
00274     itkDebugMacro(<< " ");
00275     itkDebugMacro(<< "==================   ");
00276 
00277     itkDebugMacro(<< "The eigen vectors: ");
00278 
00279 
00280     for(unsigned int i = 0; i < m_Means.size(); i++) 
00281     {
00282     itkDebugMacro(<< m_EigenVectors.get_row(i));
00283     }  
00284 
00285     itkDebugMacro(<< " ");
00286     itkDebugMacro(<< "+++++++++++++++++++++++++");
00287   }// end PrintSelf
00288 
00289 
00290 private:
00291   ActiveShapeModelCalculator(const Self&); //purposely not implemented
00292   void operator=(const Self&); //purposely not implemented
00293 
00294   bool                  m_Valid;                      // Have parameters been computed yet?
00295   float                 m_LowerThreshold;
00296   float                 m_UpperThreshold1;
00297   float                 m_UpperThreshold2;
00298   float                 m_Tolerance;
00299   VectorOfDoubleType    m_Means; 
00300   MatrixOfDoubleType    m_EigenVectors;
00301   VectorOfDoubleType    m_EigenValues;
00302   unsigned int          m_NumberOfTrainingImages;
00303   unsigned int          m_PruneIteration;
00304   Image3DConstPointer   m_Image;
00305 
00306 }; // class ActiveShapeModelCalculator
00307   
00308 } // end of namespace itk
00309 
00310 #ifndef ITK_MANUAL_INSTANTIATION
00311 #include "itkActiveShapeModelCalculator.txx"
00312 #endif
00313 
00314 #endif
00315 

Generated at Wed Nov 5 20:13:59 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000