ITK  4.13.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< typename TInputImage, typename TClassifiedImage >
125 class ITK_TEMPLATE_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 
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 
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 
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  // Begin concept checking
310  itkConceptMacro( UnsignedIntConvertibleToClassifiedCheck,
312  itkConceptMacro( ClassifiedConvertibleToUnsignedIntCheck,
314  itkConceptMacro( ClassifiedConvertibleToIntCheck,
316  itkConceptMacro( IntConvertibleToClassifiedCheck,
318  itkConceptMacro( SameDimensionCheck,
320  // End concept checking
321 #endif
322 
323 protected:
324  MRFImageFilter();
325  ~MRFImageFilter() ITK_OVERRIDE;
326  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
327 
329  void Allocate();
330 
335  virtual void ApplyMRFImageFilter();
336 
338  virtual void MinimizeFunctional();
339 
340  typedef Image< int, itkGetStaticConstMacro(InputImageDimension) > LabelStatusImageType;
341  typedef typename LabelStatusImageType::IndexType LabelStatusIndexType;
342  typedef typename LabelStatusImageType::RegionType LabelStatusRegionType;
343  typedef typename LabelStatusImageType::Pointer LabelStatusImagePointer;
344  typedef ImageRegionIterator< LabelStatusImageType > LabelStatusImageIterator;
345 
347  typedef NeighborhoodIterator< LabelStatusImageType >
349  //Function implementing the neighborhood operation
350 
351  virtual void DoNeighborhoodOperation(const InputImageNeighborhoodIterator & imageIter,
352  LabelledImageNeighborhoodIterator & labelledIter,
353  LabelStatusImageNeighborhoodIterator & labelStatusIter);
354 
355  virtual void GenerateData() ITK_OVERRIDE;
356 
357  virtual void GenerateInputRequestedRegion() ITK_OVERRIDE;
358 
359  virtual void EnlargeOutputRequestedRegion(DataObject *) ITK_OVERRIDE;
360 
361  virtual void GenerateOutputInformation() ITK_OVERRIDE;
362 
363 private:
364  ITK_DISALLOW_COPY_AND_ASSIGN(MRFImageFilter);
365 
366  typedef typename TInputImage::SizeType InputImageSizeType;
367 
368  typedef typename LabelStatusImageNeighborhoodIterator::RadiusType
370 
371  typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< LabelStatusImageType >
373 
374  typedef typename LabelStatusImageFacesCalculator::FaceListType
376 
377  typedef typename LabelStatusImageFaceListType::iterator
379 
380  InputImageNeighborhoodRadiusType m_InputImageNeighborhoodRadius;
381  LabelledImageNeighborhoodRadiusType m_LabelledImageNeighborhoodRadius;
382  LabelStatusImageNeighborhoodRadiusType m_LabelStatusImageNeighborhoodRadius;
383 
384  unsigned int m_NumberOfClasses;
385  unsigned int m_MaximumNumberOfIterations;
386  unsigned int m_KernelSize;
387 
388  int m_ErrorCounter;
389  int m_NeighborhoodSize;
390  int m_TotalNumberOfValidPixelsInOutputImage;
391  int m_TotalNumberOfPixelsInInputImage;
392  double m_ErrorTolerance;
393  double m_SmoothingFactor;
394  double * m_ClassProbability; //Class liklihood
395  unsigned int m_NumberOfIterations;
396  StopConditionType m_StopCondition;
397 
398  LabelStatusImagePointer m_LabelStatusImage;
399 
400  std::vector< double > m_MRFNeighborhoodWeight;
401  std::vector< double > m_NeighborInfluence;
402  std::vector< double > m_MahalanobisDistance;
403  std::vector< double > m_DummyVector;
404 
406  typename ClassifierType::Pointer m_ClassifierPtr;
407 
411  virtual void SetDefaultMRFNeighborhoodWeight();
412 
413  //Function implementing the ICM algorithm to label the images
414  void ApplyICMLabeller();
415 }; // class MRFImageFilter
416 } // namespace itk
417 
418 #ifndef ITK_MANUAL_INSTANTIATION
419 #include "itkMRFImageFilter.hxx"
420 #endif
421 
422 #endif
TInputImage::RegionType InputImageRegionType
Light weight base class for most itk classes.
LabelledImageIndexType::IndexValueType IndexValueType
LabelledImageFacesCalculator::FaceListType LabelledImageFaceListType
InputImageFaceListType::iterator InputImageFaceListIterator
TClassifiedImage::PixelType LabelledImagePixelType
LabelStatusImageType::RegionType LabelStatusRegionType
TClassifiedImage::IndexType LabelledImageIndexType
signed long IndexValueType
Definition: itkIntTypes.h:150
SmartPointer< const Self > ConstPointer
InputImageFacesCalculator::FaceListType InputImageFaceListType
TInputImage::PixelType InputImagePixelType
ImageRegionIterator< TInputImage > InputImageRegionIterator
LabelStatusImageNeighborhoodIterator::RadiusType LabelStatusImageNeighborhoodRadiusType
InputImageNeighborhoodIterator::RadiusType InputImageNeighborhoodRadiusType
NeighborhoodIterator< TClassifiedImage > LabelledImageNeighborhoodIterator
TClassifiedImage::OffsetType LabelledImageOffsetType
LabelledImageNeighborhoodIterator::RadiusType LabelledImageNeighborhoodRadiusType
Base class for the ImageClassifierBase object.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
TClassifiedImage::Pointer TrainingImagePointer
TClassifiedImage::RegionType LabelledImageRegionType
LabelStatusImageFaceListType::iterator LabelStatusImageFaceListIterator
Implementation of a labeller object that uses Markov Random Fields to classify pixels in an image dat...
ImageToImageFilter< TInputImage, TClassifiedImage > Superclass
ImageRegionIterator< TClassifiedImage > LabelledImageRegionIterator
Splits an image into a main region and several &quot;face&quot; regions which are used to handle computations o...
TClassifiedImage::PixelType TrainingImagePixelType
ImageRegionConstIterator< TInputImage > InputImageRegionConstIterator
ConstNeighborhoodIterator< TInputImage > InputImageNeighborhoodIterator
TClassifiedImage::Pointer LabelledImagePointer
A multi-dimensional iterator templated over image type that walks a region of pixels.
TInputImage::SizeType NeighborhoodRadiusType
Superclass::OutputImagePointer OutputImagePointer
LabelledImageFaceListType::iterator LabelledImageFaceListIterator
SmartPointer< Self > Pointer
TInputImage::SizeType SizeType
virtual std::vector< double > GetMRFNeighborhoodWeight()
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TInputImage > InputImageFacesCalculator
Superclass::RadiusType RadiusType
const NeighborhoodRadiusType GetNeighborhoodRadius() const
TInputImage::Pointer InputImagePointer
ImageClassifierBase< TInputImage, TClassifiedImage > ClassifierType
Base class for filters that take an image as input and produce an image as output.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
TInputImage::ConstPointer InputImageConstPointer
LabelStatusImageFacesCalculator::FaceListType LabelStatusImageFaceListType
Base class for most ITK classes.
Definition: itkObject.h:59
#define itkConceptMacro(name, concept)
NeighborhoodAlgorithm::ImageBoundaryFacesCalculator< TClassifiedImage > LabelledImageFacesCalculator
Base class for all data objects in ITK.
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
Templated n-dimensional image class.
Definition: itkImage.h:75
A multi-dimensional iterator templated over image type that walks a region of pixels.
TInputImage::SizeType InputImageSizeType