00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00295 typedef enum{
00296 MaximumNumberOfIterations=1,
00297 ErrorTolerance
00298 } StopConditionType;
00299
00302 itkGetConstReferenceMacro( StopCondition, StopConditionType );
00303
00304
00305 itkGetConstReferenceMacro( NumberOfIterations, unsigned int );
00306
00307 protected:
00308 MRFImageFilter();
00309 ~MRFImageFilter();
00310 void PrintSelf(std::ostream& os, Indent indent) const;
00311
00313 void Allocate();
00314
00319 virtual void ApplyMRFImageFilter();
00320
00322 virtual void MinimizeFunctional();
00323
00324 typedef Image<int,itkGetStaticConstMacro(InputImageDimension) > LabelStatusImageType;
00325 typedef typename LabelStatusImageType::IndexType LabelStatusIndexType;
00326 typedef typename LabelStatusImageType::RegionType LabelStatusRegionType;
00327 typedef typename LabelStatusImageType::Pointer LabelStatusImagePointer;
00328 typedef ImageRegionIterator< LabelStatusImageType >
00329 LabelStatusImageIterator;
00330
00332 typedef NeighborhoodIterator< LabelStatusImageType >
00333 LabelStatusImageNeighborhoodIterator;
00334
00335
00336 virtual void DoNeighborhoodOperation( const InputImageNeighborhoodIterator &imageIter,
00337 LabelledImageNeighborhoodIterator &labelledIter,
00338 LabelStatusImageNeighborhoodIterator &labelStatusIter );
00339
00340 virtual void GenerateData();
00341 virtual void GenerateInputRequestedRegion();
00342 virtual void EnlargeOutputRequestedRegion( DataObject * );
00343 virtual void GenerateOutputInformation();
00344
00345 private:
00346 MRFImageFilter(const Self&);
00347 void operator=(const Self&);
00348
00349 typedef typename TInputImage::SizeType InputImageSizeType;
00350
00351 typedef typename LabelStatusImageNeighborhoodIterator::RadiusType
00352 LabelStatusImageNeighborhoodRadiusType;
00353
00354 typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< LabelStatusImageType >
00355 LabelStatusImageFacesCalculator;
00356
00357 typedef typename LabelStatusImageFacesCalculator::FaceListType
00358 LabelStatusImageFaceListType;
00359
00360 typedef typename LabelStatusImageFaceListType::iterator
00361 LabelStatusImageFaceListIterator;
00362
00363 InputImageNeighborhoodRadiusType m_InputImageNeighborhoodRadius;
00364 LabelledImageNeighborhoodRadiusType m_LabelledImageNeighborhoodRadius;
00365 LabelStatusImageNeighborhoodRadiusType m_LabelStatusImageNeighborhoodRadius;
00366
00367 unsigned int m_NumberOfClasses;
00368 unsigned int m_MaximumNumberOfIterations;
00369 unsigned int m_KernelSize;
00370
00371 int m_ErrorCounter;
00372 int m_NeighborhoodSize;
00373 int m_TotalNumberOfValidPixelsInOutputImage;
00374 int m_TotalNumberOfPixelsInInputImage;
00375 double m_ErrorTolerance;
00376 double m_SmoothingFactor;
00377 double *m_ClassProbability;
00378 unsigned int m_NumberOfIterations;
00379 StopConditionType m_StopCondition;
00380
00381 LabelStatusImagePointer m_LabelStatusImage;
00382
00383 std::vector<double> m_MRFNeighborhoodWeight;
00384 std::vector<double> m_NeighborInfluence;
00385 std::vector<double> m_MahalanobisDistance;
00386 std::vector<double> m_DummyVector;
00387
00389 typename ClassifierType::Pointer m_ClassifierPtr;
00390
00391
00395 virtual void SetDefaultMRFNeighborhoodWeight( );
00396
00397
00398 void ApplyICMLabeller();
00399
00400 };
00401
00402
00403 }
00404
00405 #ifndef ITK_MANUAL_INSTANTIATION
00406 #include "itkMRFImageFilter.txx"
00407 #endif
00408
00409 #endif
00410