ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkWienerDeconvolutionImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkWienerDeconvolutionImageFilter_h
00019 #define __itkWienerDeconvolutionImageFilter_h
00020 
00021 #include "itkInverseDeconvolutionImageFilter.h"
00022 
00023 namespace itk
00024 {
00074 template< class TInputImage, class TKernelImage = TInputImage, class TOutputImage = TInputImage, class TInternalPrecision=double >
00075 class ITK_EXPORT WienerDeconvolutionImageFilter :
00076   public InverseDeconvolutionImageFilter< TInputImage, TKernelImage, TOutputImage >
00077 {
00078 public:
00079   typedef WienerDeconvolutionImageFilter                         Self;
00080   typedef FFTConvolutionImageFilter< TInputImage, TOutputImage > Superclass;
00081   typedef SmartPointer< Self >                                   Pointer;
00082   typedef SmartPointer< const Self >                             ConstPointer;
00083 
00085   itkNewMacro(Self);
00086 
00088   itkTypeMacro(WienerDeconvolutionImageFilter, InverseDeconvolutionImageFilter);
00089 
00091   itkStaticConstMacro(ImageDimension, unsigned int,
00092                       TInputImage::ImageDimension);
00093 
00094   typedef TInputImage                           InputImageType;
00095   typedef TOutputImage                          OutputImageType;
00096   typedef TKernelImage                          KernelImageType;
00097   typedef typename Superclass::InputPixelType   InputPixelType;
00098   typedef typename Superclass::OutputPixelType  OutputPixelType;
00099   typedef typename Superclass::KernelPixelType  KernelPixelType;
00100   typedef typename Superclass::InputIndexType   InputIndexType;
00101   typedef typename Superclass::OutputIndexType  OutputIndexType;
00102   typedef typename Superclass::KernelIndexType  KernelIndexType;
00103   typedef typename Superclass::InputSizeType    InputSizeType;
00104   typedef typename Superclass::OutputSizeType   OutputSizeType;
00105   typedef typename Superclass::KernelSizeType   KernelSizeType;
00106   typedef typename Superclass::SizeValueType    SizeValueType;
00107   typedef typename Superclass::InputRegionType  InputRegionType;
00108   typedef typename Superclass::OutputRegionType OutputRegionType;
00109   typedef typename Superclass::KernelRegionType KernelRegionType;
00110 
00112   typedef typename Superclass::InternalImageType               InternalImageType;
00113   typedef typename Superclass::InternalImagePointerType        InternalImagePointerType;
00114   typedef typename Superclass::InternalComplexType             InternalComplexType;
00115   typedef typename Superclass::InternalComplexImageType        InternalComplexImageType;
00116   typedef typename Superclass::InternalComplexImagePointerType InternalComplexImagePointerType;
00117 
00120   itkSetMacro(NoiseVariance, double);
00121   itkGetConstMacro(NoiseVariance, double);
00123 
00124 protected:
00125   WienerDeconvolutionImageFilter();
00126   ~WienerDeconvolutionImageFilter() {}
00127 
00129   void GenerateData();
00130 
00131   virtual void PrintSelf( std::ostream & os, Indent indent ) const;
00132 
00133 private:
00134   WienerDeconvolutionImageFilter(const Self &); //purposely not implemented
00135   void operator=(const Self &);                 //purposely not implemented
00136 
00137   double m_NoiseVariance;
00138 };
00139 
00140 namespace Functor
00141 {
00142 template< class TPixel >
00143 class WienerDeconvolutionFunctor
00144 {
00145 public:
00146   WienerDeconvolutionFunctor() { m_KernelZeroMagnitudeThreshold = 0.0; }
00147   ~WienerDeconvolutionFunctor() {}
00148 
00149   bool operator!=( const WienerDeconvolutionFunctor & ) const
00150   {
00151     return false;
00152   }
00153   bool operator==( const WienerDeconvolutionFunctor & other) const
00154   {
00155     return !(*this != other);
00156   }
00157   inline TPixel operator()(const TPixel & I, const TPixel & H) const
00158   {
00159     TPixel Pn = m_NoisePowerSpectralDensityConstant;
00160 
00161     // We estimate the power spectral density of the output image to
00162     // be the same as the power spectral density of the blurred input
00163     // minus the power spectral density of the noise.
00164     TPixel Pf = std::norm( I );
00165 
00166     TPixel denominator = std::norm( H ) + ( Pn / (Pf - Pn) );
00167     TPixel value = NumericTraits< TPixel >::ZeroValue();
00168     if ( std::abs( denominator ) >= m_KernelZeroMagnitudeThreshold )
00169       {
00170       value = I * ( std::conj( H ) / denominator );
00171       }
00172 
00173     return value;
00174   }
00175 
00178   void SetNoisePowerSpectralDensityConstant(double constant)
00179   {
00180     m_NoisePowerSpectralDensityConstant = constant;
00181   }
00182   double GetNoisePowerSpectralDensityConstant() const
00183   {
00184     return m_NoisePowerSpectralDensityConstant;
00185   }
00187 
00190   void SetKernelZeroMagnitudeThreshold(double mu)
00191   {
00192     m_KernelZeroMagnitudeThreshold = mu;
00193   }
00194   double GetKernelZeroMagnitudeThreshold() const
00195   {
00196     return m_KernelZeroMagnitudeThreshold;
00197   }
00199 
00200 private:
00201   double m_NoisePowerSpectralDensityConstant;
00202   double m_KernelZeroMagnitudeThreshold;
00203 };
00204 } //namespace Functor
00205 
00206 }
00207 
00208 #ifndef ITK_MANUAL_INSTANTIATION
00209 #include "itkWienerDeconvolutionImageFilter.hxx"
00210 #endif
00211 
00212 #endif
00213