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: 2002/10/01 01:36:05 $
00007   Version:   $Revision: 1.34 $
00008 
00009   Copyright (c) 2002 Insight 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 
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   itkGetMacro(NumberOfClasses, unsigned int);
00245 
00248   itkSetMacro(MaximumNumberOfIterations, unsigned int);
00249   itkGetMacro(MaximumNumberOfIterations, unsigned int);
00250 
00253   itkSetMacro(ErrorTolerance, double);
00254   itkGetMacro(ErrorTolerance, double);
00255 
00258   itkSetMacro(SmoothingFactor, double);
00259   itkGetMacro(SmoothingFactor, double);
00260 
00262   void SetNeighborhoodRadius(const NeighborhoodRadiusType &);  
00263 
00267   void SetNeighborhoodRadius( const unsigned long );
00268   void SetNeighborhoodRadius( const unsigned long *radiusArray );  
00269 
00271   const NeighborhoodRadiusType GetNeighborhoodRadius() const
00272     { 
00273       NeighborhoodRadiusType radius;
00274       
00275       for(int i=0; i<InputImageDimension; ++i)
00276         radius[i] = m_InputImageNeighborhoodRadius[i];
00277 
00278       return radius;
00279     }
00280     
00286   virtual void SetMRFNeighborhoodWeight( std::vector<double> BetaMatrix );
00287   virtual std::vector<double> GetMRFNeighborhoodWeight()
00288     {
00289     return m_MRFNeighborhoodWeight;
00290     }
00291     
00292 protected:
00293   MRFImageFilter();
00294   ~MRFImageFilter();
00295   void PrintSelf(std::ostream& os, Indent indent) const;
00296 
00298   void Allocate();
00299 
00304   virtual void ApplyMRFImageFilter();  
00305 
00307   virtual void MinimizeFunctional();
00308 
00309   typedef Image<int,itkGetStaticConstMacro(InputImageDimension) > LabelStatusImageType;
00310   typedef typename LabelStatusImageType::IndexType LabelStatusIndexType;
00311   typedef typename LabelStatusImageType::RegionType LabelStatusRegionType;
00312   typedef typename LabelStatusImageType::Pointer LabelStatusImagePointer;
00313   typedef ImageRegionIterator< LabelStatusImageType > 
00314     LabelStatusImageIterator;
00315 
00317   typedef NeighborhoodIterator< LabelStatusImageType >
00318     LabelStatusImageNeighborhoodIterator;
00319   //Function implementing the neighborhood operation
00320 
00321   virtual void DoNeighborhoodOperation( const InputImageNeighborhoodIterator &imageIter,
00322     LabelledImageNeighborhoodIterator &labelledIter,
00323     LabelStatusImageNeighborhoodIterator &labelStatusIter );
00324 
00325   virtual void GenerateData();
00326   virtual void GenerateInputRequestedRegion();
00327   virtual void EnlargeOutputRequestedRegion( DataObject * );
00328   virtual void GenerateOutputInformation();
00329 
00330 private:            
00331   MRFImageFilter(const Self&); //purposely not implemented
00332   void operator=(const Self&); //purposely not implemented
00333   
00334   typedef typename TInputImage::SizeType InputImageSizeType;
00335 
00336   typedef typename LabelStatusImageNeighborhoodIterator::RadiusType 
00337     LabelStatusImageNeighborhoodRadiusType;
00338 
00339   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< LabelStatusImageType >
00340       LabelStatusImageFacesCalculator;
00341   
00342   typedef typename LabelStatusImageFacesCalculator::FaceListType
00343     LabelStatusImageFaceListType;
00344 
00345   typedef typename LabelStatusImageFaceListType::iterator 
00346     LabelStatusImageFaceListIterator;
00347 
00348   InputImageNeighborhoodRadiusType       m_InputImageNeighborhoodRadius;
00349   LabelledImageNeighborhoodRadiusType    m_LabelledImageNeighborhoodRadius;
00350   LabelStatusImageNeighborhoodRadiusType m_LabelStatusImageNeighborhoodRadius;
00351  
00352   unsigned int              m_NumberOfClasses;
00353   unsigned int              m_MaximumNumberOfIterations;
00354   unsigned int              m_KernelSize;
00355 
00356   int                       m_ErrorCounter;
00357   int                       m_NeighborhoodSize;
00358   int                       m_TotalNumberOfValidPixelsInOutputImage;
00359   int                       m_TotalNumberOfPixelsInInputImage;
00360   double                    m_ErrorTolerance;  
00361   double                    m_SmoothingFactor;
00362   double                    *m_ClassProbability; //Class liklihood
00363 
00364   LabelStatusImagePointer   m_LabelStatusImage;
00365 
00366   std::vector<double>       m_MRFNeighborhoodWeight;
00367   std::vector<double>       m_NeighborInfluence;
00368   std::vector<double>       m_MahalanobisDistance;
00369 
00371  typename ClassifierType::Pointer m_ClassifierPtr;
00372 
00373 
00377   virtual void SetMRFNeighborhoodWeight( double* );
00378 
00379   //Function implementing the ICM algorithm to label the images
00380   void ApplyICMLabeller();
00381 
00382 
00383 }; // class MRFImageFilter
00384 
00385 
00386 } // namespace itk
00387 
00388 #ifndef ITK_MANUAL_INSTANTIATION
00389 #include "itkMRFImageFilter.txx"
00390 #endif
00391 
00392 
00393 
00394 #endif
00395 

Generated at Wed Mar 12 01:13:07 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000