ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkPatchBasedDenoisingBaseImageFilter.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 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 
32 namespace itk
33 {
34 
93 template <typename TInputImage, typename TOutputImage>
94 class ITK_TEMPLATE_EXPORT PatchBasedDenoisingBaseImageFilter :
95  public ImageToImageFilter<TInputImage, TOutputImage>
96 {
97 public:
98  ITK_DISALLOW_COPY_AND_ASSIGN(PatchBasedDenoisingBaseImageFilter);
99 
105 
108 
110  using InputImageType = TInputImage;
111  using OutputImageType = TOutputImage;
112 
114  static constexpr unsigned int ImageDimension = InputImageType::ImageDimension;
115 
119  using InputPixelType = typename InputImageType::PixelType;
120  using OutputPixelType = typename OutputImageType::PixelType;
123 
125  typedef enum { NOMODEL = 0, GAUSSIAN = 1, RICIAN = 2, POISSON = 3 } NoiseModelType;
126 
131  typedef enum { EUCLIDEAN = 0, RIEMANNIAN = 1 } ComponentSpaceType;
132 
134  typedef enum { UNINITIALIZED = 0, INITIALIZED = 1 } FilterStateType;
135 
140 
145  using ListAdaptorType = typename::itk::Statistics::ImageToNeighborhoodSampleAdaptor<
147  using PatchRadiusType = typename ListAdaptorType::NeighborhoodRadiusType;
150 
156  itkSetMacro(PatchRadius, unsigned int);
157  itkGetConstMacro(PatchRadius, unsigned int);
159 
160  PatchRadiusType GetPatchRadiusInVoxels() const;
161 
162  PatchRadiusType GetPatchDiameterInVoxels() const;
163 
164  typename PatchRadiusType::SizeValueType GetPatchLengthInVoxels() const;
165 
170  void SetPatchWeights(const PatchWeightsType& weights);
171 
172  PatchWeightsType GetPatchWeights() const;
173 
178  itkSetMacro(NoiseModel, NoiseModelType);
179  itkGetConstMacro(NoiseModel, NoiseModelType);
181 
187  itkSetClampMacro(SmoothingWeight, double, 0.0, 1.0);
188  itkGetConstMacro(SmoothingWeight, double);
190 
196  itkSetClampMacro(NoiseModelFidelityWeight, double, 0.0, 1.0);
197  itkGetConstMacro(NoiseModelFidelityWeight, double);
199 
204  itkSetMacro(KernelBandwidthEstimation, bool);
205  itkBooleanMacro(KernelBandwidthEstimation);
206  itkGetConstMacro(KernelBandwidthEstimation, bool);
208 
215  itkSetClampMacro(KernelBandwidthUpdateFrequency, unsigned int, 1, NumericTraits<unsigned int>::max() );
216  itkGetConstMacro(KernelBandwidthUpdateFrequency, unsigned int);
218 
223  itkSetClampMacro(NumberOfIterations, unsigned int, 1, NumericTraits<unsigned int>::max() );
224  itkGetConstReferenceMacro(NumberOfIterations, unsigned int);
226 
228  itkGetConstReferenceMacro(ElapsedIterations, unsigned int);
229 
234  itkSetMacro(AlwaysTreatComponentsAsEuclidean, bool);
235  itkBooleanMacro(AlwaysTreatComponentsAsEuclidean);
236  itkGetConstMacro(AlwaysTreatComponentsAsEuclidean, bool);
238 
240  virtual void SetStateToInitialized();
241 
243  virtual void SetStateToUninitialized();
244 
246 #if !defined(ITK_WRAPPING_PARSER)
247  itkSetMacro(State, FilterStateType);
248  itkGetConstReferenceMacro(State, FilterStateType);
249 #endif
250 
251 
256  itkSetMacro(ManualReinitialization, bool);
257  itkGetConstReferenceMacro(ManualReinitialization, bool);
258  itkBooleanMacro(ManualReinitialization);
260 
261 protected:
263  ~PatchBasedDenoisingBaseImageFilter() override = default;
264 
265  void PrintSelf(std::ostream& os, Indent indent) const override;
266 
267  void GenerateInputRequestedRegion() override;
268 
269  void GenerateData() override;
270 
271  virtual void CopyInputToOutput() = 0;
272 
274  virtual void InitializePatchWeights();
275 
276  virtual void Initialize() { }
277 
279  virtual void AllocateUpdateBuffer() = 0;
280 
281  virtual void PreProcessInput() { }
282 
283  virtual void InitializeIteration() { }
284 
286  virtual void ComputeKernelBandwidthUpdate() = 0;
287 
289  virtual void ComputeImageUpdate() = 0;
290 
291  virtual void ApplyUpdate() = 0;
292 
293  virtual void PostProcessOutput() { }
294 
296  virtual bool Halt();
297 
298  virtual bool ThreadedHalt(void *itkNotUsed(threadInfo) )
299  {
300  return this->Halt();
301  }
302 
303  itkSetMacro(ElapsedIterations, unsigned int);
304 
307  {
308  return EUCLIDEAN;
309  }
310 
312  {
313  return EUCLIDEAN;
314  }
315 
317  {
318  return RIEMANNIAN;
319  }
320 
321  template <typename PixelT>
322  ComponentSpaceType DetermineComponentSpace(const PixelT& itkNotUsed(p) )
323  {
324  return EUCLIDEAN;
325  }
326 
328  itkSetMacro(ComponentSpace, ComponentSpaceType);
329  itkGetConstMacro(ComponentSpace, ComponentSpaceType);
331 
332  // Cache input and output pointer to get rid of thousands of calls
333  // to GetInput and GetOutput.
336 
337 private:
339  unsigned int m_PatchRadius{ 4 };
341 
343  bool m_KernelBandwidthEstimation{ false };
344  unsigned int m_KernelBandwidthUpdateFrequency{ 3 };
345 
348  unsigned int m_NumberOfIterations{ 1 };
349  unsigned int m_ElapsedIterations{ 0 };
350 
353  double m_SmoothingWeight{ 1.0 };
354  double m_NoiseModelFidelityWeight{ 0.0 };
355 
358  bool m_AlwaysTreatComponentsAsEuclidean{ false };
360 
361  bool m_ManualReinitialization{ false };
362 
364 };
365 } // end namespace itk
366 
367 #ifndef ITK_MANUAL_INSTANTIATION
368 #include "itkPatchBasedDenoisingBaseImageFilter.hxx"
369 #endif
370 
371 #endif
A function object that determines a neighborhood of values at an image boundary according to a Neuman...
Define numeric traits for std::vector.
Represent Red, Green, Blue and Alpha components for color images.
Definition: itkRGBAPixel.h:59
Base class for patch-based denoising algorithms.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
typename::itk::Statistics::ImageToNeighborhoodSampleAdaptor< OutputImageType, BoundaryConditionType > ListAdaptorType
typename NumericTraits< PixelType >::ValueType PixelValueType
ComponentSpaceType DetermineComponentSpace(const RGBAPixel< PixelValueType > &)
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
ComponentSpaceType DetermineComponentSpace(const RGBPixel< PixelValueType > &)
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
typename ListAdaptorType::NeighborhoodRadiusType PatchRadiusType
Represent a diffusion tensor as used in DTI images.
ComponentSpaceType DetermineComponentSpace(const DiffusionTensor3D< PixelValueType > &)