ITK  5.0.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 
92 template<typename TInputImage, typename TMaskImage =
93  Image<unsigned char, TInputImage::ImageDimension>,
94  class TOutputImage = TInputImage>
96  public ImageToImageFilter<TInputImage, TOutputImage>
97 {
98 public:
99  ITK_DISALLOW_COPY_AND_ASSIGN(N4BiasFieldCorrectionImageFilter);
100 
106 
109 
111  itkNewMacro( Self );
112 
114  static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
115 
117  using InputImageType = TInputImage;
118  using OutputImageType = TOutputImage;
119  using MaskImageType = TMaskImage;
120  using MaskPixelType = typename MaskImageType::PixelType;
121 
122  using RealType = float;
126 
133 
139 
142 
146  void SetInput1( const InputImageType *image ) { this->SetInput( image ); }
147 
153  itkSetInputMacro(MaskImage, MaskImageType);
154  void SetInput2( const MaskImageType *mask ) { this->SetMaskImage( mask ); }
156 
162  itkGetInputMacro(MaskImage, MaskImageType);
163 
172  itkSetMacro( MaskLabel, MaskPixelType );
173  itkGetConstMacro( MaskLabel, MaskPixelType );
175 
179  itkSetMacro( UseMaskLabel, bool );
180  itkGetConstMacro( UseMaskLabel, bool );
181  itkBooleanMacro( UseMaskLabel );
183 
194  itkSetInputMacro(ConfidenceImage, RealImageType);
195  void SetInput3( const RealImageType *image ) { this->SetConfidenceImage( image ); }
197 
208  itkGetInputMacro(ConfidenceImage, RealImageType);
209 
210  // Sharpen histogram parameters: in estimating the bias field, the
211  // first step is to sharpen the intensity histogram by Wiener deconvolution
212  // with a 1-D Gaussian. The following parameters define this operation.
213  // These default values in N4 match the default values in N3.
214 
219  itkSetMacro( NumberOfHistogramBins, unsigned int );
220 
225  itkGetConstMacro( NumberOfHistogramBins, unsigned int );
226 
230  itkSetMacro( WienerFilterNoise, RealType );
231 
235  itkGetConstMacro( WienerFilterNoise, RealType );
236 
241  itkSetMacro( BiasFieldFullWidthAtHalfMaximum, RealType );
242 
247  itkGetConstMacro( BiasFieldFullWidthAtHalfMaximum, RealType );
248 
249  // B-spline parameters governing the fitting routine
250 
254  itkSetMacro( SplineOrder, unsigned int );
255 
259  itkGetConstMacro( SplineOrder, unsigned int );
260 
268  itkSetMacro( NumberOfControlPoints, ArrayType );
269 
277  itkGetConstMacro( NumberOfControlPoints, ArrayType );
278 
285  itkSetMacro( NumberOfFittingLevels, ArrayType );
286 
293  void SetNumberOfFittingLevels( unsigned int n )
294  {
295  ArrayType nlevels;
296 
297  nlevels.Fill( n );
298  this->SetNumberOfFittingLevels( nlevels );
299  }
300 
307  itkGetConstMacro( NumberOfFittingLevels, ArrayType );
308 
313  itkSetMacro( MaximumNumberOfIterations, VariableSizeArrayType );
314 
319  itkGetConstMacro( MaximumNumberOfIterations, VariableSizeArrayType );
320 
328  itkSetMacro( ConvergenceThreshold, RealType );
329 
337  itkGetConstMacro( ConvergenceThreshold, RealType );
338 
348  itkGetConstObjectMacro( LogBiasFieldControlPointLattice, BiasFieldControlPointLatticeType );
349 
354  itkGetConstMacro( ElapsedIterations, unsigned int );
355 
360  itkGetConstMacro( CurrentConvergenceMeasurement, RealType );
361 
366  itkGetConstMacro( CurrentLevel, unsigned int );
367 
368 protected:
370  ~N4BiasFieldCorrectionImageFilter() override = default;
371  void PrintSelf( std::ostream& os, Indent indent ) const override;
372 
373  void GenerateData() override;
374 
375 private:
376  // N4 algorithm functions: The basic algorithm iterates between sharpening
377  // the intensity histogram of the corrected input image and spatially
378  // smoothing those results with a B-spline scalar field estimate of the
379  // bias field. The former is handled by the function SharpenImage()
380  // whereas the latter is handled by the function UpdateBiasFieldEstimate().
381  // Convergence is determined by the coefficient of variation of the difference
382  // image between the current bias field estimate and the previous estimate.
383 
390 
397 
402 
408 
410  bool m_UseMaskLabel{ false };
411 
412  // Parameters for deconvolution with Wiener filter
413 
414  unsigned int m_NumberOfHistogramBins{ 200 };
415  RealType m_WienerFilterNoise{ static_cast< RealType >( 0.01 ) };
417 
418  // Convergence parameters
419 
421  unsigned int m_ElapsedIterations{ 0 };
422  RealType m_ConvergenceThreshold{ static_cast< RealType >( 0.001 ) };
424  unsigned int m_CurrentLevel{ 0 };
425 
426  // B-spline fitting parameters
427 
428  typename
429  BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice;
430 
431  unsigned int m_SplineOrder{ 3 };
434 
435 };
436 
437 } // end namespace itk
438 
439 #ifndef ITK_MANUAL_INSTANTIATION
440 #include "itkN4BiasFieldCorrectionImageFilter.hxx"
441 #endif
442 
443 #endif
void PrintSelf(std::ostream &os, Indent indent) const override
SmartPointer< Self > Pointer
Definition: itkPointSet.h:92
RealImagePointer UpdateBiasFieldEstimate(RealImageType *, std::vcl_size_t)
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
void EnlargeOutputRequestedRegion(DataObject *) override
typename BSplineFilterType::PointDataImageType BiasFieldControlPointLatticeType
Base class for all process objects that output image data.
~N4BiasFieldCorrectionImageFilter() override=default
RealImagePointer SharpenImage(const RealImageType *) const
typename MeshTraits::PointType PointType
Definition: itkPointSet.h:108
virtual void SetInput(const InputImageType *image)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
TOutputImage OutputImageType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:84
virtual void SetNumberOfFittingLevels(ArrayType _arg)
Image filter which provides a B-spline output approximation.
virtual void SetConfidenceImage(const RealImageType *input)
PointSet< ScalarType, Self::ImageDimension > PointSetType
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
SmartPointer< Self > Pointer
Definition: itkImage.h:83
BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice
virtual void SetMaskImage(const MaskImageType *input)
Base class for all data objects in ITK.
Implementation of the N4 bias field correction algorithm.
Templated n-dimensional image class.
Definition: itkImage.h:75