Orfeo Toolbox  3.16
itkAnisotropicDiffusionImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkAnisotropicDiffusionImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-08-16 02:05:44 $
7  Version: $Revision: 1.30 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkAnisotropicDiffusionImageFilter_txx
18 #define __itkAnisotropicDiffusionImageFilter_txx
19 
21 
22 namespace itk
23 {
24 
28 template <class TInputImage, class TOutputImage>
31 {
32  this->SetNumberOfIterations(1);
33  m_ConductanceParameter = 1.0;
34  m_ConductanceScalingParameter = 1.0;
35  m_ConductanceScalingUpdateInterval = 1;
36  m_TimeStep = 0.5 / vcl_pow(2.0, static_cast<double>(ImageDimension));
37  m_FixedAverageGradientMagnitude = 1.0;
38  m_GradientMagnitudeIsFixed = false;
39 }
40 
42 template <class TInputImage, class TOutputImage>
43 void
46 {
49  (this->GetDifferenceFunction().GetPointer());
50  if (! f)
51  {
52  throw ExceptionObject(__FILE__, __LINE__, "Anisotropic diffusion function is not set.", ITK_LOCATION);
53  }
54 
55  f->SetConductanceParameter(m_ConductanceParameter);
56  f->SetTimeStep(m_TimeStep);
57 
58  // Check the timestep for stability
59  double minSpacing;
60  if (this->GetUseImageSpacing())
61  {
62  minSpacing = this->GetInput()->GetSpacing()[0];
63  for (unsigned int i = 1; i < ImageDimension; i++)
64  {
65  if (this->GetInput()->GetSpacing()[i] < minSpacing)
66  {
67  minSpacing = this->GetInput()->GetSpacing()[i];
68  }
69  }
70  }
71  else
72  {
73  minSpacing = 1.0;
74  }
75  if ( m_TimeStep > (minSpacing / vcl_pow(2.0, static_cast<double>(ImageDimension) + 1)) )
76  {
77  // f->SetTimeStep(1.0 / vcl_pow(2.0, static_cast<double>(ImageDimension)));
78  itkWarningMacro( << "Anisotropic diffusion unstable time step: "
79  << m_TimeStep << std::endl
80  << "Stable time step for this image must be smaller than "
81  << minSpacing / vcl_pow(2.0, static_cast<double>(ImageDimension+1)));
82  }
83 
84  if (m_GradientMagnitudeIsFixed == false)
85  {
86  if ((this->GetElapsedIterations() % m_ConductanceScalingUpdateInterval) == 0 )
87  {
88  f->CalculateAverageGradientMagnitudeSquared(this->GetOutput());
89  }
90  }
91  else
92  {
93  f->SetAverageGradientMagnitudeSquared(m_FixedAverageGradientMagnitude
94  *
95  m_FixedAverageGradientMagnitude);
96  }
98 
99  if (this->GetNumberOfIterations() != 0)
100  {
101  this->UpdateProgress(((float)(this->GetElapsedIterations()))
102  /((float)(this->GetNumberOfIterations())));
103  }
104  else
105  {
106  this->UpdateProgress(0);
107  }
108 }
109 
110 template <class TInputImage, class TOutputImage>
111 void
113 ::PrintSelf(std::ostream& os, Indent indent) const
114 {
115  Superclass::PrintSelf(os, indent.GetNextIndent());
116  os << indent << "TimeStep: " << m_TimeStep << std::endl;
117  os << indent << "ConductanceParameter: "
118  << m_ConductanceParameter << std::endl;
119  os << indent << "ConductanceScalingParameter: "
120  << m_ConductanceScalingParameter << std::endl;
121  os << indent << "ConductanceScalingUpdateInterval: "
122  << m_ConductanceScalingUpdateInterval << std::endl;
123  os << indent << "FixedAverageGradientMagnitude: "
124  << m_FixedAverageGradientMagnitude << std::endl;
125 }
126 
127 } // end namespace itk
128 
129 #endif

Generated at Sat Feb 2 2013 23:23:59 for Orfeo Toolbox with doxygen 1.8.1.1