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/12/17 17:50:35 $
00007   Version:   $Revision: 1.35 $
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 
00127 template <class TInputImage, class TClassifiedImage>
00128 class ITK_EXPORT MRFImageFilter : 
00129   public ImageToImageFilter<TInputImage,TClassifiedImage>
00130 {
00131 public:       
00133   typedef MRFImageFilter   Self;
00134   typedef ImageToImageFilter<TInputImage,TClassifiedImage> Superclass;
00135   typedef SmartPointer<Self>  Pointer;
00136   typedef SmartPointer<const Self>  ConstPointer;
00137   typedef typename Superclass::OutputImagePointer OutputImagePointer;
00138 
00140   itkNewMacro(Self);
00141 
00143   itkTypeMacro(MRFImageFilter,Object);
00144 
00146   typedef TInputImage InputImageType;
00147   typedef typename TInputImage::Pointer              InputImagePointer;
00148   typedef typename TInputImage::ConstPointer         InputImageConstPointer;  
00149 
00151   typedef typename TInputImage::PixelType            InputImagePixelType;
00152 
00154   typedef typename TInputImage::RegionType           InputImageRegionType;
00155 
00157   typedef ImageRegionIterator<TInputImage>           InputImageRegionIterator;
00158   typedef ImageRegionConstIterator<TInputImage>      InputImageRegionConstIterator;
00159 
00161   itkStaticConstMacro(InputImageDimension, unsigned int,
00162                       TInputImage::ImageDimension);
00163 
00165   typedef typename TClassifiedImage::Pointer         TrainingImagePointer;
00166 
00168   typedef typename TClassifiedImage::PixelType       TrainingImagePixelType;
00169 
00172   typedef typename TClassifiedImage::Pointer         LabelledImagePointer;
00173       
00176   typedef typename TClassifiedImage::PixelType       LabelledImagePixelType;
00177 
00180   typedef typename TClassifiedImage::RegionType      LabelledImageRegionType;
00181 
00183   typedef typename TClassifiedImage::IndexType       LabelledImageIndexType;
00184   typedef typename LabelledImageIndexType::IndexValueType    IndexValueType;
00185 
00187   typedef typename TClassifiedImage::OffsetType      LabelledImageOffsetType;
00188 
00190   typedef ImageRegionIterator<TClassifiedImage>  
00191     LabelledImageRegionIterator;
00192 
00194   itkStaticConstMacro(ClassifiedImageDimension, unsigned int,
00195                       TClassifiedImage::ImageDimension);
00196 
00198   typedef ImageClassifierBase<TInputImage,TClassifiedImage> ClassifierType;
00199 
00201   typedef typename TInputImage::SizeType SizeType;
00202 
00204   typedef typename TInputImage::SizeType NeighborhoodRadiusType;
00205 
00207   typedef ConstNeighborhoodIterator< TInputImage >
00208     InputImageNeighborhoodIterator;
00209 
00210   typedef typename InputImageNeighborhoodIterator::RadiusType 
00211     InputImageNeighborhoodRadiusType;
00212 
00213   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TInputImage >
00214       InputImageFacesCalculator;
00215   
00216   typedef typename InputImageFacesCalculator::FaceListType
00217     InputImageFaceListType;
00218 
00219   typedef typename InputImageFaceListType::iterator 
00220     InputImageFaceListIterator;
00221 
00223   typedef NeighborhoodIterator< TClassifiedImage >
00224     LabelledImageNeighborhoodIterator;
00225 
00226   typedef typename LabelledImageNeighborhoodIterator::RadiusType 
00227     LabelledImageNeighborhoodRadiusType;
00228 
00229   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TClassifiedImage >
00230       LabelledImageFacesCalculator;
00231   
00232   typedef typename LabelledImageFacesCalculator::FaceListType
00233     LabelledImageFaceListType;
00234 
00235   typedef typename LabelledImageFaceListType::iterator 
00236     LabelledImageFaceListIterator;
00237 
00239   void SetClassifier( typename ClassifierType::Pointer ptrToClassifier );
00240 
00242   itkSetMacro(NumberOfClasses, unsigned int);
00243   itkGetMacro(NumberOfClasses, unsigned int);
00244 
00247   itkSetMacro(MaximumNumberOfIterations, unsigned int);
00248   itkGetMacro(MaximumNumberOfIterations, unsigned int);
00249 
00252   itkSetMacro(ErrorTolerance, double);
00253   itkGetMacro(ErrorTolerance, double);
00254 
00257   itkSetMacro(SmoothingFactor, double);
00258   itkGetMacro(SmoothingFactor, double);
00259 
00261   void SetNeighborhoodRadius(const NeighborhoodRadiusType &);  
00262 
00266   void SetNeighborhoodRadius( const unsigned long );
00267   void SetNeighborhoodRadius( const unsigned long *radiusArray );  
00268 
00270   const NeighborhoodRadiusType GetNeighborhoodRadius() const
00271     { 
00272       NeighborhoodRadiusType radius;
00273       
00274       for(int i=0; i<InputImageDimension; ++i)
00275         radius[i] = m_InputImageNeighborhoodRadius[i];
00276 
00277       return radius;
00278     }
00279     
00285   virtual void SetMRFNeighborhoodWeight( std::vector<double> BetaMatrix );
00286   virtual std::vector<double> GetMRFNeighborhoodWeight()
00287     {
00288     return m_MRFNeighborhoodWeight;
00289     }
00290     
00291 protected:
00292   MRFImageFilter();
00293   ~MRFImageFilter();
00294   void PrintSelf(std::ostream& os, Indent indent) const;
00295 
00297   void Allocate();
00298 
00303   virtual void ApplyMRFImageFilter();  
00304 
00306   virtual void MinimizeFunctional();
00307 
00308   typedef Image<int,itkGetStaticConstMacro(InputImageDimension) > LabelStatusImageType;
00309   typedef typename LabelStatusImageType::IndexType LabelStatusIndexType;
00310   typedef typename LabelStatusImageType::RegionType LabelStatusRegionType;
00311   typedef typename LabelStatusImageType::Pointer LabelStatusImagePointer;
00312   typedef ImageRegionIterator< LabelStatusImageType > 
00313     LabelStatusImageIterator;
00314 
00316   typedef NeighborhoodIterator< LabelStatusImageType >
00317     LabelStatusImageNeighborhoodIterator;
00318   //Function implementing the neighborhood operation
00319 
00320   virtual void DoNeighborhoodOperation( const InputImageNeighborhoodIterator &imageIter,
00321     LabelledImageNeighborhoodIterator &labelledIter,
00322     LabelStatusImageNeighborhoodIterator &labelStatusIter );
00323 
00324   virtual void GenerateData();
00325   virtual void GenerateInputRequestedRegion();
00326   virtual void EnlargeOutputRequestedRegion( DataObject * );
00327   virtual void GenerateOutputInformation();
00328 
00329 private:            
00330   MRFImageFilter(const Self&); //purposely not implemented
00331   void operator=(const Self&); //purposely not implemented
00332   
00333   typedef typename TInputImage::SizeType InputImageSizeType;
00334 
00335   typedef typename LabelStatusImageNeighborhoodIterator::RadiusType 
00336     LabelStatusImageNeighborhoodRadiusType;
00337 
00338   typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< LabelStatusImageType >
00339       LabelStatusImageFacesCalculator;
00340   
00341   typedef typename LabelStatusImageFacesCalculator::FaceListType
00342     LabelStatusImageFaceListType;
00343 
00344   typedef typename LabelStatusImageFaceListType::iterator 
00345     LabelStatusImageFaceListIterator;
00346 
00347   InputImageNeighborhoodRadiusType       m_InputImageNeighborhoodRadius;
00348   LabelledImageNeighborhoodRadiusType    m_LabelledImageNeighborhoodRadius;
00349   LabelStatusImageNeighborhoodRadiusType m_LabelStatusImageNeighborhoodRadius;
00350  
00351   unsigned int              m_NumberOfClasses;
00352   unsigned int              m_MaximumNumberOfIterations;
00353   unsigned int              m_KernelSize;
00354 
00355   int                       m_ErrorCounter;
00356   int                       m_NeighborhoodSize;
00357   int                       m_TotalNumberOfValidPixelsInOutputImage;
00358   int                       m_TotalNumberOfPixelsInInputImage;
00359   double                    m_ErrorTolerance;  
00360   double                    m_SmoothingFactor;
00361   double                    *m_ClassProbability; //Class liklihood
00362 
00363   LabelStatusImagePointer   m_LabelStatusImage;
00364 
00365   std::vector<double>       m_MRFNeighborhoodWeight;
00366   std::vector<double>       m_NeighborInfluence;
00367   std::vector<double>       m_MahalanobisDistance;
00368 
00370  typename ClassifierType::Pointer m_ClassifierPtr;
00371 
00372 
00376   virtual void SetMRFNeighborhoodWeight( double* );
00377 
00378   //Function implementing the ICM algorithm to label the images
00379   void ApplyICMLabeller();
00380 
00381 
00382 }; // class MRFImageFilter
00383 
00384 
00385 } // namespace itk
00386 
00387 #ifndef ITK_MANUAL_INSTANTIATION
00388 #include "itkMRFImageFilter.txx"
00389 #endif
00390 
00391 
00392 
00393 #endif
00394 

Generated at Fri May 21 01:15:04 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000