21 #ifndef otbGammaMAPImageFilter_hxx
22 #define otbGammaMAPImageFilter_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"
40 template <
class TInputImage,
class TOutputImage>
45 this->DynamicMultiThreadingOn();
49 template <
class TInputImage,
class TOutputImage>
53 Superclass::GenerateInputRequestedRegion();
56 typename Superclass::InputImagePointer inputPtr =
const_cast<TInputImage*
>(this->GetInput());
57 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
59 if (!inputPtr || !outputPtr)
66 typename TInputImage::RegionType inputRequestedRegion;
67 inputRequestedRegion = inputPtr->GetRequestedRegion();
70 inputRequestedRegion.PadByRadius(m_Radius);
73 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
75 inputPtr->SetRequestedRegion(inputRequestedRegion);
84 inputPtr->SetRequestedRegion(inputRequestedRegion);
87 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
88 std::ostringstream msg;
89 msg << static_cast<const char*>(this->GetNameOfClass()) <<
"::GenerateInputRequestedRegion()";
90 e.SetLocation(msg.str());
91 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
92 e.SetDataObject(inputPtr);
97 template <
class TInputImage,
class TOutputImage>
101 itk::ZeroFluxNeumannBoundaryCondition<InputImageType> nbc;
103 itk::ConstNeighborhoodIterator<InputImageType> bit;
104 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);
120 double Ci, Ci2, Cu, Cu2, E_I, I, Var_I, dPixel, alpha, b, d, Cmax;
123 Cu2 = 1.0 / m_NbLooks;
128 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
130 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
131 const unsigned int neighborhoodSize = bit.Size();
132 it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
133 bit.OverrideBoundaryCondition(&nbc);
139 while (!bit.IsAtEnd())
141 sum = itk::NumericTraits<InputRealType>::Zero;
142 sum2 = itk::NumericTraits<InputRealType>::Zero;
145 for (i = 0; i < neighborhoodSize; ++i)
147 dPixel =
static_cast<double>(bit.GetPixel(i));
150 E_I = sum /
static_cast<double>(neighborhoodSize);
152 for (i = 0; i < neighborhoodSize; ++i)
154 dPixel =
static_cast<double>(bit.GetPixel(i));
155 sum2 += (dPixel - E_I) * (dPixel - E_I);
157 Var_I = sum2 /
static_cast<double>(neighborhoodSize - 1);
159 I =
static_cast<double>(bit.GetCenterPixel());
161 Ci2 = Var_I / (E_I * E_I);
164 const double epsilon = 0.0000000001;
165 if (std::abs(E_I) < epsilon)
167 dPixel = itk::NumericTraits<OutputPixelType>::Zero;
169 else if (std::abs(Var_I) < epsilon)
179 Cmax = std::sqrt(2.0) * Cu;
183 alpha = (1 + Cu2) / (Ci2 - Cu2);
184 b = alpha - m_NbLooks - 1;
185 d = E_I * E_I * b * b + 4 * alpha * m_NbLooks * E_I * I;
186 dPixel = (b * E_I + std::sqrt(d)) / (2 * alpha);
204 template <
class TInputImage,
class TOutput>
207 Superclass::PrintSelf(os, indent);
208 os << indent <<
"Radius: " << m_Radius << std::endl;
void GenerateInputRequestedRegion() override
OutputImageType::PixelType OutputPixelType
OutputImageType::RegionType OutputImageRegionType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
itk::NumericTraits< InputPixelType >::RealType InputRealType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.