KWStyle - itkVarianceImageFunction.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkVarianceImageFunction.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
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 DEF #ifndef _itkVarianceImageFunction_txx
18 DEF #define _itkVarianceImageFunction_txx
19 #include "itkVarianceImageFunction.h"
20
21 #include "itkNumericTraits.h"
22 #include "itkConstNeighborhoodIterator.h"
23
24 namespace itk
25 {
26
27 /**
28  * Constructor
29  */
30 template <class TInputImage, class TCoordRep>
31 VarianceImageFunction<TInputImage,TCoordRep>
32 ::VarianceImageFunction()
33 {
34   m_NeighborhoodRadius = 1;
35 }
36
37
38 /**
39  *
40  */
41 template <class TInputImage, class TCoordRep>
42 void
43 VarianceImageFunction<TInputImage,TCoordRep>
44 ::PrintSelf(std::ostream& os, Indent indent) const
45 {
46   this->Superclass::PrintSelf(os,indent);
47   os << indent << "NeighborhoodRadius: "  << m_NeighborhoodRadius << std::endl;
48 }
49
50
51 /**
52  *
53  */
54 template <class TInputImage, class TCoordRep>
55 typename VarianceImageFunction<TInputImage,TCoordRep>
56 ::RealType
57 VarianceImageFunction<TInputImage,TCoordRep>
58 ::EvaluateAtIndex(const IndexType& index) const
59 {
60   RealType sum;
61   RealType sumOfSquares;
62   RealType var;
63
64   sum = NumericTraits<RealType>::Zero;
65   sumOfSquares = NumericTraits<RealType>::Zero;
66   
67   if( !this->GetInputImage() )
68     {
69     return ( NumericTraits<RealType>::max() );
70     }
71   
72   if ( !this->IsInsideBuffer( index ) )
73     {
74     return ( NumericTraits<RealType>::max() );
75     }
76
77   // Create an N-d neighborhood kernel, using a zeroflux boundary condition
78   typename InputImageType::SizeType kernelSize;
79   kernelSize.Fill( m_NeighborhoodRadius );
80   
81   ConstNeighborhoodIterator<InputImageType>
82 LEN,IND ****it(kernelSize, this->GetInputImage(), this->GetInputImage()->GetBufferedRegion());
83
84   // Set the iterator at the desired location
85   it.SetLocation(index);
86
87   // Walk the neighborhood
88   const unsigned int size = it.Size();
89   for (unsigned int i = 0; i < size; ++i)
90     {
91     const RealType value = static_cast<RealType>( it.GetPixel(i) );
92     sum           += value;
93     sumOfSquares  += value * value;
94     }
95
96   const double num = static_cast<double>( size );
97   var = ( sumOfSquares - ( sum*sum / num ) ) / ( num - 1.0 );
98   
99   return ( var );
100 }
101
102
103 // namespace itk
104
105 #endif
106

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