ITK  5.4.0
Insight Toolkit
itkRGBGibbsPriorFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 #include <memory> // For unique_ptr.
27 
28 namespace itk
29 {
55 template <typename TInputImage, typename TClassifiedImage>
56 class ITK_TEMPLATE_EXPORT RGBGibbsPriorFilter : public MRFImageFilter<TInputImage, TClassifiedImage>
57 {
58 public:
59  ITK_DISALLOW_COPY_AND_MOVE(RGBGibbsPriorFilter);
60 
66 
68  itkNewMacro(Self);
69 
71  itkOverrideGetNameOfClassMacro(RGBGibbsPriorFilter);
72 
74  using typename Superclass::InputImagePixelType;
75  using typename Superclass::InputImageRegionConstIterator;
76  using typename Superclass::InputImageRegionIterator;
77  using typename Superclass::LabelledImageRegionIterator;
78  using typename Superclass::LabelledImagePixelType;
79  using typename Superclass::IndexValueType;
80 
82  using InputImageType = TInputImage;
85 
87  using InputPixelType = typename TInputImage::PixelType;
88 
90  using ClassifiedImageType = TClassifiedImage;
92 
96 
99 
103  using LabelType = unsigned int;
104 
107 
109  using InputImageVecType = typename TInputImage::PixelType;
111 
113  itkSetMacro(TrainingImage, TrainingImageType);
114  itkGetConstMacro(TrainingImage, TrainingImageType);
118  void
119  SetLabelledImage(LabelledImageType image);
120 
124  {
125  return m_LabelledImage;
126  }
127 
129  void
130  SetClassifier(typename ClassifierType::Pointer ptrToClassifier);
131 
133  void
134  SetNumberOfClasses(const unsigned int numberOfClasses) override
135  {
136  itkDebugMacro("setting NumberOfClasses to " << numberOfClasses);
137  if (this->m_NumberOfClasses != numberOfClasses)
138  {
139  this->m_NumberOfClasses = numberOfClasses;
140  this->Modified();
141  }
142  }
146  unsigned int
147  GetNumberOfClasses() const override
148  {
149  return this->m_NumberOfClasses;
150  }
151 
154  void
155  SetMaximumNumberOfIterations(const unsigned int numberOfIterations) override
156  {
157  itkDebugMacro("setting MaximumNumberOfIterations to " << numberOfIterations);
158  if (this->m_MaximumNumberOfIterations != numberOfIterations)
159  {
160  this->m_MaximumNumberOfIterations = numberOfIterations;
161  this->Modified();
162  }
163  }
168  unsigned int
170  {
171  return this->m_MaximumNumberOfIterations;
172  }
173 
175  itkSetMacro(ClusterSize, unsigned int);
176  itkGetConstMacro(ClusterSize, unsigned int);
180  itkSetMacro(ObjectLabel, LabelType);
181  itkGetConstMacro(ObjectLabel, LabelType);
185  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
186 
187  itkSetMacro(StartPoint, IndexType);
188  itkGetConstMacro(StartPoint, IndexType);
189 
190  itkSetMacro(BoundaryGradient, unsigned int);
191  itkGetConstMacro(BoundaryGradient, unsigned int);
192 
193  itkSetMacro(ObjectThreshold, double);
194  itkGetConstMacro(ObjectThreshold, double);
195 
197  itkSetMacro(CliqueWeight_1, double);
198  itkGetConstMacro(CliqueWeight_1, double);
199  itkSetMacro(CliqueWeight_2, double);
200  itkGetConstMacro(CliqueWeight_2, double);
201  itkSetMacro(CliqueWeight_3, double);
202  itkGetConstMacro(CliqueWeight_3, double);
203  itkSetMacro(CliqueWeight_4, double);
204  itkGetConstMacro(CliqueWeight_4, double);
205  itkSetMacro(CliqueWeight_5, double);
206  itkGetConstMacro(CliqueWeight_5, double);
207  itkSetMacro(CliqueWeight_6, double);
208  itkGetConstMacro(CliqueWeight_6, double);
212  using MatrixType = vnl_matrix<double>;
213 
214 protected:
216  ~RGBGibbsPriorFilter() override = default;
217  void
218  PrintSelf(std::ostream & os, Indent indent) const override;
219 
221  void
222  Allocate();
223 
224  void
225  MinimizeFunctional() override;
226 
227  void
228  GenerateData() override;
229 
230  virtual void
231  ApplyGibbsLabeller();
232 
233  virtual void
234  ApplyGPImageFilter();
235 
236 #ifdef ITK_USE_CONCEPT_CHECKING
237  // Begin concept checking
239  SameDimension,
242  // End concept checking
243 #endif
244 
245 private:
247 
249  InputImageConstPointer m_InputImage{};
250 
252  TrainingImageType m_TrainingImage{};
253 
255  LabelledImageType m_LabelledImage{};
256 
258  unsigned int m_NumberOfClasses{ 0 };
259 
261  unsigned int m_MaximumNumberOfIterations{ 10 };
262 
263  typename ClassifierType::Pointer m_ClassifierPtr{};
264 
266  unsigned int m_BoundaryGradient{ 7 };
267 
269  double m_BoundaryWeight{ 1 };
270 
272  double m_GibbsPriorWeight{ 1 };
273 
275  int m_StartRadius{ 10 };
276 
278  int m_RecursiveNumber{ 0 };
279 
281  std::unique_ptr<LabelType[]> m_LabelStatus{ nullptr };
282 
284  InputImagePointer m_MediumImage{};
285 
287  unsigned int m_Temp{ 0 };
288 
290  IndexType m_StartPoint{};
291 
293  unsigned int m_ImageWidth{ 0 };
294 
296  unsigned int m_ImageHeight{ 0 };
297 
299  unsigned int m_ImageDepth{ 0 };
300 
302  unsigned int m_ClusterSize{ 10 };
303 
305  LabelType m_ObjectLabel{ 1 };
306 
308  unsigned int m_VecDim{ 0 };
309 
311  InputPixelType m_LowPoint{};
312 
314  std::unique_ptr<unsigned short[]> m_Region{ nullptr };
315 
317  std::unique_ptr<unsigned short[]> m_RegionCount{ nullptr };
318 
319  // Weights for different clique configurations.
320 
322  double m_CliqueWeight_1{ 0.0 };
323 
325  double m_CliqueWeight_2{ 0.0 };
326 
328  double m_CliqueWeight_3{ 0.0 };
329 
331  double m_CliqueWeight_4{ 0.0 };
332 
334  double m_CliqueWeight_5{ 0.0 };
335 
337  double m_CliqueWeight_6{ 0.0 };
338 
341  void
342  GibbsTotalEnergy(int i);
343 
345  double
346  GibbsEnergy(unsigned int i, unsigned int k, unsigned int k1);
347 
349  int
350  Sim(int a, int b);
351 
353  unsigned int
354  LabelRegion(int i, int l, int change);
355 
358  void
359  RegionEraser();
360 
362  void
363  GenerateMediumImage();
364 
367  void
368  GreyScalarBoundary(LabelledImageIndexType Index3D);
369 
370  double m_ObjectThreshold{ 5.0 };
371 };
372 } // end namespace itk
373 #ifndef ITK_MANUAL_INSTANTIATION
374 # include "itkRGBGibbsPriorFilter.hxx"
375 #endif
376 #endif
itk::RGBGibbsPriorFilter::ClassifiedImageType
TClassifiedImage ClassifiedImageType
Definition: itkRGBGibbsPriorFilter.h:90
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkAddImageFilter.h:94
itk::RGBGibbsPriorFilter::TrainingImageType
typename TClassifiedImage::Pointer TrainingImageType
Definition: itkRGBGibbsPriorFilter.h:91
itk::RGBGibbsPriorFilter::SetMaximumNumberOfIterations
void SetMaximumNumberOfIterations(const unsigned int numberOfIterations) override
Definition: itkRGBGibbsPriorFilter.h:155
itk::MRFImageFilter
Implementation of a labeler object that uses Markov Random Fields to classify pixels in an image data...
Definition: itkMRFImageFilter.h:149
itk::MRFImageFilter::InputImageConstPointer
typename TInputImage::ConstPointer InputImageConstPointer
Definition: itkMRFImageFilter.h:171
itk::RGBGibbsPriorFilter::LabelType
unsigned int LabelType
Definition: itkRGBGibbsPriorFilter.h:103
itk::RGBGibbsPriorFilter::GetNumberOfClasses
unsigned int GetNumberOfClasses() const override
Definition: itkRGBGibbsPriorFilter.h:147
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itk::RGBGibbsPriorFilter::LabelledImageType
typename TClassifiedImage::Pointer LabelledImageType
Definition: itkRGBGibbsPriorFilter.h:95
itk::SmartPointer< Self >
itk::RGBGibbsPriorFilter::InputPixelType
typename TInputImage::PixelType InputPixelType
Definition: itkRGBGibbsPriorFilter.h:87
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::RGBGibbsPriorFilter
The RGBGibbsPriorFilter applies Gibbs Prior model for the segmentation of MRF images.
Definition: itkRGBGibbsPriorFilter.h:56
itk::IndexValueType
long IndexValueType
Definition: itkIntTypes.h:90
itk::Concept::SameDimension
Definition: itkConceptChecking.h:694
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::MRFImageFilter::LabelledImageIndexType
typename TClassifiedImage::IndexType LabelledImageIndexType
Definition: itkMRFImageFilter.h:205
itk::RGBGibbsPriorFilter::GetMaximumNumberOfIterations
unsigned int GetMaximumNumberOfIterations() const override
Definition: itkRGBGibbsPriorFilter.h:169
itk::ImageClassifierBase
Base class for the ImageClassifierBase object.
Definition: itkImageClassifierBase.h:71
itk::MRFImageFilter::InputImageSizeType
typename TInputImage::SizeType InputImageSizeType
Definition: itkMRFImageFilter.h:393
itk::RGBGibbsPriorFilter::IndexType
typename TInputImage::IndexType IndexType
Definition: itkRGBGibbsPriorFilter.h:110
itkMRFImageFilter.h
itk::MRFImageFilter::InputImagePointer
typename TInputImage::Pointer InputImagePointer
Definition: itkMRFImageFilter.h:170
itk::RGBGibbsPriorFilter::SetNumberOfClasses
void SetNumberOfClasses(const unsigned int numberOfClasses) override
Definition: itkRGBGibbsPriorFilter.h:134
itk::MRFImageFilter::InputImageType
TInputImage InputImageType
Definition: itkMRFImageFilter.h:169
itk::RGBGibbsPriorFilter::InputImageVecType
typename TInputImage::PixelType InputImageVecType
Definition: itkRGBGibbsPriorFilter.h:109
itkConceptMacro
#define itkConceptMacro(name, concept)
Definition: itkConceptChecking.h:65
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::RGBGibbsPriorFilter::MatrixType
vnl_matrix< double > MatrixType
Definition: itkRGBGibbsPriorFilter.h:212
itk::RGBGibbsPriorFilter::GetLabelledImage
LabelledImageType GetLabelledImage()
Definition: itkRGBGibbsPriorFilter.h:123