ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkN4BiasFieldCorrectionImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 itkN4BiasFieldCorrectionImageFilter_h
19 #define itkN4BiasFieldCorrectionImageFilter_h
20 
21 #include "itkImageToImageFilter.h"
22 
23 #include "itkArray.h"
25 #include "itkPointSet.h"
26 #include "itkVector.h"
27 
28 #include "vnl/vnl_vector.h"
29 
30 namespace itk {
31 
90 template<typename TInputImage, typename TMaskImage =
91  Image<unsigned char, TInputImage::ImageDimension>,
92  class TOutputImage = TInputImage>
94  public ImageToImageFilter<TInputImage, TOutputImage>
95 {
96 public:
102 
105 
107  itkNewMacro( Self );
108 
110  itkStaticConstMacro( ImageDimension, unsigned int,
111  TInputImage::ImageDimension );
112 
114  typedef TInputImage InputImageType;
115  typedef TOutputImage OutputImageType;
116  typedef TMaskImage MaskImageType;
117  typedef typename MaskImageType::PixelType MaskPixelType;
118 
119  typedef float RealType;
123 
131 
137 
141  void SetInput1( const InputImageType *image ) { this->SetInput( image ); }
142 
143 
149  void SetMaskImage( const MaskImageType *mask )
150  {
151  this->SetNthInput( 1, const_cast<MaskImageType *>( mask ) );
152  }
153  void SetInput2( const MaskImageType *mask ) { this->SetMaskImage( mask ); }
155 
162  {
163  return static_cast<const MaskImageType*>( this->ProcessObject::GetInput( 1 ) );
164  }
165 
176  void SetConfidenceImage( const RealImageType *image )
177  {
178  this->SetNthInput( 2, const_cast<RealImageType *>( image ) );
179  }
180  void SetInput3( const RealImageType *image ) { this->SetConfidenceImage( image ); }
182 
194  {
195  return static_cast<const RealImageType*>( this->ProcessObject::GetInput( 2 ) );
196  }
197 
203  itkSetMacro( MaskLabel, MaskPixelType );
204 
210  itkGetConstMacro( MaskLabel, MaskPixelType );
211 
212  // Sharpen histogram parameters: in estimating the bias field, the
213  // first step is to sharpen the intensity histogram by Wiener deconvolution
214  // with a 1-D Gaussian. The following parameters define this operation.
215  // These default values in N4 match the default values in N3.
216 
221  itkSetMacro( NumberOfHistogramBins, unsigned int );
222 
227  itkGetConstMacro( NumberOfHistogramBins, unsigned int );
228 
232  itkSetMacro( WienerFilterNoise, RealType );
233 
237  itkGetConstMacro( WienerFilterNoise, RealType );
238 
243  itkSetMacro( BiasFieldFullWidthAtHalfMaximum, RealType );
244 
249  itkGetConstMacro( BiasFieldFullWidthAtHalfMaximum, RealType );
250 
251  // B-spline parameters governing the fitting routine
252 
256  itkSetMacro( SplineOrder, unsigned int );
257 
261  itkGetConstMacro( SplineOrder, unsigned int );
262 
270  itkSetMacro( NumberOfControlPoints, ArrayType );
271 
279  itkGetConstMacro( NumberOfControlPoints, ArrayType );
280 
287  itkSetMacro( NumberOfFittingLevels, ArrayType );
288 
295  void SetNumberOfFittingLevels( unsigned int n )
296  {
297  ArrayType nlevels;
298 
299  nlevels.Fill( n );
300  this->SetNumberOfFittingLevels( nlevels );
301  }
302 
309  itkGetConstMacro( NumberOfFittingLevels, ArrayType );
310 
315  itkSetMacro( MaximumNumberOfIterations, VariableSizeArrayType );
316 
321  itkGetConstMacro( MaximumNumberOfIterations, VariableSizeArrayType );
322 
330  itkSetMacro( ConvergenceThreshold, RealType );
331 
339  itkGetConstMacro( ConvergenceThreshold, RealType );
340 
350  itkGetConstMacro( LogBiasFieldControlPointLattice,
352 
357  itkGetConstMacro( ElapsedIterations, unsigned int );
358 
363  itkGetConstMacro( CurrentConvergenceMeasurement, RealType );
364 
369  itkGetConstMacro( CurrentLevel, unsigned int );
370 
371 protected:
374  void PrintSelf( std::ostream& os, Indent indent ) const ITK_OVERRIDE;
375 
376  void GenerateData() ITK_OVERRIDE;
377 
378 private:
379  N4BiasFieldCorrectionImageFilter( const Self& ) ITK_DELETE_FUNCTION;
380  void operator=( const Self& ) ITK_DELETE_FUNCTION;
381 
382  // N4 algorithm functions: The basic algorithm iterates between sharpening
383  // the intensity histogram of the corrected input image and spatially
384  // smoothing those results with a B-spline scalar field estimate of the
385  // bias field. The former is handled by the function SharpenImage()
386  // whereas the latter is handled by the function UpdateBiasFieldEstimate().
387  // Convergence is determined by the coefficient of variation of the difference
388  // image between the current bias field estimate and the previous estimate.
389 
396 
403 
408 
413  RealType CalculateConvergenceMeasurement( const RealImageType *, const RealImageType * ) const;
414 
416 
417  // Parameters for deconvolution with Wiener filter
418 
422 
423  // Convergence parameters
424 
426  unsigned int m_ElapsedIterations;
429  unsigned int m_CurrentLevel;
430 
431  // B-spline fitting parameters
432 
433  typename
434  BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice;
435 
436  unsigned int m_SplineOrder;
439 
440 };
441 
442 } // end namespace itk
443 
444 #ifndef ITK_MANUAL_INSTANTIATION
445 #include "itkN4BiasFieldCorrectionImageFilter.hxx"
446 #endif
447 
448 #endif
void PrintSelf(std::ostream &os, Indent indent) const override
PointSet< ScalarType, itkGetStaticConstMacro(ImageDimension)> PointSetType
SmartPointer< Self > Pointer
Definition: itkImage.h:81
Image< ScalarType, itkGetStaticConstMacro(ImageDimension)> ScalarImageType
Base class for all process objects that output image data.
void Fill(const ValueType &)
RealImagePointer SharpenImage(const RealImageType *) const
ImageToImageFilter< TInputImage, TOutputImage > Superclass
RealImagePointer UpdateBiasFieldEstimate(RealImageType *)
virtual void SetInput(const InputImageType *image)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
BSplineScatteredDataPointSetToImageFilter< PointSetType, ScalarImageType > BSplineFilterType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
virtual void SetNumberOfFittingLevels(ArrayType _arg)
MeshTraits::PointType PointType
Definition: itkPointSet.h:106
Image filter which provides a B-spline output approximation.
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
BSplineFilterType::PointDataImageType BiasFieldControlPointLatticeType
RealImagePointer ReconstructBiasField(BiasFieldControlPointLatticeType *)
Base class for filters that take an image as input and produce an image as output.
RealType CalculateConvergenceMeasurement(const RealImageType *, const RealImageType *) const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void SetNthInput(DataObjectPointerArraySizeType num, DataObject *input)
BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice
Implementation of the N4 bias field correction algorithm.
Templated n-dimensional image class.
Definition: itkImage.h:75