KWStyle - itkGaussianDerivativeSpatialFunction.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkGaussianDerivativeSpatialFunction.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:36 $
7   Version:   $Revision: 1.4 $
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 __itkGaussianDerivativeSpatialFunction_txx
18 #define __itkGaussianDerivativeSpatialFunction_txx
19
20 #include <math.h>
21 #include "itkGaussianDerivativeSpatialFunction.h"
22
23 namespace itk
24 {
25
26 template <typename TOutput, unsigned int VImageDimension, typename TInput>
27 GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>
28 ::GaussianDerivativeSpatialFunction()
29 {
30   m_Mean = ArrayType::Filled(0.0);
31   m_Sigma = ArrayType::Filled(1.0);
32   m_Scale = 1.0;
33   m_Normalized = false;
34   m_Direction = 0;
35 }
36
37 template <typename TOutput, unsigned int VImageDimension, typename TInput>
38 GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>
39 ::~GaussianDerivativeSpatialFunction()
40 {
41
42 }
43
44 template <typename TOutput, unsigned int VImageDimension, typename TInput>
45 LEN typename GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>::OutputType 
46 GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>
47 ::Evaluate(const TInput& position) const
48 {
49   // Normalizing the Gaussian is important for statistical applications
50   // but is generally not desirable for creating images because of the
51   // very small numbers involved (would need to use doubles)
52   double prefixDenom;
53
54   if (m_Normalized)
55     {
56     prefixDenom = m_Sigma[0]*m_Sigma[0]*m_Sigma[0];
57
58     for(unsigned int i = 1; i < VImageDimension; i++)
59       {
60       prefixDenom *= m_Sigma[i]*m_Sigma[i]*m_Sigma[i];
61       }
62
63     prefixDenom *= 2 * 3.1415927;
64     }
65   else
66     {
67     prefixDenom = 1.0;
68     }
69
70   double suffixExp = 0;
71
72   for(unsigned int i = 0; i < VImageDimension; i++)
73     {
74 LEN     suffixExp += (position[m_Direction] - m_Mean[m_Direction])*(position[m_Direction] - m_Mean[m_Direction]) / (2 * m_Sigma[m_Direction] * m_Sigma[m_Direction]);
75     }
76
77  
78 LEN   double value = -2*(position[m_Direction] - m_Mean[m_Direction])*m_Scale * (1 / prefixDenom) * exp(-1 * suffixExp);
79  
80   return (TOutput) value;
81 }
82
83
84 /** Evaluate the function at a given position and return a vector */
85 template <typename TOutput, unsigned int VImageDimension, typename TInput>
86 LEN typename GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>::VectorType 
87 GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>
88 ::EvaluateVector(const TInput& position) const
89 {
90   VectorType gradient;
91   for(unsigned int i = 0; i < VImageDimension; i++)
92     {
93     m_Direction = i;
94     gradient[i]=this->Evaluate(position);
95     } 
96   return gradient;
97 }
98
99 template <typename TOutput, unsigned int VImageDimension, typename TInput>
100 void
101 GaussianDerivativeSpatialFunction<TOutput, VImageDimension, TInput>
102 ::PrintSelf(std::ostream& os, Indent indent) const
103 {
104   Superclass::PrintSelf(os,indent);
105
106   os << indent << "Sigma: " << m_Sigma << std::endl;
107   os << indent << "Mean: " <<  m_Mean << std::endl;
108   os << indent << "Scale: " << m_Scale << std::endl;
109   os << indent << "Normalized?: " << m_Normalized << std::endl;
110   os << indent << "Direction: " << m_Direction << std::endl;
111 }
112
113
114 // end namespace itk
115
116 #endif
117

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:10PM
© Kitware Inc.