ITK  4.2.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 <time.h>
22 
23 #include "itkImageToImageFilter.h"
24 #include "itkArray2D.h"
25 #include "itkMRASlabIdentifier.h"
30 #include "itkImageRegionIterator.h"
31 
32 namespace itk
33 {
46 template< class TImage, class TImageMask, class 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  MeasureType GetValue(const ParametersType & parameters) const;
127 
130  void GetDerivative( const ParametersType & itkNotUsed(parameters),
131  DerivativeType & itkNotUsed(derivative) ) const
132  {}
133 
139  Array< double > classSigmas);
140 
141  unsigned int GetNumberOfParameters(void) const;
142 
143 protected:
146 
148  virtual ~MRIBiasEnergyFunction();
149 private:
150 
153 
156 
159 
162 
165 
168 
169  MRIBiasEnergyFunction(const Self &); //purposely not implemented
170  void operator=(const Self &); //purposely not implemented
171 }; // end of class
172 
223 template< class TInputImage, class TOutputImage, class TMaskImage >
225  public ImageToImageFilter< TInputImage, TOutputImage >
226 {
227 public:
233 
235  itkNewMacro(Self);
236 
239 
241  itkStaticConstMacro(ImageDimension, unsigned int,
242  TOutputImage::ImageDimension);
243 
245  typedef TOutputImage OutputImageType;
246  typedef typename TOutputImage::Pointer OutputImagePointer;
247  typedef typename TOutputImage::IndexType OutputImageIndexType;
248  typedef typename TOutputImage::PixelType OutputImagePixelType;
249  typedef typename TOutputImage::SizeType OutputImageSizeType;
250  typedef typename TOutputImage::RegionType OutputImageRegionType;
251 
252  typedef TInputImage InputImageType;
253  typedef typename TInputImage::Pointer InputImagePointer;
254  typedef typename TInputImage::IndexType InputImageIndexType;
255  typedef typename TInputImage::PixelType InputImagePixelType;
256  typedef typename TInputImage::SizeType InputImageSizeType;
257  typedef typename TInputImage::RegionType InputImageRegionType;
258 
260  typedef TMaskImage ImageMaskType;
261  typedef typename ImageMaskType::Pointer ImageMaskPointer;
262  typedef typename ImageMaskType::RegionType ImageMaskRegionType;
263 
270 
274  typedef typename SlabRegionVectorType::iterator SlabRegionVectorIteratorType;
275 
278 
284 
287 
290 
293 
297  void SetInputMask(ImageMaskType *inputMask);
298 
299  itkGetObjectMacro(InputMask, ImageMaskType);
300 
303  void SetOutputMask(ImageMaskType *outputMask);
304 
306  itkGetObjectMacro(OutputMask, ImageMaskType);
307 
311  void IsBiasFieldMultiplicative(bool flag)
312  { m_BiasMultiplicative = flag; }
313 
315  bool IsBiasFieldMultiplicative()
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 
370  void SetInitialBiasFieldCoefficients(const
372  & coefficients)
373  { this->Modified(); m_BiasFieldCoefficients = coefficients; }
374 
378  BiasFieldType::CoefficientArrayType GetEstimatedBiasFieldCoefficients()
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; }
398  double GetOptimizerInitialRadius()
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;
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< class TSource, class 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();
534 
535 private:
536  MRIBiasFieldCorrectionFilter(const Self &); //purposely not implemented
537  void operator=(const Self &); //purposely not implemented
538 
541 
544 
547 
550 
553 
556 
559 
562 
568 
569  unsigned int m_SlabNumberOfSamples;
574 
576  unsigned int m_NumberOfLevels;
577 
580 
584 
588 
591 
594 
597 
600 
603 
606 
609 };
610 
611 // ==================================
612 } // end namespace itk
613 
614 #ifndef ITK_MANUAL_INSTANTIATION
615 #include "itkMRIBiasFieldCorrectionFilter.hxx"
616 #endif
617 
618 #endif
619