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

itkMRFImageFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkMRFImageFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-04-23 03:53:35 $
00007   Version:   $Revision: 1.44 $
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 __itkMRFImageFilter_h
00018 #define __itkMRFImageFilter_h
00019 
00020 
00021 #include "vnl/vnl_vector.h"
00022 #include "vnl/vnl_matrix.h"
00023 
00024 #include "itkImageClassifierBase.h"
00025 
00026 #include "itkImageToImageFilter.h"
00027 #include "itkImageRegionIterator.h"
00028 
00029 #include "itkConstNeighborhoodIterator.h"
00030 #include "itkNeighborhoodIterator.h"
00031 #include "itkNeighborhoodAlgorithm.h"
00032 #include "itkNeighborhood.h"
00033 #include "itkSize.h"
00034 
00035 namespace itk
00036 {
00037 
00128 template <class TInputImage, class TClassifiedImage>
00129 class ITK_EXPORT MRFImageFilter : 
00130     public ImageToImageFilter<TInputImage,TClassifiedImage>
00131 {
00132 public:
00134   typedef MRFImageFilter                                   Self;
00135   typedef ImageToImageFilter<TInputImage,TClassifiedImage> Superclass;
00136   typedef SmartPointer<Self>                               Pointer;
00137   typedef SmartPointer<const Self>                         ConstPointer;
00138   typedef typename Superclass::OutputImagePointer          OutputImagePointer;
00139 
00141   itkNewMacro(Self);
00142 
00144   itkTypeMacro(MRFImageFilter,Object);
00145 
00147   typedef TInputImage                        InputImageType;
00148   typedef typename TInputImage::Pointer      InputImagePointer;
00149   typedef typename TInputImage::ConstPointer InputImageConstPointer;  
00150 
00152   typedef typename TInputImage::PixelType            InputImagePixelType;
00153 
00155   typedef typename TInputImage::RegionType           InputImageRegionType;
00156 
00158   typedef ImageRegionIterator<TInputImage>           InputImageRegionIterator;
00159   typedef ImageRegionConstIterator<TInputImage>      InputImageRegionConstIterator;
00160 
00162   itkStaticConstMacro(InputImageDimension, unsigned int,
00163                       TInputImage::ImageDimension);
00164 
00166   typedef typename TClassifiedImage::Pointer         TrainingImagePointer;
00167 
00169   typedef typename TClassifiedImage::PixelType       TrainingImagePixelType;
00170 
00173   typedef typename TClassifiedImage::Pointer         LabelledImagePointer;
00174 
00177   typedef typename TClassifiedImage::PixelType       LabelledImagePixelType;
00178 
00181   typedef typename TClassifiedImage::RegionType      LabelledImageRegionType;
00182 
00184   typedef typename TClassifiedImage::IndexType       LabelledImageIndexType;
00185   typedef typename LabelledImageIndexType::IndexValueType    IndexValueType;
00186 
00188   typedef typename TClassifiedImage::OffsetType      LabelledImageOffsetType;
00189 
00191   typedef ImageRegionIterator<TClassifiedImage>  
00192   LabelledImageRegionIterator;
00193 
00195   itkStaticConstMacro(ClassifiedImageDimension, unsigned int,
00196                       TClassifiedImage::ImageDimension);
00197 
00199   typedef ImageClassifierBase<TInputImage,TClassifiedImage> ClassifierType;
00200 
00202   typedef typename TInputImage::SizeType SizeType;
00203 
00205   typedef typename TInputImage::SizeType NeighborhoodRadiusType;
00206 
00208   typedef ConstNeighborhoodIterator< TInputImage >
00209   InputImageNeighborhoodIterator;
00210 
00211   typedef typename InputImageNeighborhoodIterator::RadiusType 
00212   InputImageNeighborhoodRadiusType;
00213 
00214   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TInputImage >
00215   InputImageFacesCalculator;
00216   
00217   typedef typename InputImageFacesCalculator::FaceListType
00218   InputImageFaceListType;
00219 
00220   typedef typename InputImageFaceListType::iterator 
00221   InputImageFaceListIterator;
00222 
00224   typedef NeighborhoodIterator< TClassifiedImage >
00225   LabelledImageNeighborhoodIterator;
00226 
00227   typedef typename LabelledImageNeighborhoodIterator::RadiusType 
00228   LabelledImageNeighborhoodRadiusType;
00229 
00230   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TClassifiedImage >
00231   LabelledImageFacesCalculator;
00232   
00233   typedef typename LabelledImageFacesCalculator::FaceListType
00234   LabelledImageFaceListType;
00235 
00236   typedef typename LabelledImageFaceListType::iterator 
00237   LabelledImageFaceListIterator;
00238 
00240   void SetClassifier( typename ClassifierType::Pointer ptrToClassifier );
00241 
00243   itkSetMacro(NumberOfClasses, unsigned int);
00244   itkGetConstMacro(NumberOfClasses, unsigned int);
00246 
00249   itkSetMacro(MaximumNumberOfIterations, unsigned int);
00250   itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
00252 
00255   itkSetMacro(ErrorTolerance, double);
00256   itkGetConstMacro(ErrorTolerance, double);
00258 
00261   itkSetMacro(SmoothingFactor, double);
00262   itkGetConstMacro(SmoothingFactor, double);
00264 
00266   void SetNeighborhoodRadius(const NeighborhoodRadiusType &);  
00267 
00271   void SetNeighborhoodRadius( const unsigned long );
00272   void SetNeighborhoodRadius( const unsigned long *radiusArray );  
00273 
00275   const NeighborhoodRadiusType GetNeighborhoodRadius() const
00276     {
00277     NeighborhoodRadiusType radius;
00278 
00279     for(int i=0; i<InputImageDimension; ++i)
00280       {
00281       radius[i] = m_InputImageNeighborhoodRadius[i];
00282       }
00283     return radius;
00284     }
00285     
00291   virtual void SetMRFNeighborhoodWeight( std::vector<double> BetaMatrix );
00292   virtual std::vector<double> GetMRFNeighborhoodWeight()
00293     {
00294     return m_MRFNeighborhoodWeight;
00295     }
00297 
00298 //Enum to get the stopping condition of the MRF filter
00299   typedef enum{
00300     MaximumNumberOfIterations=1,
00301     ErrorTolerance
00302   } StopConditionType;
00303   
00306   itkGetConstReferenceMacro( StopCondition, StopConditionType );
00307 
00308   /* Get macro for number of iterations */
00309   itkGetConstReferenceMacro( NumberOfIterations, unsigned int );
00310 
00311 #ifdef ITK_USE_CONCEPT_CHECKING
00312 
00313   itkConceptMacro(UnsignedIntConvertibleToClassifiedCheck,
00314     (Concept::Convertible<unsigned int, LabelledImagePixelType>));
00315   itkConceptMacro(ClassifiedConvertibleToUnsignedIntCheck,
00316     (Concept::Convertible<LabelledImagePixelType, unsigned int> ));
00317   itkConceptMacro(ClassifiedConvertibleToIntCheck,
00318     (Concept::Convertible<LabelledImagePixelType, int> ));
00319   itkConceptMacro(IntConvertibleToClassifiedCheck,
00320     (Concept::Convertible<int, LabelledImagePixelType>));
00321   itkConceptMacro(SameDimensionCheck,
00322     (Concept::SameDimension<InputImageDimension, ClassifiedImageDimension>));
00323 
00325 #endif
00326 
00327 protected:
00328   MRFImageFilter();
00329   ~MRFImageFilter();
00330   void PrintSelf(std::ostream& os, Indent indent) const;
00331 
00333   void Allocate();
00334 
00339   virtual void ApplyMRFImageFilter();  
00340 
00342   virtual void MinimizeFunctional();
00343 
00344   typedef Image<int,itkGetStaticConstMacro(InputImageDimension) > LabelStatusImageType;
00345   typedef typename LabelStatusImageType::IndexType    LabelStatusIndexType;
00346   typedef typename LabelStatusImageType::RegionType   LabelStatusRegionType;
00347   typedef typename LabelStatusImageType::Pointer      LabelStatusImagePointer;
00348   typedef ImageRegionIterator< LabelStatusImageType > LabelStatusImageIterator;
00349 
00351   typedef NeighborhoodIterator< LabelStatusImageType >
00352   LabelStatusImageNeighborhoodIterator;
00353   //Function implementing the neighborhood operation
00354 
00355   virtual void DoNeighborhoodOperation( const InputImageNeighborhoodIterator &imageIter,
00356                                         LabelledImageNeighborhoodIterator &labelledIter,
00357                                         LabelStatusImageNeighborhoodIterator &labelStatusIter );
00358 
00359   virtual void GenerateData();
00360   virtual void GenerateInputRequestedRegion();
00361   virtual void EnlargeOutputRequestedRegion( DataObject * );
00362   virtual void GenerateOutputInformation();
00363   
00364 private:
00365   MRFImageFilter(const Self&); //purposely not implemented
00366   void operator=(const Self&); //purposely not implemented
00367   
00368   typedef typename TInputImage::SizeType InputImageSizeType;
00369 
00370   typedef typename LabelStatusImageNeighborhoodIterator::RadiusType 
00371   LabelStatusImageNeighborhoodRadiusType;
00372 
00373   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< LabelStatusImageType >
00374   LabelStatusImageFacesCalculator;
00375   
00376   typedef typename LabelStatusImageFacesCalculator::FaceListType
00377   LabelStatusImageFaceListType;
00378 
00379   typedef typename LabelStatusImageFaceListType::iterator 
00380   LabelStatusImageFaceListIterator;
00381 
00382   InputImageNeighborhoodRadiusType       m_InputImageNeighborhoodRadius;
00383   LabelledImageNeighborhoodRadiusType    m_LabelledImageNeighborhoodRadius;
00384   LabelStatusImageNeighborhoodRadiusType m_LabelStatusImageNeighborhoodRadius;
00385  
00386   unsigned int              m_NumberOfClasses;
00387   unsigned int              m_MaximumNumberOfIterations;
00388   unsigned int              m_KernelSize;
00389 
00390   int                       m_ErrorCounter;
00391   int                       m_NeighborhoodSize;
00392   int                       m_TotalNumberOfValidPixelsInOutputImage;
00393   int                       m_TotalNumberOfPixelsInInputImage;
00394   double                    m_ErrorTolerance;  
00395   double                    m_SmoothingFactor;
00396   double                   *m_ClassProbability; //Class liklihood
00397   unsigned int              m_NumberOfIterations;
00398   StopConditionType         m_StopCondition;
00399 
00400   LabelStatusImagePointer   m_LabelStatusImage;
00401 
00402   std::vector<double>       m_MRFNeighborhoodWeight;
00403   std::vector<double>       m_NeighborInfluence;
00404   std::vector<double>       m_MahalanobisDistance;
00405   std::vector<double>       m_DummyVector;
00406 
00408   typename ClassifierType::Pointer m_ClassifierPtr;
00409 
00410 
00414   virtual void SetDefaultMRFNeighborhoodWeight(  );
00415 
00416   //Function implementing the ICM algorithm to label the images
00417   void ApplyICMLabeller();
00418 
00419 }; // class MRFImageFilter
00420 
00421 
00422 } // namespace itk
00423 
00424 #ifndef ITK_MANUAL_INSTANTIATION
00425 #include "itkMRFImageFilter.txx"
00426 #endif
00427 
00428 #endif
00429 

Generated at Fri Apr 16 19:04:21 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000