File: itkAnisotropicDiffusionFunction.h

package info (click to toggle)
insighttoolkit 3.20.1%2Bgit20120521-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 80,672 kB
  • ctags: 85,253
  • sloc: cpp: 458,133; ansic: 196,222; fortran: 28,000; python: 3,839; tcl: 1,811; sh: 1,184; java: 583; makefile: 428; csh: 220; perl: 193; xml: 20
file content (247 lines) | stat: -rw-r--r-- 10,104 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkAnisotropicDiffusionFunction.h
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkAnisotropicDiffusionFunction_h
#define __itkAnisotropicDiffusionFunction_h


#include "itkFiniteDifferenceFunction.h"

namespace itk {

/**
 * \class AnisotropicDiffusionFunction
 * This class is a virtual base for anisotropic diffusion function objects.  It
 * is a component object in the finite difference solver hierarchy (see
 * itkFiniteDifferenceImageFilter for an overview).
 * AnisotropicDiffusionFunction objects are used by
 * AnisotropicDiffusionImageFilter objects to perform non-linear diffusion on
 * itk::Images.
 *
 * \par Overview of anisotropic diffusion
 *
 * Anisotropic diffusion methods are formulated to reduce noise (or unwanted
 * detail) in images while preserving specific image features.  For many
 * applications, there is an assumption that light-dark transitions
 * (edges) are interesting.  Standard isotropic diffusion methods move and blur
 * light-dark boundaries.  Anisotropic diffusion methods are formulated to
 * specifically preserve edges.
 *
 * Anisotropic diffusion methods can be thought of as tools for calculating
 * multi-scale descriptions of images. Embed an image \f$U(\mathbf{x})\f$ in a
 * higher dimensional function of derived images, \f$U(\mathbf{x}, t)\f$.  This
 * higher dimensional function represents the solution of the heat diffusion
 * equation,
 *
 * \par
 * \f[\frac{d U(\mathbf{x})}{d t} = \nabla \cdot c \nabla U(\mathbf{x})\f]
 *
 * \par
 * with constant \f$c\f$ and initial condition
 * \f$U(\mathbf{x}, 0) = U_0(\mathbf{x})\f$, the original image.
 *
 * \par
 * Extending to the case where \f$c\f$ is not a constant, but a function of
 * \f$\mathbf{x}\f$, gives
 *
 * \par
 * \f[\frac{d U(\mathbf{x})}{d t} = C(\mathbf{x})\Delta U(\mathbf{x})
 * + \nabla C(\mathbf{x}) \nabla U(\mathbf{x})\f]
 *
 * \par
 * Our choice of \f$C\f$ now varies the strength of diffusion anisotropically.
 * Typically, \f$C\f$ is chosen as some function of image features to
 * selectively preserve or remove those features.  For example, edges tend to
 * be preserved over smoother regions where \f$C\f$ is inversely scaled
 * according to gradient magnitude as in
 *
 * \par
 * \f[C(\mathbf{x}) = e^{-(\frac{\parallel \nabla U(\mathbf{x}) \parallel}{K})^2}\f].
 *
 * \par
 * Several variations on the scheme presented above are implemented in Itk as
 * subclasses of this equation.  The equations are solved using an iterative,
 * finite forward difference technique (see the FiniteDifferenceImageFilter
 * class).
 *
 * \par How to use this class
 * This class must be subclassed to provide the CalculateUpdate() methods of
 * FiniteDifferenceFunction and the function
 * CalculateAverageGradientMagnitudeSquared(), which is called before each
 * iteration to recalibrate the conductance term.
 *
 * \par Parameters
 *  The parameters defined in this class apply to the basic anisotropic
 *  diffusion equation described in AnisotropicDiffusionFunction.  Variations
 *  on the basic equation will be more or less sensitive to these parameters.
 *  For example, functions that perform higher-order derivative calculations
 *  may require smaller time-steps than those that only do first-derivative
 *  calculations. Wherever possibe, reasonable parameters settings are
 *  suggested in the documentation of a specific equation implementation.
 *
 * \par TimeStep
 * In the anisotropic diffusion filter hierarchy, the time step is set
 * explicitly by the user.  The time step referred to here corresponds exactly
 * to \f$ \Delta t \f$ in the finite difference update equation described in
 * FiniteDifferenceImageFilter (see itkFiniteDifferenceImageFilter for more
 * information).  Appropriate time steps for solving this type of p.d.e. depend 
 * on the dimensionality of the image and the order of the equation.  Typical
 * values are less than 0.250.  A stable value for most 2 and 3d functions is
 * 0.125.  In general, you should keep the time step below 1/2^N, where N is
 * the number of image dimensions.  A filter will automatically attempt to
 * constrain its time step to a stable  value and generate a run-time warning
 * if the time step is set too high. 
 *
 * \par Conductance Parameter
 * The conductance parameter controls the sensitivity of the conductance term
 * in the basic anisotropic diffusion equation.  It affect the conductance term
 * in different ways depending on the particular variation on the basic
 * equation. As a general rule, the lower the value, the more strongly the
 * diffusion equation preserves image features (such as high gradients or
 * curvature).  A high value for conductance will cause the filter to diffuse
 * image features more readily.  Typical values range from 0.5 to 2.0 for data
 * like the Visible Human color data, but the correct value for your
 * application is wholly dependent on the results you want from a specific data
 * set and the number or iterations you perform.
 *
 * \par References
 * Pietro Perona and Jalhandra Malik, ``Scale-space and edge detection using
 * anisotropic diffusion,'' IEEE Transactions on Pattern Analysis Machine
 * Intelligence, vol. 12, pp. 629-639, 1990.
 *
 * \sa VectorAnisotropicDiffusionFunction
 * \sa ScalarAnisotropicDiffusionFunction
 * \sa GradientAnisotropicDiffusionFunction
 * \sa CurvatureAnisotropicDiffusionFunction
 * \sa VectorGradientAnisotropicDiffusionFunction
 * \ingroup FiniteDifferenceFunctions
 * \ingroup ImageEnhancement
 * \todo Automatically generate the time step value from image dimensionality
 *  and order of the equations */
template <class TImage>
class ITK_EXPORT AnisotropicDiffusionFunction :
    public FiniteDifferenceFunction<TImage>
{
public:
  /** Standard class typedefs. */
  typedef AnisotropicDiffusionFunction     Self;
  typedef FiniteDifferenceFunction<TImage> Superclass;
  typedef SmartPointer<Self>               Pointer;
  typedef SmartPointer<const Self>         ConstPointer;

  /** Run-time type information (and related methods) */
  itkTypeMacro( AnisotropicDiffusionFunction, FiniteDifferenceFunction );
  
  /** Inherit some parameters from the superclass type */
  typedef typename Superclass::ImageType        ImageType;
  typedef typename Superclass::PixelType        PixelType;
  typedef typename Superclass::PixelRealType    PixelrealType;
  typedef typename Superclass::RadiusType       RadiusType;
  typedef typename Superclass::NeighborhoodType NeighborhoodType;
  typedef typename Superclass::TimeStepType     TimeStepType;
  typedef typename Superclass::FloatOffsetType  FloatOffsetType;

  /** Inherit some parameters from the superclass type */
  itkStaticConstMacro(ImageDimension, unsigned int,Superclass::ImageDimension);

  /** This method is called before each iteration.  It calculates a scalar
      value that is the average of the gradient magnitude squared at each pixel 
      in the output image (intermediate solution). The average gradient magnitude
      value is typically used in the anisotropic diffusion equations to
      calibrate the conductance term. */
  virtual void CalculateAverageGradientMagnitudeSquared(ImageType *) = 0;

  /** Set/Get the time step. For this class of anisotropic diffusion filters,
      the time-step is supplied by the user and remains fixed for all
      updates. */
  void SetTimeStep(const TimeStepType &t)
    {
    m_TimeStep = t;
    }
  const TimeStepType &GetTimeStep() const
    {
    return m_TimeStep;
    }

  /** Set/Get the conductance parameter.  The conductance parameter. */
  void SetConductanceParameter(const double &c)
    {
    m_ConductanceParameter = c;
    }
  const double &GetConductanceParameter() const
    {
    return m_ConductanceParameter;
    }

  /** Set/Get the average gradient magnitude squared. */
  const double &GetAverageGradientMagnitudeSquared() const
    {
    return m_AverageGradientMagnitudeSquared;
    }
  void SetAverageGradientMagnitudeSquared(const double &c)
    {
    m_AverageGradientMagnitudeSquared = c;
    }

  /** Returns the time step supplied by the user.  We don't need to use the
   * global data supplied since we are returning a fixed value.  */
  virtual TimeStepType ComputeGlobalTimeStep(void *itkNotUsed(GlobalData)) const
    {
    return this->GetTimeStep();
    }

  /** The anisotropic diffusion classes don't use this particular parameter
   * so it's safe to return a null value. */
  virtual void *GetGlobalDataPointer() const
    {
    return 0;
    }

  /** Does nothing.  No global data is used in this class of equations.   */
  virtual void ReleaseGlobalDataPointer(void *itkNotUsed(GlobalData)) const
    {
    /* do nothing */
    }
  
protected:
  AnisotropicDiffusionFunction()
    {
    m_AverageGradientMagnitudeSquared = 0.0;
    m_ConductanceParameter     = 1.0;     // default value
    m_TimeStep                 = 0.125f;  // default value
    }
  ~AnisotropicDiffusionFunction() {}

  void PrintSelf(std::ostream& os, Indent indent) const
    {
    Superclass::PrintSelf(os,indent);
    os << indent << "TimeStep: " << m_TimeStep << std::endl;
    os << indent << "ConductanceParameter: " << m_ConductanceParameter <<
      std::endl;
    }

private:
  AnisotropicDiffusionFunction(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

  double          m_AverageGradientMagnitudeSquared;
  double          m_ConductanceParameter;
  TimeStepType    m_TimeStep;
};

}// end namespace itk

#endif