KWStyle - itkGaussianSpatialFunction.txx
 
Matrix View
Description

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

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