itkN4MRIBiasFieldCorrectionImageFilter.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 __itkN4MRIBiasFieldCorrectionImageFilter_h
00019 #define __itkN4MRIBiasFieldCorrectionImageFilter_h
00020 
00021 #include "itkImageToImageFilter.h"
00022 
00023 #include "itkArray.h"
00024 #include "itkBSplineScatteredDataPointSetToImageFilter.h"
00025 #include "itkPointSet.h"
00026 #include "itkVector.h"
00027 
00028 #include "vnl/vnl_vector.h"
00029 
00030 namespace itk {
00031 
00089 template<class TInputImage, class TMaskImage =
00090   Image<unsigned char, ::itk::GetImageDimension<TInputImage>::ImageDimension>,
00091   class TOutputImage = TInputImage>
00092 class ITK_EXPORT N4MRIBiasFieldCorrectionImageFilter :
00093   public ImageToImageFilter<TInputImage, TOutputImage>
00094 {
00095 public:
00097   typedef N4MRIBiasFieldCorrectionImageFilter           Self;
00098   typedef ImageToImageFilter<TInputImage, TOutputImage> Superclass;
00099   typedef SmartPointer<Self>                            Pointer;
00100   typedef SmartPointer<const Self>                      ConstPointer;
00101 
00103   itkTypeMacro( N4MRIBiasFieldCorrectionImageFilter, ImageToImageFilter );
00104 
00106   itkNewMacro( Self );
00107 
00109   itkStaticConstMacro( ImageDimension, unsigned int,
00110                        TInputImage::ImageDimension );
00111 
00113   typedef TInputImage                       InputImageType;
00114   typedef TOutputImage                      OutputImageType;
00115   typedef TMaskImage                        MaskImageType;
00116   typedef typename MaskImageType::PixelType MaskPixelType;
00117 
00118   typedef float                           RealType;
00119   typedef Image<RealType, ImageDimension> RealImageType;
00120   typedef typename RealImageType::Pointer RealImagePointer;
00121   typedef Array<unsigned int>             VariableSizeArrayType;
00122 
00124   typedef Vector<RealType, 1>                                             ScalarType;
00125   typedef PointSet<ScalarType, itkGetStaticConstMacro( ImageDimension )>  PointSetType;
00126   typedef Image<ScalarType, itkGetStaticConstMacro( ImageDimension )>     ScalarImageType;
00127   typedef typename PointSetType::Pointer                                  PointSetPointer;
00128   typedef typename PointSetType::PointType                                PointType;
00129 
00131   typedef BSplineScatteredDataPointSetToImageFilter<
00132     PointSetType, ScalarImageType>                          BSplineFilterType;
00133   typedef typename BSplineFilterType::PointDataImageType    BiasFieldControlPointLatticeType;
00134   typedef typename BSplineFilterType::ArrayType             ArrayType;
00135 
00141   void SetMaskImage( const MaskImageType *mask )
00142     {
00143     this->SetNthInput( 1, const_cast<MaskImageType *>( mask ) );
00144     }
00145 
00151   const MaskImageType* GetMaskImage() const
00152     {
00153     return static_cast<const MaskImageType*>( this->ProcessObject::GetInput( 1 ) );
00154     }
00155 
00166   void SetConfidenceImage( const RealImageType *image )
00167     {
00168     this->SetNthInput( 2, const_cast<RealImageType *>( image ) );
00169     }
00170 
00181   const RealImageType* GetConfidenceImage() const
00182     {
00183     return static_cast<const RealImageType*>( this->ProcessObject::GetInput( 2 ) );
00184     }
00185 
00191   itkSetMacro( MaskLabel, MaskPixelType );
00192 
00198   itkGetConstMacro( MaskLabel, MaskPixelType );
00199 
00200   // Sharpen histogram parameters: in estimating the bias field, the
00201   // first step is to sharpen the intensity histogram by Wiener deconvolution
00202   // with a 1-D Gaussian.  The following parameters define this operation.
00203   // These default values in N4 match the default values in N3.
00204 
00209   itkSetMacro( NumberOfHistogramBins, unsigned int );
00210 
00215   itkGetConstMacro( NumberOfHistogramBins, unsigned int );
00216 
00220   itkSetMacro( WienerFilterNoise, RealType );
00221 
00225   itkGetConstMacro( WienerFilterNoise, RealType );
00226 
00231   itkSetMacro( BiasFieldFullWidthAtHalfMaximum, RealType );
00232 
00237   itkGetConstMacro( BiasFieldFullWidthAtHalfMaximum, RealType );
00238 
00239   // B-spline parameters governing the fitting routine
00240 
00244   itkSetMacro( SplineOrder, unsigned int );
00245 
00249   itkGetConstMacro( SplineOrder, unsigned int );
00250 
00258   itkSetMacro( NumberOfControlPoints, ArrayType );
00259 
00267   itkGetConstMacro( NumberOfControlPoints, ArrayType );
00268 
00275   itkSetMacro( NumberOfFittingLevels, ArrayType );
00276 
00283   void SetNumberOfFittingLevels( unsigned int n )
00284     {
00285     ArrayType nlevels;
00286 
00287     nlevels.Fill( n );
00288     this->SetNumberOfFittingLevels( nlevels );
00289     }
00290 
00297   itkGetConstMacro( NumberOfFittingLevels, ArrayType );
00298 
00303   itkSetMacro( MaximumNumberOfIterations, VariableSizeArrayType );
00304 
00309   itkGetConstMacro( MaximumNumberOfIterations, VariableSizeArrayType );
00310 
00318   itkSetMacro( ConvergenceThreshold, RealType );
00319 
00327   itkGetConstMacro( ConvergenceThreshold, RealType );
00328 
00338   itkGetConstMacro( LogBiasFieldControlPointLattice,
00339                     typename BiasFieldControlPointLatticeType::Pointer );
00340 
00345   itkGetConstMacro( ElapsedIterations, unsigned int );
00346 
00351   itkGetConstMacro( CurrentConvergenceMeasurement, RealType );
00352 
00357   itkGetConstMacro( CurrentLevel, unsigned int );
00358 
00359 protected:
00360   N4MRIBiasFieldCorrectionImageFilter();
00361   ~N4MRIBiasFieldCorrectionImageFilter() {}
00362   void PrintSelf( std::ostream& os, Indent indent ) const;
00363 
00364   void GenerateData();
00365 
00366 private:
00367   N4MRIBiasFieldCorrectionImageFilter( const Self& ); //purposely not
00368                                                       // implemented
00369   void operator=( const Self& );                      //purposely not
00370                                                       // implemented
00371 
00372   // N4 algorithm functions:  The basic algorithm iterates between sharpening
00373   // the intensity histogram of the corrected input image and spatially
00374   // smoothing those results with a B-spline scalar field estimate of the
00375   // bias field.  The former is handled by the function SharpenImage()
00376   // whereas the latter is handled by the function UpdateBiasFieldEstimate().
00377   // Convergence is determined by the coefficient of variation of the difference
00378   // image between the current bias field estimate and the previous estimate.
00379 
00385   RealImagePointer SharpenImage( const RealImageType * ) const;
00386 
00392   RealImagePointer UpdateBiasFieldEstimate( RealImageType * );
00393 
00398   RealType CalculateConvergenceMeasurement( const RealImageType *, const RealImageType * ) const;
00399 
00400 
00401   MaskPixelType m_MaskLabel;
00402 
00403   // Parameters for deconvolution with Wiener filter
00404 
00405   unsigned int m_NumberOfHistogramBins;
00406   RealType     m_WienerFilterNoise;
00407   RealType     m_BiasFieldFullWidthAtHalfMaximum;
00408 
00409   // Convergence parameters
00410 
00411   VariableSizeArrayType m_MaximumNumberOfIterations;
00412   unsigned int          m_ElapsedIterations;
00413   RealType              m_ConvergenceThreshold;
00414   RealType              m_CurrentConvergenceMeasurement;
00415   unsigned int          m_CurrentLevel;
00416 
00417   // B-spline fitting parameters
00418 
00419   typename
00420   BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice;
00421 
00422   unsigned int m_SplineOrder;
00423   ArrayType    m_NumberOfControlPoints;
00424   ArrayType    m_NumberOfFittingLevels;
00425 
00426 };
00427 
00428 } // end namespace itk
00429 
00430 #ifndef ITK_MANUAL_INSTANTIATION
00431 #include "itkN4MRIBiasFieldCorrectionImageFilter.txx"
00432 #endif
00433 
00434 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1