ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkMRIBiasFieldCorrectionFilter.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 itkMRIBiasFieldCorrectionFilter_h
19 #define itkMRIBiasFieldCorrectionFilter_h
20 
21 #include <ctime>
22 
23 #include "itkImageToImageFilter.h"
24 #include "itkArray2D.h"
25 #include "itkMRASlabIdentifier.h"
30 #include "itkImageRegionIterator.h"
31 
32 namespace itk
33 {
46 template< typename TImage, typename TImageMask, typename TBiasField >
48 {
49 public:
55 
58 
60  itkNewMacro(Self);
61 
63  typedef TImage ImageType;
64  typedef typename ImageType::Pointer ImagePointer;
65  typedef typename ImageType::PixelType ImageElementType;
66  typedef typename ImageType::IndexType ImageIndexType;
67  typedef typename ImageType::RegionType ImageRegionType;
68  typedef TImageMask MaskType;
69  typedef typename MaskType::Pointer MaskPointer;
70  typedef typename MaskType::PixelType MaskElementType;
71 
73  typedef TBiasField BiasFieldType;
74 
78 
81 
84 
85  itkStaticConstMacro(SpaceDimension, unsigned int, 3);
86 
88  typedef CompositeValleyFunction InternalEnergyFunction;
89 
91  typedef unsigned int SamplingFactorType[SpaceDimension];
92 
94  itkSetObjectMacro(Image, ImageType);
95 
97  itkSetObjectMacro(Mask, MaskType);
98 
100  itkSetMacro(Region, ImageRegionType);
101 
104  { m_BiasField = bias; }
105 
109  {
110  for ( unsigned int i = 0; i < SpaceDimension; i++ )
111  {
112  m_SamplingFactor[i] = factor[i];
113  }
114  }
116 
119  double GetEnergy0(double diff)
120  {
121  return ( *m_InternalEnergyFunction )( diff );
122  }
123 
126  virtual MeasureType GetValue(const ParametersType & parameters) const ITK_OVERRIDE;
127 
130  void GetDerivative( const ParametersType & itkNotUsed(parameters),
131  DerivativeType & itkNotUsed(derivative) ) const ITK_OVERRIDE
132  {}
133 
139  Array< double > classSigmas);
140 
141  virtual unsigned int GetNumberOfParameters(void) const ITK_OVERRIDE;
142 
143 protected:
146 
148  virtual ~MRIBiasEnergyFunction();
149 
150 private:
151 
154 
157 
160 
163 
166 
169 
170  MRIBiasEnergyFunction(const Self &) ITK_DELETE_FUNCTION;
171  void operator=(const Self &) ITK_DELETE_FUNCTION;
172 }; // end of class
173 
224 template< typename TInputImage, typename TOutputImage, typename TMaskImage >
226  public ImageToImageFilter< TInputImage, TOutputImage >
227 {
228 public:
234 
236  itkNewMacro(Self);
237 
240 
242  itkStaticConstMacro(ImageDimension, unsigned int,
243  TOutputImage::ImageDimension);
244 
246  typedef TOutputImage OutputImageType;
247  typedef typename TOutputImage::Pointer OutputImagePointer;
248  typedef typename TOutputImage::IndexType OutputImageIndexType;
249  typedef typename TOutputImage::PixelType OutputImagePixelType;
250  typedef typename TOutputImage::SizeType OutputImageSizeType;
251  typedef typename TOutputImage::RegionType OutputImageRegionType;
252 
253  typedef TInputImage InputImageType;
254  typedef typename TInputImage::Pointer InputImagePointer;
255  typedef typename TInputImage::IndexType InputImageIndexType;
256  typedef typename TInputImage::PixelType InputImagePixelType;
257  typedef typename TInputImage::SizeType InputImageSizeType;
258  typedef typename TInputImage::RegionType InputImageRegionType;
259 
261  typedef TMaskImage ImageMaskType;
262  typedef typename ImageMaskType::Pointer ImageMaskPointer;
263  typedef typename ImageMaskType::RegionType ImageMaskRegionType;
264 
271 
275  typedef typename SlabRegionVectorType::iterator SlabRegionVectorIteratorType;
276 
279 
281  typedef MRIBiasEnergyFunction< InternalImageType,
282  ImageMaskType,
283  BiasFieldType > EnergyFunctionType;
285 
288 
291 
294 
298  void SetInputMask(ImageMaskType *inputMask);
299  itkGetModifiableObjectMacro(InputMask, ImageMaskType);
301 
304  void SetOutputMask(ImageMaskType *outputMask);
305  itkGetModifiableObjectMacro(OutputMask, ImageMaskType);
307 
312  { m_BiasMultiplicative = flag; }
313 
316  { return m_BiasMultiplicative; }
317 
321  itkSetMacro(UsingInterSliceIntensityCorrection, bool);
322  itkGetConstReferenceMacro(UsingInterSliceIntensityCorrection, bool);
324 
330  itkSetMacro(UsingSlabIdentification, bool);
331  itkGetConstReferenceMacro(UsingSlabIdentification, bool);
333 
334  itkSetMacro(SlabBackgroundMinimumThreshold, InputImagePixelType);
335  itkGetConstReferenceMacro(SlabBackgroundMinimumThreshold,
336  InputImagePixelType);
337 
338  itkSetMacro(SlabNumberOfSamples, unsigned int);
339  itkGetConstReferenceMacro(SlabNumberOfSamples, unsigned int);
340 
341  itkSetMacro(SlabTolerance, double);
342  itkGetConstReferenceMacro(SlabTolerance, double);
343 
349  itkSetMacro(UsingBiasFieldCorrection, bool);
350  itkGetConstReferenceMacro(UsingBiasFieldCorrection, bool);
352 
355  itkSetMacro(GeneratingOutput, bool);
356  itkGetConstReferenceMacro(GeneratingOutput, bool);
358 
361  itkSetMacro(SlicingDirection, int);
362 
364  itkSetMacro(BiasFieldDegree, int);
365  itkGetConstMacro(BiasFieldDegree, int);
367 
372  & coefficients)
373  { this->Modified(); m_BiasFieldCoefficients = coefficients; }
374 
379  { return m_EstimatedBiasFieldCoefficients; }
380 
384  void SetTissueClassStatistics(const Array< double > & means,
385  const Array< double > & sigmas)
386  throw ( ExceptionObject );
387 
389  itkSetMacro(VolumeCorrectionMaximumIteration, int);
390  itkGetConstMacro(VolumeCorrectionMaximumIteration, int);
391  itkSetMacro(InterSliceCorrectionMaximumIteration, int);
392  itkGetConstMacro(InterSliceCorrectionMaximumIteration, int);
394 
396  void SetOptimizerInitialRadius(double initRadius)
397  { m_OptimizerInitialRadius = initRadius; }
399  { return m_OptimizerInitialRadius; }
401 
403  itkSetMacro(OptimizerGrowthFactor, double);
404  itkGetConstMacro(OptimizerGrowthFactor, double);
406 
409  itkSetMacro(OptimizerShrinkFactor, double);
410  itkGetConstMacro(OptimizerShrinkFactor, double);
411 
418  void SetNumberOfLevels(unsigned int num);
419 
421  itkGetConstMacro(NumberOfLevels, unsigned int);
422 
429  void SetSchedule(const ScheduleType & schedule);
430 
432  itkGetConstReferenceMacro(Schedule, ScheduleType);
433 
438  void SetStartingShrinkFactors(unsigned int factor);
439 
440  void SetStartingShrinkFactors(unsigned int *factors);
441 
443  const unsigned int * GetStartingShrinkFactors() const;
444 
448  static bool IsScheduleDownwardDivisible(const ScheduleType & schedule);
449 
456  void Initialize()
457  throw ( ExceptionObject );
458 
461  BiasFieldType EstimateBiasField(InputImageRegionType region,
462  unsigned int degree,
463  int maximumIteration);
464 
468  void CorrectImage(BiasFieldType & bias,
469  InputImageRegionType region);
470 
473  void CorrectInterSliceIntensityInhomogeneity(InputImageRegionType region);
474 
475 protected:
477  virtual ~MRIBiasFieldCorrectionFilter();
478  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
479 
482  bool CheckMaskImage(ImageMaskType *mask);
483 
484 protected:
488  void Log1PImage(InternalImageType *source,
489  InternalImageType *target);
490 
493  void ExpImage(InternalImageType *source,
494  InternalImageType *target);
495 
498  template< typename TSource, typename TTarget >
499  void CopyAndConvertImage(const TSource *source,
500  TTarget *target,
501  typename TTarget::RegionType requestedRegion)
502  {
503  typedef ImageRegionConstIterator< TSource > SourceIterator;
504  typedef ImageRegionIterator< TTarget > TargetIterator;
505  typedef typename TTarget::PixelType TargetPixelType;
506 
507  SourceIterator s_iter(source, requestedRegion);
508  TargetIterator t_iter(target, requestedRegion);
509 
510  s_iter.GoToBegin();
511  t_iter.GoToBegin();
512  while ( !s_iter.IsAtEnd() )
513  {
514  t_iter.Set( static_cast< TargetPixelType >( s_iter.Get() ) );
515  ++s_iter;
516  ++t_iter;
517  }
518  }
519 
524  void GetBiasFieldSize(InputImageRegionType region,
525  BiasFieldType::DomainSizeType & domainSize);
526 
530  void AdjustSlabRegions(SlabRegionVectorType & slabs,
531  OutputImageRegionType requestedRegion);
532 
533  void GenerateData() ITK_OVERRIDE;
534 
535 private:
536  MRIBiasFieldCorrectionFilter(const Self &) ITK_DELETE_FUNCTION;
537  void operator=(const Self &) ITK_DELETE_FUNCTION;
538 
540  EnergyFunctionPointer m_EnergyFunction;
541 
543  NormalVariateGeneratorType::Pointer m_NormalVariateGenerator;
544 
546  ImageMaskPointer m_InputMask;
547 
549  ImageMaskPointer m_OutputMask;
550 
552  InternalImagePointer m_InternalInput;
553 
555  SlabRegionVectorType m_Slabs;
556 
558  int m_SlicingDirection;
559 
561  bool m_BiasMultiplicative;
562 
564  bool m_UsingInterSliceIntensityCorrection;
565  bool m_UsingSlabIdentification;
566  bool m_UsingBiasFieldCorrection;
567  bool m_GeneratingOutput;
568 
569  unsigned int m_SlabNumberOfSamples;
570  InputImagePixelType m_SlabBackgroundMinimumThreshold;
571  double m_SlabTolerance;
573  int m_BiasFieldDegree;
574 
576  unsigned int m_NumberOfLevels;
577 
579  ScheduleType m_Schedule;
580 
583  BiasFieldType::CoefficientArrayType m_BiasFieldCoefficients;
584 
587  BiasFieldType::CoefficientArrayType m_EstimatedBiasFieldCoefficients;
588 
590  int m_VolumeCorrectionMaximumIteration;
591 
593  int m_InterSliceCorrectionMaximumIteration;
594 
596  double m_OptimizerInitialRadius;
597 
599  double m_OptimizerGrowthFactor;
600 
602  double m_OptimizerShrinkFactor;
603 
605  Array< double > m_TissueClassMeans;
606 
608  Array< double > m_TissueClassSigmas;
609 };
610 
611 // ==================================
612 } // end namespace itk
613 
614 #ifndef ITK_MANUAL_INSTANTIATION
615 #include "itkMRIBiasFieldCorrectionFilter.hxx"
616 #endif
617 
618 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
Superclass::RegionType RegionType
Definition: itkImage.h:137
Superclass::DerivativeType DerivativeType
SmartPointer< const Self > ConstPointer
InternalImageType::PixelType InternalImagePixelType
This class is a base for the CostFunctions returning a single value.
Light weight base class for most itk classes.
void InitializeDistributions(Array< double > classMeans, Array< double > classSigmas)
InternalImageType::RegionType InternalImageRegionType
virtual void PrintSelf(std::ostream &os, Indent indent) const override
CompositeValleyFunction InternalEnergyFunction
unsigned int SamplingFactorType[SpaceDimension]
virtual MeasureType GetValue(const ParametersType &parameters) const override
std::vector< ImageRegionType > SlabRegionVectorType
virtual unsigned int GetNumberOfParameters(void) const override
ImageToImageFilter< TInputImage, TOutputImage > Superclass
TPixel PixelType
Definition: itkImage.h:89
Superclass::ParametersType ParametersType
MRIBiasEnergyFunction< InternalImageType, ImageMaskType, BiasFieldType > EnergyFunctionType
BiasFieldType::CoefficientArrayType GetEstimatedBiasFieldCoefficients()
Image< float, itkGetStaticConstMacro(ImageDimension) > InternalImageType
Array< ParametersValueType > DerivativeType
A multi-dimensional iterator templated over image type that walks a region of pixels.
InternalEnergyFunction * m_InternalEnergyFunction
a cost function for optimization
2D and 3D multivariate Legendre Polynomial
Standard exception handling object.
static const unsigned int SpaceDimension
A region represents some portion or piece of data.
Definition: itkRegion.h:64
virtual void Modified() const
Superclass::ParametersType ParametersType
identifies slab in MR images comparing minimum intensity averages
void GetDerivative(const ParametersType &, DerivativeType &) const override
OnePlusOneEvolutionaryOptimizer OptimizerType
Base class for filters that take an image as input and produce an image as output.
Statistics::NormalVariateGenerator NormalVariateGeneratorType
void SetSamplingFactors(SamplingFactorType factor)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MRASlabIdentifierType::SlabRegionVectorType SlabRegionVectorType
SlabRegionVectorType::iterator SlabRegionVectorIteratorType
MRASlabIdentifier< InputImageType > MRASlabIdentifierType
void SetInitialBiasFieldCoefficients(const BiasFieldType::CoefficientArrayType &coefficients)
Templated n-dimensional image class.
Definition: itkImage.h:75
A multi-dimensional iterator templated over image type that walks a region of pixels.