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

Generated at Sun Feb 3 2013 00:11:24 for Orfeo Toolbox with doxygen 1.8.1.1