Orfeo Toolbox  4.0
otbBinaryImageDensityFunction.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Copyright (c) CS Systemes d'information. All rights reserved.
13  See CSCopyright.txt for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 
22 #ifndef __otbBinaryImageDensityFunction_txx
23 #define __otbBinaryImageDensityFunction_txx
24 
26 
27 #include "itkNumericTraits.h"
29 
30 namespace otb
31 {
32 
36 template <class TInputImage, class TCoordRep>
39 {
40  m_NeighborhoodRadius.Fill(1);
41 }
42 
46 template <class TInputImage, class TCoordRep>
47 void
49 ::PrintSelf(std::ostream& os, itk::Indent indent) const
50 {
51  this->Superclass::PrintSelf(os, indent);
52  os << indent << "NeighborhoodRadius: " << m_NeighborhoodRadius << std::endl;
53 }
54 
58 template <class TInputImage, class TCoordRep>
60 ::RealType
62 ::EvaluateAtIndex(const IndexType& index) const
63 {
64  RealType sum;
65  RealType var;
66 
68 
69  if (!this->GetInputImage())
70  {
72  }
73 
74  if (!this->IsInsideBuffer(index))
75  {
77  }
78 
79  // Create an N-d neighborhood kernel, using a zeroflux boundary condition
80  typename InputImageType::SizeType kernelSize = 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  }
95 
96  const RealType num = static_cast<RealType>(size);
97  var = sum / num;
98 
99  return var;
100 }
101 
102 } // end namespace otb
103 
104 #endif

Generated at Sat Mar 8 2014 15:51:20 for Orfeo Toolbox with doxygen 1.8.3.1