21 #ifndef otbConvolutionImageFilter_hxx
22 #define otbConvolutionImageFilter_hxx
25 #include "itkConstNeighborhoodIterator.h"
26 #include "itkImageRegionIterator.h"
27 #include "itkOffset.h"
28 #include "itkProgressReporter.h"
29 #include "itkConstantBoundaryCondition.h"
37 template <
class TInputImage,
class TOutputImage,
class TBoundaryCondition,
class TFilterPrecision>
41 m_Filter.SetSize(3 * 3);
43 m_NormalizeFilter =
false;
46 template <
class TInputImage,
class TOutputImage,
class TBoundaryCondition,
class TFilterPrecision>
50 Superclass::GenerateInputRequestedRegion();
53 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
54 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
56 if (!inputPtr || !outputPtr)
63 typename TInputImage::RegionType inputRequestedRegion;
64 inputRequestedRegion = inputPtr->GetRequestedRegion();
67 inputRequestedRegion.PadByRadius(m_Radius);
69 otbMsgDevMacro(<<
"Region is now " << inputRequestedRegion.GetIndex() <<
", " << inputRequestedRegion.GetSize());
72 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
74 inputPtr->SetRequestedRegion(inputRequestedRegion);
83 inputPtr->SetRequestedRegion(inputRequestedRegion);
86 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
87 e.SetLocation(ITK_LOCATION);
88 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
89 e.SetDataObject(inputPtr);
94 template <
class TInputImage,
class TOutputImage,
class TBoundaryCondition,
class TFilterPrecision>
99 typename OutputImageType::Pointer output = this->GetOutput();
100 typename InputImageType::ConstPointer input = this->GetInput();
103 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
108 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
110 itk::ConstNeighborhoodIterator<InputImageType, BoundaryConditionType> inputIt(m_Radius, input, inputRegionForThread);
111 itk::ImageRegionIterator<OutputImageType> outputIt(output, outputRegionForThread);
114 const unsigned int neighborhoodSize = inputIt.Size();
118 if (m_NormalizeFilter)
120 InputRealType norm = itk::NumericTraits<InputRealType>::Zero;
121 for (
unsigned int i = 0; i < neighborhoodSize; ++i)
125 const double norm_double = 1. /
static_cast<double>(std::abs(norm));
127 while (!inputIt.IsAtEnd())
129 sum = itk::NumericTraits<InputRealType>::Zero;
131 for (
unsigned int i = 0; i < neighborhoodSize; ++i)
133 sum +=
static_cast<InputRealType>(inputIt.GetPixel(i) * m_Filter(i));
141 progress.CompletedPixel();
146 while (!inputIt.IsAtEnd())
148 sum = itk::NumericTraits<InputRealType>::Zero;
150 for (
unsigned int i = 0; i < neighborhoodSize; ++i)
152 sum +=
static_cast<InputRealType>(inputIt.GetPixel(i) * m_Filter(i));
159 progress.CompletedPixel();
167 template <
class TInputImage,
class TOutput,
class TBoundaryCondition,
class TFilterPrecision>
170 Superclass::PrintSelf(os, indent);
171 os << indent <<
"Radius: " << m_Radius <<
'\n';