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

Generated at Wed Mar 30 00:04:08 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000