21 #ifndef otbFrostImageFilter_hxx
22 #define otbFrostImageFilter_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;
101 itk::ConstNeighborhoodIterator<InputImageType> bit;
102 typename itk::ConstNeighborhoodIterator<InputImageType>::OffsetType off;
103 itk::ImageRegionIterator<OutputImageType> it;
106 typename OutputImageType::Pointer output = this->GetOutput();
107 typename InputImageType::ConstPointer input = this->GetInput();
110 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType faceList;
111 typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType>::FaceListType::iterator fit;
113 itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> bC;
114 faceList = bC(input, outputRegionForThread, m_Radius);
119 double Mean, Variance;
128 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
130 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
131 unsigned int neighborhoodSize = bit.Size();
132 it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
133 bit.OverrideBoundaryCondition(&nbc);
138 while (!bit.IsAtEnd())
140 sum = itk::NumericTraits<InputRealType>::Zero;
141 sum2 = itk::NumericTraits<InputRealType>::Zero;
143 for (i = 0; i < neighborhoodSize; ++i)
145 dPixel =
static_cast<double>(bit.GetPixel(i));
148 Mean = sum /
static_cast<double>(neighborhoodSize);
150 for (i = 0; i < neighborhoodSize; ++i)
152 dPixel =
static_cast<double>(bit.GetPixel(i));
153 sum2 += (dPixel - Mean) * (dPixel - Mean);
155 Variance = sum2 / double(neighborhoodSize - 1);
157 const double epsilon = 0.0000000001;
158 if (std::abs(Mean) < epsilon)
160 dPixel = itk::NumericTraits<OutputPixelType>::Zero;
162 else if (std::abs(Variance) < epsilon)
168 Alpha = m_Deramp * Variance / (Mean * Mean);
173 const int rad_x = m_Radius[0];
174 const int rad_y = m_Radius[1];
176 for (
int x = -rad_x; x <= rad_x; ++x)
178 for (
int y = -rad_y; y <= rad_y; ++y)
180 double Dist = std::sqrt(
static_cast<double>(x * x + y * y));
184 dPixel =
static_cast<double>(bit.GetPixel(off));
186 CoefFilter = std::exp(-Alpha * Dist);
187 NormFilter += CoefFilter;
188 FrostFilter += (CoefFilter * dPixel);
192 dPixel = FrostFilter / NormFilter;
206 template <
class TInputImage,
class TOutput>
209 Superclass::PrintSelf(os, indent);
210 os << indent <<
"Radius: " << m_Radius << std::endl;
itk::NumericTraits< InputPixelType >::RealType InputRealType
void GenerateInputRequestedRegion() override
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
OutputImageType::RegionType OutputImageRegionType
OutputImageType::PixelType OutputPixelType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.