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: 2009-02-01 13:08:40 $
00007   Version:   $Revision: 1.2 $
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 
00218   void GenerateData( );
00219 
00221   VectorOfDoubleType  GetMeanShape();
00222 
00224   VectorOfDoubleType  GetEigenvalues();
00225 
00227   MatrixOfDoubleType  GetEigenvector();
00228 
00229 protected:
00230 
00231   ActiveShapeModelCalculator(): m_NumberOfTrainingImages(0)
00232     {
00233     m_LowerThreshold      = 10.0; // default value
00234     m_UpperThreshold1     = 1.0;  // default value
00235     m_UpperThreshold2     = 1.0;  // default value
00236     m_Tolerance           = 2.0;  // default value
00237     m_PruneIteration      = 3;    // default value
00238     m_NumberOfTrainingImages = 0;
00239     m_EigenVectors.set_size(0,0);
00240     m_EigenValues.set_size(0);
00241     m_Means.set_size(0);
00242     m_Valid = false;
00243     m_Image = NULL;
00244     }
00245 
00246   ~ActiveShapeModelCalculator() {}
00247 
00248   void PrintSelf(std::ostream& os, Indent indent) const
00249     {
00250     Superclass::PrintSelf(os,indent);
00251     os << indent << "LowerThreshold: " << m_LowerThreshold << std::endl;
00252     os << indent << "UpperThreshold1: " << m_UpperThreshold1 << std::endl;
00253     os << indent << "UpperThreshold2: " << m_UpperThreshold2 << std::endl;
00254     os << indent << "Tolerance: " << m_Tolerance << std::endl;
00255     os << indent << "Number of training images: " << m_NumberOfTrainingImages << std::endl;
00256     os << indent << "Number of iteration for Prunig filter: " << m_PruneIteration << std::endl;
00257     itkDebugMacro(<<"                                    ");
00258     itkDebugMacro(<<"Results of the shape model");
00259     itkDebugMacro(<<"====================================");
00260 
00261     itkDebugMacro(<< "The mean shape: ");
00262     
00263     itkDebugMacro(<< m_Means);
00264 
00265     itkDebugMacro(<< " ");
00266     itkDebugMacro(<< "==================   ");
00267 
00268     itkDebugMacro(<< "The eigen values: ");
00269     
00270     itkDebugMacro(<< m_EigenValues);
00271 
00272     itkDebugMacro(<< " ");
00273     itkDebugMacro(<< "==================   ");
00274 
00275     itkDebugMacro(<< "The eigen vectors: ");
00276 
00277 
00278     for(unsigned int i = 0; i < m_Means.size(); i++) 
00279       {
00280       itkDebugMacro(<< m_EigenVectors.get_row(i));
00281       }  
00282 
00283     itkDebugMacro(<< " ");
00284     itkDebugMacro(<< "+++++++++++++++++++++++++");
00285     }// end PrintSelf
00286 
00287 
00288 private:
00289   ActiveShapeModelCalculator(const Self&); //purposely not implemented
00290   void operator=(const Self&); //purposely not implemented
00291 
00292   bool                  m_Valid;                      // Have parameters been computed yet?
00293   float                 m_LowerThreshold;
00294   float                 m_UpperThreshold1;
00295   float                 m_UpperThreshold2;
00296   float                 m_Tolerance;
00297   VectorOfDoubleType    m_Means; 
00298   MatrixOfDoubleType    m_EigenVectors;
00299   VectorOfDoubleType    m_EigenValues;
00300   unsigned int          m_NumberOfTrainingImages;
00301   unsigned int          m_PruneIteration;
00302   Image3DConstPointer   m_Image;
00303 
00304 }; // class ActiveShapeModelCalculator
00305   
00306 } // end of namespace itk
00307 
00308 #ifndef ITK_MANUAL_INSTANTIATION
00309 #include "itkActiveShapeModelCalculator.txx"
00310 #endif
00311 
00312 #endif
00313 

Generated at Mon Jul 12 2010 17:41:36 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000