ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkRGBGibbsPriorFilter.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 itkRGBGibbsPriorFilter_h
19 #define itkRGBGibbsPriorFilter_h
20 
21 #include "vnl/vnl_vector.h"
22 #include "vnl/vnl_matrix.h"
23 
24 #include "itkMRFImageFilter.h"
25 
26 namespace itk
27 {
46 template< typename TInputImage, typename TClassifiedImage >
47 class ITK_TEMPLATE_EXPORT RGBGibbsPriorFilter:public MRFImageFilter< TInputImage,
48  TClassifiedImage >
49 {
50 public:
56 
58  itkNewMacro(Self);
59 
61  itkTypeMacro(RGBGibbsPriorFilter, MRFImageFilter);
62 
64  using InputImagePixelType = typename Superclass::InputImagePixelType;
65  using InputImageRegionConstIterator = typename Superclass::InputImageRegionConstIterator;
66  using InputImageRegionIterator = typename Superclass::InputImageRegionIterator;
67  using LabelledImageRegionIterator = typename Superclass::LabelledImageRegionIterator;
68  using LabelledImagePixelType = typename Superclass::LabelledImagePixelType;
70 
72  using InputImageType = TInputImage;
73  using InputImagePointer = typename TInputImage::Pointer;
74  using InputImageConstPointer = typename TInputImage::ConstPointer;
75 
77  using InputPixelType = typename TInputImage::PixelType;
78 
80  using ClassifiedImageType = TClassifiedImage;
81  using TrainingImageType = typename TClassifiedImage::Pointer;
82 
85  using LabelledImageType = typename TClassifiedImage::Pointer;
86 
89 
93  using LabelType = unsigned int;
94 
97 
99  using InputImageVecType = typename TInputImage::PixelType;
101 
103  void SetTrainingImage(TrainingImageType image);
104 
106  void SetLabelledImage(LabelledImageType LabelledImage);
107 
110  { return m_LabelledImage; }
111 
113  void SetClassifier(typename ClassifierType::Pointer ptrToClassifier);
114 
116  void SetNumberOfClasses( const unsigned int numberOfClasses ) override
117  {
118  itkDebugMacro("setting NumberOfClasses to " << numberOfClasses );
119  if ( this->m_NumberOfClasses != numberOfClasses )
120  {
121  this->m_NumberOfClasses = numberOfClasses;
122  this->Modified();
123  }
124  }
126 
128  unsigned int GetNumberOfClasses() const override
129  {
130  return this->m_NumberOfClasses;
131  }
132 
135  void SetMaximumNumberOfIterations( const unsigned int numberOfIterations ) override
136  {
137  itkDebugMacro("setting MaximumNumberOfIterations to " << numberOfIterations);
138  if ( this->m_MaximumNumberOfIterations != numberOfIterations )
139  {
140  this->m_MaximumNumberOfIterations = numberOfIterations;
141  this->Modified();
142  }
143  }
145 
148  unsigned int GetMaximumNumberOfIterations() const override
149  {
150  return this->m_MaximumNumberOfIterations;
151  }
152 
154  itkSetMacro(ClusterSize, unsigned int);
155 
157  itkSetMacro(ObjectLabel, LabelType);
158 
160  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
161 
162  itkSetMacro(StartPoint, IndexType);
163 
164  itkSetMacro(BoundaryGradient, unsigned int);
165 
166  itkSetMacro(ObjectThreshold, double);
167 
169  itkSetMacro(CliqueWeight_1, double);
170  itkGetConstMacro(CliqueWeight_1, double);
171  itkSetMacro(CliqueWeight_2, double);
172  itkGetConstMacro(CliqueWeight_2, double);
173  itkSetMacro(CliqueWeight_3, double);
174  itkGetConstMacro(CliqueWeight_3, double);
175  itkSetMacro(CliqueWeight_4, double);
176  itkGetConstMacro(CliqueWeight_4, double);
177  itkSetMacro(CliqueWeight_5, double);
178  itkGetConstMacro(CliqueWeight_5, double);
179  itkSetMacro(CliqueWeight_6, double);
180  itkGetConstMacro(CliqueWeight_6, double);
182 
184  using MatrixType = vnl_matrix< double >;
185 
186 protected:
188  ~RGBGibbsPriorFilter() override;
189  void PrintSelf(std::ostream & os, Indent indent) const override;
190 
193  void MinimizeFunctional() override;
194 
195  void GenerateData() override;
196 
197  virtual void ApplyGibbsLabeller();
198 
199  virtual void ApplyGPImageFilter();
200 
201 #ifdef ITK_USE_CONCEPT_CHECKING
202  // Begin concept checking
203  itkConceptMacro( SameDimension,
204  ( Concept::SameDimension< Self::InputImageType::ImageDimension,
205  Self::ClassifiedImageType::ImageDimension > ) );
206  itkConceptMacro( DimensionShouldBe3,
208  // End concept checking
209 #endif
210 
211 private:
212  RGBGibbsPriorFilter(const Self &) = delete;
213  void operator=(const Self &) = delete;
214 
216 
232 
254  unsigned int m_ImageHeight{0};
255  unsigned int m_ImageDepth{0};
256 
289  void GibbsTotalEnergy(int i);
290 
292  double GibbsEnergy(unsigned int i, unsigned int k, unsigned int k1);
293 
307  double m_ObjectThreshold{5.0};
308 };
309 } // end namespace itk
310 #ifndef ITK_MANUAL_INSTANTIATION
311 #include "itkRGBGibbsPriorFilter.hxx"
312 #endif
313 #endif
void SetMaximumNumberOfIterations(const unsigned int numberOfIterations) override
typename TInputImage::ConstPointer InputImageConstPointer
Light weight base class for most itk classes.
typename TClassifiedImage::IndexType LabelledImageIndexType
typename TInputImage::SizeType InputImageSizeType
typename TClassifiedImage::Pointer TrainingImageType
typename TInputImage::PixelType InputPixelType
typename TInputImage::PixelType InputImagePixelType
typename TClassifiedImage::Pointer LabelledImageType
ClassifierType::Pointer m_ClassifierPtr
Base class for the ImageClassifierBase object.
Implementation of a labeller object that uses Markov Random Fields to classify pixels in an image dat...
LabelledImageType GetLabelledImage()
void SetNumberOfClasses(const unsigned int numberOfClasses) override
typename TInputImage::IndexType IndexType
typename TInputImage::PixelType InputImageVecType
A multi-dimensional iterator templated over image type that walks a region of pixels.
signed long IndexValueType
Definition: itkIntTypes.h:90
vnl_matrix< double > MatrixType
typename TInputImage::Pointer InputImagePointer
typename TClassifiedImage::PixelType LabelledImagePixelType
The RGBGibbsPriorFilter applies Gibbs Prior model for the segmentation of MRF images.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename LabelledImageIndexType::IndexValueType IndexValueType
unsigned int GetNumberOfClasses() const override
#define itkConceptMacro(name, concept)
TClassifiedImage ClassifiedImageType
A multi-dimensional iterator templated over image type that walks a region of pixels.
unsigned int GetMaximumNumberOfIterations() const override