21 #ifndef otbKuanImageFilter_hxx
22 #define otbKuanImageFilter_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>
44 this->DynamicMultiThreadingOn();
48 template <
class TInputImage,
class TOutputImage>
52 Superclass::GenerateInputRequestedRegion();
55 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
56 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
58 if (!inputPtr || !outputPtr)
65 typename TInputImage::RegionType inputRequestedRegion;
66 inputRequestedRegion = inputPtr->GetRequestedRegion();
69 inputRequestedRegion.PadByRadius(m_Radius);
72 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
74 inputPtr->SetRequestedRegion(inputRequestedRegion);
83 inputPtr->SetRequestedRegion(inputRequestedRegion);
86 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
87 std::ostringstream msg;
88 msg << static_cast<const char*>(this->GetNameOfClass()) <<
"::GenerateInputRequestedRegion()";
89 e.SetLocation(msg.str());
90 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
91 e.SetDataObject(inputPtr);
96 template <
class TInputImage,
class TOutputImage>
100 itk::ZeroFluxNeumannBoundaryCondition<InputImageType> nbc;
102 itk::ConstNeighborhoodIterator<InputImageType> bit;
103 itk::ImageRegionIterator<OutputImageType> it;
105 typename OutputImageType::Pointer output = this->GetOutput();
106 typename InputImageType::ConstPointer input = this->GetInput();
109 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType faceList;
110 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType::iterator fit;
112 itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> bC;
113 faceList = bC(input, outputRegionForThread, m_Radius);
119 double Ci2, Cu2, w, E_I, I, Var_I, dPixel;
122 Cu2 = 1.0 / m_NbLooks;
126 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
128 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
129 const unsigned int neighborhoodSize = bit.Size();
130 it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
131 bit.OverrideBoundaryCondition(&nbc);
137 while (!bit.IsAtEnd())
139 sum = itk::NumericTraits<InputRealType>::Zero;
140 sum2 = itk::NumericTraits<InputRealType>::Zero;
143 for (i = 0; i < neighborhoodSize; ++i)
145 dPixel =
static_cast<double>(bit.GetPixel(i));
148 E_I = sum /
static_cast<double>(neighborhoodSize);
150 for (i = 0; i < neighborhoodSize; ++i)
152 dPixel =
static_cast<double>(bit.GetPixel(i));
153 sum2 += (dPixel - E_I) * (dPixel - E_I);
155 Var_I = sum2 /
static_cast<double>(neighborhoodSize - 1);
157 I =
static_cast<double>(bit.GetCenterPixel());
159 Ci2 = Var_I / (E_I * E_I);
161 const double epsilon = 0.0000000001;
162 if (std::abs(E_I) < epsilon)
164 dPixel = itk::NumericTraits<OutputPixelType>::Zero;
166 else if (std::abs(Var_I) < epsilon)
176 w = (1 - Cu2 / Ci2) / (1 + Cu2);
177 dPixel = I * w + E_I * (1 - w);
193 template <
class TInputImage,
class TOutput>
196 Superclass::PrintSelf(os, indent);
197 os << indent <<
"Radius: " << m_Radius << std::endl;
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void GenerateInputRequestedRegion() override
OutputImageType::RegionType OutputImageRegionType
OutputImageType::PixelType OutputPixelType
itk::NumericTraits< InputPixelType >::RealType InputRealType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.