ITK  5.2.0
Insight Toolkit
itkPatchBasedDenoisingBaseImageFilter.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  * 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 itkPatchBasedDenoisingBaseImageFilter_h
19 #define itkPatchBasedDenoisingBaseImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 #include "itkArray.h"
23 #include "itkSample.h"
24 #include "itkNumericTraits.h"
28 #include "itkRGBPixel.h"
29 #include "itkRGBAPixel.h"
30 #include "itkDiffusionTensor3D.h"
31 #include "ITKDenoisingExport.h"
32 
33 namespace itk
34 {
40 {
41 public:
46  enum class NoiseModel : uint8_t
47  {
48  NOMODEL = 0,
49  GAUSSIAN = 1,
50  RICIAN = 2,
51  POISSON = 3
52  };
53 
60  enum class ComponentSpace : uint8_t
61  {
62  EUCLIDEAN = 0,
63  RIEMANNIAN = 1
64  };
65 
70  enum class FilterState : uint8_t
71  {
72  UNINITIALIZED = 0,
73  INITIALIZED = 1
74  };
75 };
76 // Define how to print enumeration
77 extern ITKDenoising_EXPORT std::ostream &
78  operator<<(std::ostream & out, const PatchBasedDenoisingBaseImageFilterEnums::NoiseModel value);
79 extern ITKDenoising_EXPORT std::ostream &
81 // Define how to print enumeration
82 extern ITKDenoising_EXPORT std::ostream &
143 
144 template <typename TInputImage, typename TOutputImage>
145 class ITK_TEMPLATE_EXPORT PatchBasedDenoisingBaseImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
146 {
147 public:
148  ITK_DISALLOW_COPY_AND_MOVE(PatchBasedDenoisingBaseImageFilter);
149 
155 
158 
160  using InputImageType = TInputImage;
161  using OutputImageType = TOutputImage;
162 
164  static constexpr unsigned int ImageDimension = InputImageType::ImageDimension;
165 
169  using InputPixelType = typename InputImageType::PixelType;
170  using OutputPixelType = typename OutputImageType::PixelType;
173 
177 #if !defined(ITK_LEGACY_REMOVE)
182  static constexpr NoiseModelEnum NOMODEL = NoiseModelEnum::NOMODEL;
183  static constexpr NoiseModelEnum GAUSSIAN = NoiseModelEnum::GAUSSIAN;
184  static constexpr NoiseModelEnum RICIAN = NoiseModelEnum::RICIAN;
185  static constexpr NoiseModelEnum POISSON = NoiseModelEnum::POISSON;
186 
187  static constexpr ComponentSpaceEnum EUCLIDEAN = ComponentSpaceEnum::EUCLIDEAN;
188  static constexpr ComponentSpaceEnum RIEMANNIAN = ComponentSpaceEnum::RIEMANNIAN;
189 
192 #endif
193 
198 
203  using ListAdaptorType =
204  typename ::itk::Statistics::ImageToNeighborhoodSampleAdaptor<OutputImageType, BoundaryConditionType>;
205  using PatchRadiusType = typename ListAdaptorType::NeighborhoodRadiusType;
207 
213  itkSetMacro(PatchRadius, unsigned int);
214  itkGetConstMacro(PatchRadius, unsigned int);
216 
218  GetPatchRadiusInVoxels() const;
219 
221  GetPatchDiameterInVoxels() const;
222 
224  GetPatchLengthInVoxels() const;
225 
230  void
231  SetPatchWeights(const PatchWeightsType & weights);
232 
234  GetPatchWeights() const;
235 
240  itkSetEnumMacro(NoiseModel, NoiseModelEnum);
241  itkGetConstMacro(NoiseModel, NoiseModelEnum);
243 
249  itkSetClampMacro(SmoothingWeight, double, 0.0, 1.0);
250  itkGetConstMacro(SmoothingWeight, double);
252 
258  itkSetClampMacro(NoiseModelFidelityWeight, double, 0.0, 1.0);
259  itkGetConstMacro(NoiseModelFidelityWeight, double);
261 
266  itkSetMacro(KernelBandwidthEstimation, bool);
267  itkBooleanMacro(KernelBandwidthEstimation);
268  itkGetConstMacro(KernelBandwidthEstimation, bool);
270 
277  itkSetClampMacro(KernelBandwidthUpdateFrequency, unsigned int, 1, NumericTraits<unsigned int>::max());
278  itkGetConstMacro(KernelBandwidthUpdateFrequency, unsigned int);
280 
285  itkSetClampMacro(NumberOfIterations, unsigned int, 1, NumericTraits<unsigned int>::max());
286  itkGetConstReferenceMacro(NumberOfIterations, unsigned int);
288 
290  itkGetConstReferenceMacro(ElapsedIterations, unsigned int);
291 
296  itkSetMacro(AlwaysTreatComponentsAsEuclidean, bool);
297  itkBooleanMacro(AlwaysTreatComponentsAsEuclidean);
298  itkGetConstMacro(AlwaysTreatComponentsAsEuclidean, bool);
300 
302  virtual void
303  SetStateToInitialized();
304 
306  virtual void
307  SetStateToUninitialized();
308 
310 #if !defined(ITK_WRAPPING_PARSER)
311  itkSetEnumMacro(State, FilterStateEnum);
312  itkGetConstReferenceMacro(State, FilterStateEnum);
313 #endif
314 
315 
320  itkSetMacro(ManualReinitialization, bool);
321  itkGetConstReferenceMacro(ManualReinitialization, bool);
322  itkBooleanMacro(ManualReinitialization);
324 
325 protected:
327  ~PatchBasedDenoisingBaseImageFilter() override = default;
328 
329  void
330  PrintSelf(std::ostream & os, Indent indent) const override;
331 
332  void
333  GenerateInputRequestedRegion() override;
334 
335  void
336  GenerateData() override;
337 
338  virtual void
339  CopyInputToOutput() = 0;
340 
342  virtual void
343  InitializePatchWeights();
344 
345  virtual void
347  {}
348 
350  virtual void
351  AllocateUpdateBuffer() = 0;
352 
353  virtual void
355  {}
356 
357  virtual void
359  {}
360 
362  virtual void
363  ComputeKernelBandwidthUpdate() = 0;
364 
366  virtual void
367  ComputeImageUpdate() = 0;
368 
369  virtual void
370  ApplyUpdate() = 0;
371 
372  virtual void
374  {}
375 
377  virtual bool
378  Halt();
379 
380  virtual bool
381  ThreadedHalt(void * itkNotUsed(threadInfo))
382  {
383  return this->Halt();
384  }
385 
386  itkSetMacro(ElapsedIterations, unsigned int);
387 
389  ComponentSpaceEnum
391  {
392  return ComponentSpaceEnum::EUCLIDEAN;
393  }
394 
395  ComponentSpaceEnum
397  {
398  return ComponentSpaceEnum::EUCLIDEAN;
399  }
400 
401  ComponentSpaceEnum
403  {
404  return ComponentSpaceEnum::RIEMANNIAN;
405  }
406 
407  template <typename PixelT>
408  ComponentSpaceEnum
409  DetermineComponentSpace(const PixelT & itkNotUsed(p))
410  {
411  return ComponentSpaceEnum::EUCLIDEAN;
412  }
413 
415  itkSetEnumMacro(ComponentSpace, ComponentSpaceEnum);
416  itkGetConstMacro(ComponentSpace, ComponentSpaceEnum);
418 
419  // Cache input and output pointer to get rid of thousands of calls
420  // to GetInput and GetOutput.
423 
424 private:
426  unsigned int m_PatchRadius{ 4 };
428 
430  bool m_KernelBandwidthEstimation{ false };
431  unsigned int m_KernelBandwidthUpdateFrequency{ 3 };
432 
435  unsigned int m_NumberOfIterations{ 1 };
436  unsigned int m_ElapsedIterations{ 0 };
437 
439  NoiseModelEnum m_NoiseModel{ NoiseModelEnum::NOMODEL };
440  double m_SmoothingWeight{ 1.0 };
441  double m_NoiseModelFidelityWeight{ 0.0 };
442 
445  bool m_AlwaysTreatComponentsAsEuclidean{ false };
446  ComponentSpaceEnum m_ComponentSpace{ ComponentSpaceEnum::EUCLIDEAN };
447 
448  bool m_ManualReinitialization{ false };
449 
451 };
452 } // end namespace itk
453 
454 #ifndef ITK_MANUAL_INSTANTIATION
455 # include "itkPatchBasedDenoisingBaseImageFilter.hxx"
456 #endif
457 
458 #endif
itk::PatchBasedDenoisingBaseImageFilter::PreProcessInput
virtual void PreProcessInput()
Definition: itkPatchBasedDenoisingBaseImageFilter.h:354
itk::PatchBasedDenoisingBaseImageFilter::InputPixelType
typename InputImageType::PixelType InputPixelType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:169
itk::uint8_t
::uint8_t uint8_t
Definition: itkIntTypes.h:29
itk::PatchBasedDenoisingBaseImageFilterEnums::NoiseModel::NOMODEL
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
itkConstNeighborhoodIterator.h
itk::PatchBasedDenoisingBaseImageFilterEnums::FilterState
FilterState
Definition: itkPatchBasedDenoisingBaseImageFilter.h:70
itk::PatchBasedDenoisingBaseImageFilter::DetermineComponentSpace
ComponentSpaceEnum DetermineComponentSpace(const RGBAPixel< PixelValueType > &)
Definition: itkPatchBasedDenoisingBaseImageFilter.h:396
itkRGBPixel.h
itk::PatchBasedDenoisingBaseImageFilter::DetermineComponentSpace
ComponentSpaceEnum DetermineComponentSpace(const RGBPixel< PixelValueType > &)
Definition: itkPatchBasedDenoisingBaseImageFilter.h:390
itk::PatchBasedDenoisingBaseImageFilterEnums::ComponentSpace
ComponentSpace
Definition: itkPatchBasedDenoisingBaseImageFilter.h:60
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:218
FilterState
itk::PatchBasedDenoisingBaseImageFilterEnums::ComponentSpace::RIEMANNIAN
itkDiffusionTensor3D.h
itk::PatchBasedDenoisingBaseImageFilter::PatchRadiusType
typename ListAdaptorType::NeighborhoodRadiusType PatchRadiusType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:205
itk::PatchBasedDenoisingBaseImageFilter::ThreadedHalt
virtual bool ThreadedHalt(void *)
Definition: itkPatchBasedDenoisingBaseImageFilter.h:381
itk::DiffusionTensor3D
Represent a diffusion tensor as used in DTI images.
Definition: itkDiffusionTensor3D.h:79
itkRGBAPixel.h
itk::PatchBasedDenoisingBaseImageFilterEnums::FilterState::INITIALIZED
itk::PatchBasedDenoisingBaseImageFilterEnums::NoiseModel::RICIAN
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::PatchBasedDenoisingBaseImageFilter::OutputImageType
TOutputImage OutputImageType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:161
itk::ImageToImageFilter
Base class for filters that take an image as input and produce an image as output.
Definition: itkImageToImageFilter.h:108
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
NoiseModel
itk::PatchBasedDenoisingBaseImageFilterEnums
Contains all enum classes used by the PatchBasedDenoisingBaseImageFilter class.
Definition: itkPatchBasedDenoisingBaseImageFilter.h:39
itk::PatchBasedDenoisingBaseImageFilter::PostProcessOutput
virtual void PostProcessOutput()
Definition: itkPatchBasedDenoisingBaseImageFilter.h:373
itk::PatchBasedDenoisingBaseImageFilterEnums::NoiseModel
NoiseModel
Definition: itkPatchBasedDenoisingBaseImageFilter.h:46
itk::PatchBasedDenoisingBaseImageFilter::m_OutputImage
OutputImageType * m_OutputImage
Definition: itkPatchBasedDenoisingBaseImageFilter.h:422
itkImageToImageFilter.h
itk::PatchBasedDenoisingBaseImageFilter::m_PatchWeights
PatchWeightsType m_PatchWeights
Definition: itkPatchBasedDenoisingBaseImageFilter.h:427
itk::PatchBasedDenoisingBaseImageFilter::Initialize
virtual void Initialize()
Definition: itkPatchBasedDenoisingBaseImageFilter.h:346
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itkArray.h
itk::PatchBasedDenoisingBaseImageFilter::DetermineComponentSpace
ComponentSpaceEnum DetermineComponentSpace(const DiffusionTensor3D< PixelValueType > &)
Definition: itkPatchBasedDenoisingBaseImageFilter.h:402
itk::RGBAPixel
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
itk::GPUFiniteDifferenceFilterEnum::INITIALIZED
itk::PatchBasedDenoisingBaseImageFilter::ListAdaptorType
typename ::itk::Statistics::ImageToNeighborhoodSampleAdaptor< OutputImageType, BoundaryConditionType > ListAdaptorType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:204
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::PatchBasedDenoisingBaseImageFilter::InitializeIteration
virtual void InitializeIteration()
Definition: itkPatchBasedDenoisingBaseImageFilter.h:358
itkSample.h
itk::ConstNeighborhoodIterator
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
Definition: itkConstNeighborhoodIterator.h:51
itk::PatchBasedDenoisingBaseImageFilterEnums::ComponentSpace::EUCLIDEAN
itk::PatchBasedDenoisingBaseImageFilter::PixelType
OutputPixelType PixelType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:171
itk::PatchBasedDenoisingBaseImageFilter::DetermineComponentSpace
ComponentSpaceEnum DetermineComponentSpace(const PixelT &)
Definition: itkPatchBasedDenoisingBaseImageFilter.h:409
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:138
itk::PatchBasedDenoisingBaseImageFilter::m_InputImage
const InputImageType * m_InputImage
Definition: itkPatchBasedDenoisingBaseImageFilter.h:416
itk::Array< float >
itkNumericTraits.h
itk::PatchBasedDenoisingBaseImageFilter::PixelValueType
typename NumericTraits< PixelType >::ValueType PixelValueType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:172
itk::PatchBasedDenoisingBaseImageFilterEnums::NoiseModel::POISSON
itk::GPUFiniteDifferenceFilterEnum::UNINITIALIZED
itk::ZeroFluxNeumannBoundaryCondition
A function object that determines a neighborhood of values at an image boundary according to a Neuman...
Definition: itkZeroFluxNeumannBoundaryCondition.h:58
itkImageToNeighborhoodSampleAdaptor.h
itk::PatchBasedDenoisingBaseImageFilter::InputImageType
TInputImage InputImageType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:160
itk::PatchBasedDenoisingBaseImageFilter
Base class for patch-based denoising algorithms.
Definition: itkPatchBasedDenoisingBaseImageFilter.h:145
itk::PatchBasedDenoisingBaseImageFilterEnums::NoiseModel::GAUSSIAN
itkZeroFluxNeumannBoundaryCondition.h
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::PatchBasedDenoisingBaseImageFilterEnums::FilterState::UNINITIALIZED
itk::PatchBasedDenoisingBaseImageFilter::OutputPixelType
typename OutputImageType::PixelType OutputPixelType
Definition: itkPatchBasedDenoisingBaseImageFilter.h:170