ITK  6.0.0
Insight Toolkit
itkWienerDeconvolutionImageFilter.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 itkWienerDeconvolutionImageFilter_h
19 #define itkWienerDeconvolutionImageFilter_h
20 
22 #include "itkMath.h"
23 
24 namespace itk
25 {
76 template <typename TInputImage,
77  typename TKernelImage = TInputImage,
78  typename TOutputImage = TInputImage,
79  typename TInternalPrecision = double>
80 class ITK_TEMPLATE_EXPORT WienerDeconvolutionImageFilter
81  : public InverseDeconvolutionImageFilter<TInputImage, TKernelImage, TOutputImage, TInternalPrecision>
82 {
83 public:
84  ITK_DISALLOW_COPY_AND_MOVE(WienerDeconvolutionImageFilter);
91 
93  itkNewMacro(Self);
94 
96  itkOverrideGetNameOfClassMacro(WienerDeconvolutionImageFilter);
97 
99  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
100 
101  using InputImageType = TInputImage;
102  using OutputImageType = TOutputImage;
103  using KernelImageType = TKernelImage;
104  using typename Superclass::InputPixelType;
105  using typename Superclass::OutputPixelType;
106  using typename Superclass::KernelPixelType;
107  using typename Superclass::InputIndexType;
108  using typename Superclass::OutputIndexType;
109  using typename Superclass::KernelIndexType;
110  using typename Superclass::InputSizeType;
111  using typename Superclass::OutputSizeType;
112  using typename Superclass::KernelSizeType;
113  using typename Superclass::SizeValueType;
114  using typename Superclass::InputRegionType;
115  using typename Superclass::OutputRegionType;
116  using typename Superclass::KernelRegionType;
117 
119  using typename Superclass::InternalImageType;
120  using typename Superclass::InternalImagePointerType;
121  using typename Superclass::InternalComplexType;
122  using typename Superclass::InternalComplexImageType;
123  using typename Superclass::InternalComplexImagePointerType;
124 
127  itkSetMacro(NoiseVariance, double);
128  itkGetConstMacro(NoiseVariance, double);
131 protected:
133  ~WienerDeconvolutionImageFilter() override = default;
134 
136  void
137  GenerateData() override;
138 
139  void
140  PrintSelf(std::ostream & os, Indent indent) const override;
141 
142 private:
143  double m_NoiseVariance{};
144 };
145 
146 namespace Functor
147 {
148 template <typename TPixel>
149 class ITK_TEMPLATE_EXPORT WienerDeconvolutionFunctor
150 {
151 public:
152  WienerDeconvolutionFunctor() = default;
153  ~WienerDeconvolutionFunctor() = default;
155  : m_NoisePowerSpectralDensityConstant(f.m_NoisePowerSpectralDensityConstant)
156  , m_KernelZeroMagnitudeThreshold(f.m_KernelZeroMagnitudeThreshold)
157  {}
158 
159  bool
161  {
162  return true;
163  }
164 
165  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(WienerDeconvolutionFunctor);
166 
167  inline TPixel
168  operator()(const TPixel & I, const TPixel & H) const
169  {
170  TPixel Pn = m_NoisePowerSpectralDensityConstant;
171 
172  // We estimate the power spectral density of the output image to
173  // be the same as the power spectral density of the blurred input
174  // minus the power spectral density of the noise.
175  TPixel Pf = std::norm(I);
176 
177  TPixel denominator = std::norm(H) + (Pn / (Pf - Pn));
178  TPixel value{};
179  if (itk::Math::abs(denominator) >= m_KernelZeroMagnitudeThreshold)
180  {
181  value = I * (std::conj(H) / denominator);
182  }
183 
184  return value;
185  }
186 
189  void
191  {
192  m_NoisePowerSpectralDensityConstant = constant;
193  }
194  double
196  {
197  return m_NoisePowerSpectralDensityConstant;
198  }
203  void
205  {
206  m_KernelZeroMagnitudeThreshold = mu;
207  }
208  double
210  {
211  return m_KernelZeroMagnitudeThreshold;
212  }
215 private:
216  double m_NoisePowerSpectralDensityConstant = 0.0;
217  double m_KernelZeroMagnitudeThreshold = 0.0;
218 };
219 } // namespace Functor
220 
221 } // namespace itk
222 
223 #ifndef ITK_MANUAL_INSTANTIATION
224 # include "itkWienerDeconvolutionImageFilter.hxx"
225 #endif
226 
227 #endif
itkInverseDeconvolutionImageFilter.h
itk::Functor::WienerDeconvolutionFunctor
Definition: itkWienerDeconvolutionImageFilter.h:149
itk::ConvolutionImageFilterBase::KernelImageType
TKernelImage KernelImageType
Definition: itkConvolutionImageFilterBase.h:75
itk::Functor::WienerDeconvolutionFunctor::GetKernelZeroMagnitudeThreshold
double GetKernelZeroMagnitudeThreshold() const
Definition: itkWienerDeconvolutionImageFilter.h:209
itk::WienerDeconvolutionImageFilter
The Wiener deconvolution image filter is designed to restore an image convolved with a blurring kerne...
Definition: itkWienerDeconvolutionImageFilter.h:80
itk::Functor::WienerDeconvolutionFunctor::SetKernelZeroMagnitudeThreshold
void SetKernelZeroMagnitudeThreshold(double mu)
Definition: itkWienerDeconvolutionImageFilter.h:204
itk::Functor::WienerDeconvolutionFunctor::SetNoisePowerSpectralDensityConstant
void SetNoisePowerSpectralDensityConstant(double constant)
Definition: itkWienerDeconvolutionImageFilter.h:190
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Math::abs
bool abs(bool x)
Definition: itkMath.h:839
itk::ImageSource
Base class for all process objects that output image data.
Definition: itkImageSource.h:67
itk::Functor::WienerDeconvolutionFunctor::operator()
TPixel operator()(const TPixel &I, const TPixel &H) const
Definition: itkWienerDeconvolutionImageFilter.h:168
itk::InverseDeconvolutionImageFilter
The direct linear inverse deconvolution filter.
Definition: itkInverseDeconvolutionImageFilter.h:59
itk::Functor::WienerDeconvolutionFunctor::operator==
bool operator==(const WienerDeconvolutionFunctor &) const
Definition: itkWienerDeconvolutionImageFilter.h:160
itk::Functor::WienerDeconvolutionFunctor::WienerDeconvolutionFunctor
WienerDeconvolutionFunctor(const WienerDeconvolutionFunctor &f)
Definition: itkWienerDeconvolutionImageFilter.h:154
itk::ImageToImageFilter::InputImageType
TInputImage InputImageType
Definition: itkImageToImageFilter.h:129
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itkMath.h
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ImageSource::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSource.h:90
itk::Functor::WienerDeconvolutionFunctor::GetNoisePowerSpectralDensityConstant
double GetNoisePowerSpectralDensityConstant() const
Definition: itkWienerDeconvolutionImageFilter.h:195