ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkMRFImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMRFImageFilter_h
19 #define __itkMRFImageFilter_h
20 
21 #include "vnl/vnl_vector.h"
22 #include "vnl/vnl_matrix.h"
23 
24 #include "itkImageClassifierBase.h"
25 
26 #include "itkImageToImageFilter.h"
27 
30 #include "itkSize.h"
31 
32 namespace itk
33 {
124 template< class TInputImage, class TClassifiedImage >
125 class ITK_EXPORT MRFImageFilter:
126  public ImageToImageFilter< TInputImage, TClassifiedImage >
127 {
128 public:
134  typedef typename Superclass::OutputImagePointer OutputImagePointer;
135 
137  itkNewMacro(Self);
138 
140  itkTypeMacro(MRFImageFilter, Object);
141 
143  typedef TInputImage InputImageType;
144  typedef typename TInputImage::Pointer InputImagePointer;
145  typedef typename TInputImage::ConstPointer InputImageConstPointer;
146 
148  typedef typename TInputImage::PixelType InputImagePixelType;
149 
151  typedef typename TInputImage::RegionType InputImageRegionType;
152 
156 
158  itkStaticConstMacro(InputImageDimension, unsigned int,
159  TInputImage::ImageDimension);
160 
162  typedef typename TClassifiedImage::Pointer TrainingImagePointer;
163 
165  typedef typename TClassifiedImage::PixelType TrainingImagePixelType;
166 
169  typedef typename TClassifiedImage::Pointer LabelledImagePointer;
170 
173  typedef typename TClassifiedImage::PixelType LabelledImagePixelType;
174 
177  typedef typename TClassifiedImage::RegionType LabelledImageRegionType;
178 
180  typedef typename TClassifiedImage::IndexType LabelledImageIndexType;
182 
184  typedef typename TClassifiedImage::OffsetType LabelledImageOffsetType;
185 
189 
191  itkStaticConstMacro(ClassifiedImageDimension, unsigned int,
192  TClassifiedImage::ImageDimension);
193 
196 
198  typedef typename TInputImage::SizeType SizeType;
199 
201  typedef typename TInputImage::SizeType NeighborhoodRadiusType;
202 
206 
207  typedef typename InputImageNeighborhoodIterator::RadiusType
209 
212 
215 
216  typedef typename InputImageFaceListType::iterator
218 
222 
225 
228 
231 
232  typedef typename LabelledImageFaceListType::iterator
234 
236  void SetClassifier(typename ClassifierType::Pointer ptrToClassifier);
237 
239  itkSetMacro(NumberOfClasses, unsigned int);
240  itkGetConstMacro(NumberOfClasses, unsigned int);
242 
245  itkSetMacro(MaximumNumberOfIterations, unsigned int);
246  itkGetConstMacro(MaximumNumberOfIterations, unsigned int);
248 
251  itkSetMacro(ErrorTolerance, double);
252  itkGetConstMacro(ErrorTolerance, double);
254 
257  itkSetMacro(SmoothingFactor, double);
258  itkGetConstMacro(SmoothingFactor, double);
260 
262  void SetNeighborhoodRadius(const NeighborhoodRadiusType &);
263 
267  void SetNeighborhoodRadius(const SizeValueType);
268 
269  void SetNeighborhoodRadius(const SizeValueType *radiusArray);
270 
272  const NeighborhoodRadiusType GetNeighborhoodRadius() const
273  {
274  NeighborhoodRadiusType radius;
275 
276  for ( int i = 0; i < InputImageDimension; ++i )
277  {
278  radius[i] = m_InputImageNeighborhoodRadius[i];
279  }
280  return radius;
281  }
282 
288  virtual void SetMRFNeighborhoodWeight(std::vector< double > BetaMatrix);
289 
290  virtual std::vector< double > GetMRFNeighborhoodWeight()
291  {
292  return m_MRFNeighborhoodWeight;
293  }
294 
295 //Enum to get the stopping condition of the MRF filter
296  typedef enum {
297  MaximumNumberOfIterations = 1,
298  ErrorTolerance
299  } StopConditionType;
300 
303  itkGetConstReferenceMacro(StopCondition, StopConditionType);
304 
305  /* Get macro for number of iterations */
306  itkGetConstReferenceMacro(NumberOfIterations, unsigned int);
307 
308 #ifdef ITK_USE_CONCEPT_CHECKING
309 
310  itkConceptMacro( UnsignedIntConvertibleToClassifiedCheck,
312  itkConceptMacro( ClassifiedConvertibleToUnsignedIntCheck,
314  itkConceptMacro( ClassifiedConvertibleToIntCheck,
316  itkConceptMacro( IntConvertibleToClassifiedCheck,
318  itkConceptMacro( SameDimensionCheck,
320 
322 #endif
323 
324 protected:
325  MRFImageFilter();
326  ~MRFImageFilter();
327  void PrintSelf(std::ostream & os, Indent indent) const;
328 
330  void Allocate();
331 
336  virtual void ApplyMRFImageFilter();
337 
339  virtual void MinimizeFunctional();
340 
346 
350  //Function implementing the neighborhood operation
351 
352  virtual void DoNeighborhoodOperation(const InputImageNeighborhoodIterator & imageIter,
353  LabelledImageNeighborhoodIterator & labelledIter,
354  LabelStatusImageNeighborhoodIterator & labelStatusIter);
355 
356  virtual void GenerateData();
357 
358  virtual void GenerateInputRequestedRegion();
359 
360  virtual void EnlargeOutputRequestedRegion(DataObject *);
361 
362  virtual void GenerateOutputInformation();
363 
364 private:
365  MRFImageFilter(const Self &); //purposely not implemented
366  void operator=(const Self &); //purposely not implemented
367 
368  typedef typename TInputImage::SizeType InputImageSizeType;
369 
372 
375 
378 
379  typedef typename LabelStatusImageFaceListType::iterator
381 
385 
386  unsigned int m_NumberOfClasses;
388  unsigned int m_KernelSize;
389 
396  double * m_ClassProbability; //Class liklihood
397  unsigned int m_NumberOfIterations;
399 
401 
402  std::vector< double > m_MRFNeighborhoodWeight;
403  std::vector< double > m_NeighborInfluence;
404  std::vector< double > m_MahalanobisDistance;
405  std::vector< double > m_DummyVector;
406 
409 
413  virtual void SetDefaultMRFNeighborhoodWeight();
414 
415  //Function implementing the ICM algorithm to label the images
416  void ApplyICMLabeller();
417 }; // class MRFImageFilter
418 } // namespace itk
419 
420 #ifndef ITK_MANUAL_INSTANTIATION
421 #include "itkMRFImageFilter.hxx"
422 #endif
423 
424 #endif
425