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: 2006-04-05 13:59:34 $
00007   Version:   $Revision: 1.42 $
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 
00036 
00037 namespace itk
00038 {
00039 
00130 template <class TInputImage, class TClassifiedImage>
00131 class ITK_EXPORT MRFImageFilter : 
00132     public ImageToImageFilter<TInputImage,TClassifiedImage>
00133 {
00134 public:       
00136   typedef MRFImageFilter   Self;
00137   typedef ImageToImageFilter<TInputImage,TClassifiedImage> Superclass;
00138   typedef SmartPointer<Self>  Pointer;
00139   typedef SmartPointer<const Self>  ConstPointer;
00140   typedef typename Superclass::OutputImagePointer OutputImagePointer;
00141 
00143   itkNewMacro(Self);
00144 
00146   itkTypeMacro(MRFImageFilter,Object);
00147 
00149   typedef TInputImage InputImageType;
00150   typedef typename TInputImage::Pointer              InputImagePointer;
00151   typedef typename TInputImage::ConstPointer         InputImageConstPointer;  
00152 
00154   typedef typename TInputImage::PixelType            InputImagePixelType;
00155 
00157   typedef typename TInputImage::RegionType           InputImageRegionType;
00158 
00160   typedef ImageRegionIterator<TInputImage>           InputImageRegionIterator;
00161   typedef ImageRegionConstIterator<TInputImage>      InputImageRegionConstIterator;
00162 
00164   itkStaticConstMacro(InputImageDimension, unsigned int,
00165                       TInputImage::ImageDimension);
00166 
00168   typedef typename TClassifiedImage::Pointer         TrainingImagePointer;
00169 
00171   typedef typename TClassifiedImage::PixelType       TrainingImagePixelType;
00172 
00175   typedef typename TClassifiedImage::Pointer         LabelledImagePointer;
00176 
00179   typedef typename TClassifiedImage::PixelType       LabelledImagePixelType;
00180 
00183   typedef typename TClassifiedImage::RegionType      LabelledImageRegionType;
00184 
00186   typedef typename TClassifiedImage::IndexType       LabelledImageIndexType;
00187   typedef typename LabelledImageIndexType::IndexValueType    IndexValueType;
00188 
00190   typedef typename TClassifiedImage::OffsetType      LabelledImageOffsetType;
00191 
00193   typedef ImageRegionIterator<TClassifiedImage>  
00194   LabelledImageRegionIterator;
00195 
00197   itkStaticConstMacro(ClassifiedImageDimension, unsigned int,
00198                       TClassifiedImage::ImageDimension);
00199 
00201   typedef ImageClassifierBase<TInputImage,TClassifiedImage> ClassifierType;
00202 
00204   typedef typename TInputImage::SizeType SizeType;
00205 
00207   typedef typename TInputImage::SizeType NeighborhoodRadiusType;
00208 
00210   typedef ConstNeighborhoodIterator< TInputImage >
00211   InputImageNeighborhoodIterator;
00212 
00213   typedef typename InputImageNeighborhoodIterator::RadiusType 
00214   InputImageNeighborhoodRadiusType;
00215 
00216   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TInputImage >
00217   InputImageFacesCalculator;
00218   
00219   typedef typename InputImageFacesCalculator::FaceListType
00220   InputImageFaceListType;
00221 
00222   typedef typename InputImageFaceListType::iterator 
00223   InputImageFaceListIterator;
00224 
00226   typedef NeighborhoodIterator< TClassifiedImage >
00227   LabelledImageNeighborhoodIterator;
00228 
00229   typedef typename LabelledImageNeighborhoodIterator::RadiusType 
00230   LabelledImageNeighborhoodRadiusType;
00231 
00232   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TClassifiedImage >
00233   LabelledImageFacesCalculator;
00234   
00235   typedef typename LabelledImageFacesCalculator::FaceListType
00236   LabelledImageFaceListType;
00237 
00238   typedef typename LabelledImageFaceListType::iterator 
00239   LabelledImageFaceListIterator;
00240 
00242   void SetClassifier( typename ClassifierType::Pointer ptrToClassifier );
00243 
00245   itkSetMacro(NumberOfClasses, unsigned int);
00246   itkGetMacro(NumberOfClasses, unsigned int);
00248 
00251   itkSetMacro(MaximumNumberOfIterations, unsigned int);
00252   itkGetMacro(MaximumNumberOfIterations, unsigned int);
00254 
00257   itkSetMacro(ErrorTolerance, double);
00258   itkGetMacro(ErrorTolerance, double);
00260 
00263   itkSetMacro(SmoothingFactor, double);
00264   itkGetMacro(SmoothingFactor, double);
00266 
00268   void SetNeighborhoodRadius(const NeighborhoodRadiusType &);  
00269 
00273   void SetNeighborhoodRadius( const unsigned long );
00274   void SetNeighborhoodRadius( const unsigned long *radiusArray );  
00275 
00277   const NeighborhoodRadiusType GetNeighborhoodRadius() const
00278   { 
00279     NeighborhoodRadiusType radius;
00280 
00281     for(int i=0; i<InputImageDimension; ++i)
00282       radius[i] = m_InputImageNeighborhoodRadius[i];
00283 
00284     return radius;
00285   }
00286     
00292   virtual void SetMRFNeighborhoodWeight( std::vector<double> BetaMatrix );
00293   virtual std::vector<double> GetMRFNeighborhoodWeight()
00294   {
00295     return m_MRFNeighborhoodWeight;
00296   }
00298 
00299 //Enum to get the stopping condition of the MRF filter
00300   typedef enum{
00301     MaximumNumberOfIterations=1,
00302     ErrorTolerance
00303   } StopConditionType;
00304   
00307   itkGetConstReferenceMacro( StopCondition, StopConditionType );
00308 
00309   /* Get macro for number of iterations */
00310   itkGetConstReferenceMacro( NumberOfIterations, unsigned int );
00311 
00312 #ifdef ITK_USE_CONCEPT_CHECKING
00313 
00314   itkConceptMacro(UnsignedIntConvertibleToClassifiedCheck,
00315     (Concept::Convertible<unsigned int, LabelledImagePixelType>));
00316   itkConceptMacro(ClassifiedConvertibleToUnsignedIntCheck,
00317     (Concept::Convertible<LabelledImagePixelType, unsigned int> ));
00318   itkConceptMacro(ClassifiedConvertibleToIntCheck,
00319     (Concept::Convertible<LabelledImagePixelType, int> ));
00320   itkConceptMacro(IntConvertibleToClassifiedCheck,
00321     (Concept::Convertible<int, LabelledImagePixelType>));
00322   itkConceptMacro(SameDimensionCheck,
00323     (Concept::SameDimension<InputImageDimension, ClassifiedImageDimension>));
00324 
00326 #endif
00327 
00328 protected:
00329   MRFImageFilter();
00330   ~MRFImageFilter();
00331   void PrintSelf(std::ostream& os, Indent indent) const;
00332 
00334   void Allocate();
00335 
00340   virtual void ApplyMRFImageFilter();  
00341 
00343   virtual void MinimizeFunctional();
00344 
00345   typedef Image<int,itkGetStaticConstMacro(InputImageDimension) > LabelStatusImageType;
00346   typedef typename LabelStatusImageType::IndexType LabelStatusIndexType;
00347   typedef typename LabelStatusImageType::RegionType LabelStatusRegionType;
00348   typedef typename LabelStatusImageType::Pointer LabelStatusImagePointer;
00349   typedef ImageRegionIterator< LabelStatusImageType > 
00350   LabelStatusImageIterator;
00351 
00353   typedef NeighborhoodIterator< LabelStatusImageType >
00354   LabelStatusImageNeighborhoodIterator;
00355   //Function implementing the neighborhood operation
00356 
00357   virtual void DoNeighborhoodOperation( const InputImageNeighborhoodIterator &imageIter,
00358                                         LabelledImageNeighborhoodIterator &labelledIter,
00359                                         LabelStatusImageNeighborhoodIterator &labelStatusIter );
00360 
00361   virtual void GenerateData();
00362   virtual void GenerateInputRequestedRegion();
00363   virtual void EnlargeOutputRequestedRegion( DataObject * );
00364   virtual void GenerateOutputInformation();
00365   
00366 private:            
00367   MRFImageFilter(const Self&); //purposely not implemented
00368   void operator=(const Self&); //purposely not implemented
00369   
00370   typedef typename TInputImage::SizeType InputImageSizeType;
00371 
00372   typedef typename LabelStatusImageNeighborhoodIterator::RadiusType 
00373   LabelStatusImageNeighborhoodRadiusType;
00374 
00375   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< LabelStatusImageType >
00376   LabelStatusImageFacesCalculator;
00377   
00378   typedef typename LabelStatusImageFacesCalculator::FaceListType
00379   LabelStatusImageFaceListType;
00380 
00381   typedef typename LabelStatusImageFaceListType::iterator 
00382   LabelStatusImageFaceListIterator;
00383 
00384   InputImageNeighborhoodRadiusType       m_InputImageNeighborhoodRadius;
00385   LabelledImageNeighborhoodRadiusType    m_LabelledImageNeighborhoodRadius;
00386   LabelStatusImageNeighborhoodRadiusType m_LabelStatusImageNeighborhoodRadius;
00387  
00388   unsigned int              m_NumberOfClasses;
00389   unsigned int              m_MaximumNumberOfIterations;
00390   unsigned int              m_KernelSize;
00391 
00392   int                       m_ErrorCounter;
00393   int                       m_NeighborhoodSize;
00394   int                       m_TotalNumberOfValidPixelsInOutputImage;
00395   int                       m_TotalNumberOfPixelsInInputImage;
00396   double                    m_ErrorTolerance;  
00397   double                    m_SmoothingFactor;
00398   double                    *m_ClassProbability; //Class liklihood
00399   unsigned int              m_NumberOfIterations;
00400   StopConditionType         m_StopCondition;
00401 
00402   LabelStatusImagePointer   m_LabelStatusImage;
00403 
00404   std::vector<double>       m_MRFNeighborhoodWeight;
00405   std::vector<double>       m_NeighborInfluence;
00406   std::vector<double>       m_MahalanobisDistance;
00407   std::vector<double>       m_DummyVector;
00408 
00410   typename ClassifierType::Pointer m_ClassifierPtr;
00411 
00412 
00416   virtual void SetDefaultMRFNeighborhoodWeight(  );
00417 
00418   //Function implementing the ICM algorithm to label the images
00419   void ApplyICMLabeller();
00420 
00421 }; // class MRFImageFilter
00422 
00423 
00424 } // namespace itk
00425 
00426 #ifndef ITK_MANUAL_INSTANTIATION
00427 #include "itkMRFImageFilter.txx"
00428 #endif
00429 
00430 #endif
00431 
00432 

Generated at Mon Apr 14 13:36:59 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000