21 #ifndef otbLeeImageFilter_hxx
22 #define otbLeeImageFilter_hxx
26 #include "itkDataObject.h"
27 #include "itkConstNeighborhoodIterator.h"
28 #include "itkNeighborhoodInnerProduct.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkNeighborhoodAlgorithm.h"
31 #include "itkOffset.h"
39 template <
class TInputImage,
class TOutputImage>
47 template <
class TInputImage,
class TOutputImage>
51 Superclass::GenerateInputRequestedRegion();
54 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
55 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
57 if (!inputPtr || !outputPtr)
64 typename TInputImage::RegionType inputRequestedRegion;
65 inputRequestedRegion = inputPtr->GetRequestedRegion();
68 inputRequestedRegion.PadByRadius(m_Radius);
71 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
73 inputPtr->SetRequestedRegion(inputRequestedRegion);
82 inputPtr->SetRequestedRegion(inputRequestedRegion);
85 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
86 std::ostringstream msg;
87 msg << static_cast<const char*>(this->GetNameOfClass()) <<
"::GenerateInputRequestedRegion()";
88 e.SetLocation(msg.str());
89 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
90 e.SetDataObject(inputPtr);
95 template <
class TInputImage,
class TOutputImage>
99 itk::ZeroFluxNeumannBoundaryCondition<InputImageType> nbc;
101 itk::ConstNeighborhoodIterator<InputImageType> bit;
102 itk::ImageRegionIterator<OutputImageType> it;
104 typename OutputImageType::Pointer output = this->GetOutput();
105 typename InputImageType::ConstPointer input = this->GetInput();
108 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType faceList;
109 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType::iterator fit;
111 itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> bC;
112 faceList = bC(input, outputRegionForThread, m_Radius);
118 double Ci2, Cu2, w, E_I, I, Var_I, dPixel;
121 Cu2 = 1.0 / m_NbLooks;
125 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
127 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
128 const unsigned int neighborhoodSize = bit.Size();
129 it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
130 bit.OverrideBoundaryCondition(&nbc);
136 while (!bit.IsAtEnd())
138 sum = itk::NumericTraits<InputRealType>::Zero;
139 sum2 = itk::NumericTraits<InputRealType>::Zero;
142 for (i = 0; i < neighborhoodSize; ++i)
144 dPixel =
static_cast<double>(bit.GetPixel(i));
147 E_I = sum /
static_cast<double>(neighborhoodSize);
149 for (i = 0; i < neighborhoodSize; ++i)
151 dPixel =
static_cast<double>(bit.GetPixel(i));
152 sum2 += (dPixel - E_I) * (dPixel - E_I);
154 Var_I = sum2 /
static_cast<double>(neighborhoodSize - 1);
156 I =
static_cast<double>(bit.GetCenterPixel());
158 Ci2 = Var_I / (E_I * E_I);
160 const double epsilon = 0.0000000001;
161 if (std::abs(E_I) < epsilon)
163 dPixel = itk::NumericTraits<OutputPixelType>::Zero;
165 else if (std::abs(Var_I) < epsilon)
176 dPixel = I * w + E_I * (1 - w);
191 template <
class TInputImage,
class TOutput>
194 Superclass::PrintSelf(os, indent);
195 os << indent <<
"Radius: " << m_Radius << std::endl;
itk::NumericTraits< InputPixelType >::RealType InputRealType
OutputImageType::RegionType OutputImageRegionType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
OutputImageType::PixelType OutputPixelType
void GenerateInputRequestedRegion() override
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.