ITK  5.3.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_MOVE(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 true;
162  }
163 
164  ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(WienerDeconvolutionFunctor);
165 
166  inline TPixel
167  operator()(const TPixel & I, const TPixel & H) const
168  {
169  TPixel Pn = m_NoisePowerSpectralDensityConstant;
170 
171  // We estimate the power spectral density of the output image to
172  // be the same as the power spectral density of the blurred input
173  // minus the power spectral density of the noise.
174  TPixel Pf = std::norm(I);
175 
176  TPixel denominator = std::norm(H) + (Pn / (Pf - Pn));
177  TPixel value = NumericTraits<TPixel>::ZeroValue();
178  if (std::abs(denominator) >= m_KernelZeroMagnitudeThreshold)
179  {
180  value = I * (std::conj(H) / denominator);
181  }
182 
183  return value;
184  }
185 
188  void
190  {
191  m_NoisePowerSpectralDensityConstant = constant;
192  }
193  double
195  {
196  return m_NoisePowerSpectralDensityConstant;
197  }
199 
202  void
204  {
205  m_KernelZeroMagnitudeThreshold = mu;
206  }
207  double
209  {
210  return m_KernelZeroMagnitudeThreshold;
211  }
213 
214 private:
215  double m_NoisePowerSpectralDensityConstant = 0.0;
216  double m_KernelZeroMagnitudeThreshold = 0.0;
217 };
218 } // namespace Functor
219 
220 } // namespace itk
221 
222 #ifndef ITK_MANUAL_INSTANTIATION
223 # include "itkWienerDeconvolutionImageFilter.hxx"
224 #endif
225 
226 #endif
itkInverseDeconvolutionImageFilter.h
itk::Functor::WienerDeconvolutionFunctor
Definition: itkWienerDeconvolutionImageFilter.h:148
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:208
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:203
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:189
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:167
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::operator==
bool operator==(const WienerDeconvolutionFunctor &) const
Definition: itkWienerDeconvolutionImageFilter.h:159
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:88
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:194
itk::ConvolutionImageFilterBase::KernelSizeType
typename KernelImageType::SizeType KernelSizeType
Definition: itkConvolutionImageFilterBase.h:85