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
24namespace itk
25{
76template <typename TInputImage,
77 typename TKernelImage = TInputImage,
78 typename TOutputImage = TInputImage,
79 typename TInternalPrecision = double>
80class ITK_TEMPLATE_EXPORT WienerDeconvolutionImageFilter
81 : public InverseDeconvolutionImageFilter<TInputImage, TKernelImage, TOutputImage, TInternalPrecision>
82{
83public:
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);
131protected:
134
136 void
137 GenerateData() override;
138
139 void
140 PrintSelf(std::ostream & os, Indent indent) const override;
141
142private:
143 double m_NoiseVariance{};
144};
145
146namespace Functor
147{
148template <typename TPixel>
149class ITK_TEMPLATE_EXPORT WienerDeconvolutionFunctor
150{
151public:
155 : m_NoisePowerSpectralDensityConstant(f.m_NoisePowerSpectralDensityConstant)
156 , m_KernelZeroMagnitudeThreshold(f.m_KernelZeroMagnitudeThreshold)
157 {}
158
159 bool
161 {
162 return true;
163 }
164
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 }
215private:
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
bool operator==(const WienerDeconvolutionFunctor &) const
WienerDeconvolutionFunctor(const WienerDeconvolutionFunctor &f)
TPixel operator()(const TPixel &I, const TPixel &H) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(WienerDeconvolutionFunctor)
Control indentation during Print() invocation.
Definition: itkIndent.h:50
The direct linear inverse deconvolution filter.
Light weight base class for most itk classes.
The Wiener deconvolution image filter is designed to restore an image convolved with a blurring kerne...
~WienerDeconvolutionImageFilter() override=default
void PrintSelf(std::ostream &os, Indent indent) const override
bool abs(bool x)
Definition: itkMath.h:844
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86