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"
32 #include "itkProgressReporter.h"
40 template <
class TInputImage,
class TOutputImage>
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);
116 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
122 double Ci, Ci2, Cu, Cu2, E_I, I, Var_I, dPixel, alpha, b, d, Cmax;
125 Cu2 = 1.0 / m_NbLooks;
130 for (fit = faceList.begin(); fit != faceList.end(); ++fit)
132 bit = itk::ConstNeighborhoodIterator<InputImageType>(m_Radius, input, *fit);
133 const unsigned int neighborhoodSize = bit.Size();
134 it = itk::ImageRegionIterator<OutputImageType>(output, *fit);
135 bit.OverrideBoundaryCondition(&nbc);
141 while (!bit.IsAtEnd())
143 sum = itk::NumericTraits<InputRealType>::Zero;
144 sum2 = itk::NumericTraits<InputRealType>::Zero;
147 for (i = 0; i < neighborhoodSize; ++i)
149 dPixel =
static_cast<double>(bit.GetPixel(i));
152 E_I = sum /
static_cast<double>(neighborhoodSize);
154 for (i = 0; i < neighborhoodSize; ++i)
156 dPixel =
static_cast<double>(bit.GetPixel(i));
157 sum2 += (dPixel - E_I) * (dPixel - E_I);
159 Var_I = sum2 /
static_cast<double>(neighborhoodSize - 1);
161 I =
static_cast<double>(bit.GetCenterPixel());
163 Ci2 = Var_I / (E_I * E_I);
166 const double epsilon = 0.0000000001;
167 if (std::abs(E_I) < epsilon)
169 dPixel = itk::NumericTraits<OutputPixelType>::Zero;
171 else if (std::abs(Var_I) < epsilon)
181 Cmax = std::sqrt(2.0) * Cu;
185 alpha = (1 + Cu2) / (Ci2 - Cu2);
186 b = alpha - m_NbLooks - 1;
187 d = E_I * E_I * b * b + 4 * alpha * m_NbLooks * E_I * I;
188 dPixel = (b * E_I + std::sqrt(d)) / (2 * alpha);
200 progress.CompletedPixel();
208 template <
class TInputImage,
class TOutput>
211 Superclass::PrintSelf(os, indent);
212 os << indent <<
"Radius: " << m_Radius << std::endl;