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