21 #ifndef otbVarianceImageFilter_hxx
22 #define otbVarianceImageFilter_hxx
26 #include "itkConstNeighborhoodIterator.h"
27 #include "itkNeighborhoodInnerProduct.h"
28 #include "itkImageRegionIterator.h"
29 #include "itkNeighborhoodAlgorithm.h"
30 #include "itkOffset.h"
31 #include "itkProgressReporter.h"
36 template <
class TInputImage,
class TOutputImage>
40 this->DynamicMultiThreadingOn();
43 template <
class TInputImage,
class TOutputImage>
47 Superclass::GenerateInputRequestedRegion();
50 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
51 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
53 if (!inputPtr || !outputPtr)
60 typename TInputImage::RegionType inputRequestedRegion;
61 inputRequestedRegion = inputPtr->GetRequestedRegion();
64 inputRequestedRegion.PadByRadius(m_Radius);
67 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
69 inputPtr->SetRequestedRegion(inputRequestedRegion);
78 inputPtr->SetRequestedRegion(inputRequestedRegion);
81 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
82 e.SetLocation(ITK_LOCATION);
83 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
84 e.SetDataObject(inputPtr);
89 template <
class TInputImage,
class TOutputImage>
93 itk::ZeroFluxNeumannBoundaryCondition<InputImageType> nbc;
95 itk::ConstNeighborhoodIterator<InputImageType> bit;
96 itk::ImageRegionIterator<OutputImageType> it;
99 typename OutputImageType::Pointer output = this->GetOutput();
100 typename InputImageType::ConstPointer input = this->GetInput();
103 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType faceList;
104 itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> bC;
105 faceList = bC(input, outputRegionForThread, m_Radius);
107 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType::iterator fit;
114 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
116 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
117 unsigned int neighborhoodSize = bit.Size();
118 it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
119 bit.OverrideBoundaryCondition(&nbc);
122 while (!bit.IsAtEnd())
124 sum = itk::NumericTraits<InputRealType>::Zero;
125 sumOfSquares = itk::NumericTraits<InputRealType>::Zero;
126 for (i = 0; i < neighborhoodSize; ++i)
130 sumOfSquares += value * value;
134 const double num =
static_cast<double>(neighborhoodSize);
135 it.Set(
static_cast<OutputPixelType>(sumOfSquares - (sum * sum / num)) / (num - 1.0));
146 template <
class TInputImage,
class TOutput>
149 Superclass::PrintSelf(os, indent);
150 os << indent <<
"Radius: " << m_Radius << std::endl;
void PrintSelf(std::ostream &os, itk::Indent indent) const override
OutputImageType::PixelType OutputPixelType
OutputImageType::RegionType OutputImageRegionType
void GenerateInputRequestedRegion() override
itk::NumericTraits< InputPixelType >::RealType InputRealType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.