21 #ifndef otbScalarImageToPanTexTextureFilter_hxx
22 #define otbScalarImageToPanTexTextureFilter_hxx
25 #include "itkImageRegionIteratorWithIndex.h"
26 #include "itkConstNeighborhoodIterator.h"
27 #include "itkImageRegionIterator.h"
28 #include "itkProgressReporter.h"
29 #include "itkNumericTraits.h"
33 template <
class TInputImage,
class TOutputImage>
35 : m_Radius(), m_NumberOfBinsPerAxis(8), m_InputImageMinimum(0), m_InputImageMaximum(255)
38 this->SetNumberOfRequiredOutputs(1);
42 m_OffsetList = { {0, 1}, {0, 2}, {1, -2}, {1, -1}, {1, 0}, {1, 1}, {1, 2}, {2, -1}, {2, 0}, {2, 1} };
45 template <
class TInputImage,
class TOutputImage>
49 Superclass::GenerateInputRequestedRegion();
55 if (!inputPtr || !outputPtr)
70 inputRequestedRegion.PadByRadius(m_Radius + maxOffsetSize);
73 if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
75 inputPtr->SetRequestedRegion(inputRequestedRegion);
80 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
81 e.SetLocation(ITK_LOCATION);
82 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region.");
83 e.SetDataObject(inputPtr);
88 template <
class TInputImage,
class TOutputImage>
90 itk::ThreadIdType threadId)
96 itk::ImageRegionIteratorWithIndex<OutputImageType> outputIt(outputPtr, outputRegionForThread);
100 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
103 while (!outputIt.IsAtEnd())
106 double out = itk::NumericTraits<double>::max();
109 typename OffsetListType::const_iterator offIt;
110 for (offIt = m_OffsetList.begin(); offIt != m_OffsetList.end(); ++offIt)
115 typename InputRegionType::IndexType inputIndex;
116 typename InputRegionType::SizeType inputSize;
121 for (
unsigned int dim = 0; dim < InputImageType::ImageDimension; ++dim)
123 inputIndex[dim] = outputIt.GetIndex()[dim] - m_Radius[dim];
124 inputSize[dim] = 2 * m_Radius[dim] + 1;
129 inputRegion.Crop(inputPtr->GetRequestedRegion());
133 unsigned int minRadius = 0;
134 for (
unsigned int i = 0; i < currentOffset.GetOffsetDimension(); i++)
136 unsigned int distance = std::abs(currentOffset[i]);
137 if (distance > minRadius)
139 minRadius = distance;
142 neighborhoodRadius.Fill(minRadius);
146 GLCIList->Initialize(m_NumberOfBinsPerAxis, m_InputImageMinimum, m_InputImageMaximum);
148 typedef itk::ConstNeighborhoodIterator<InputImageType> NeighborhoodIteratorType;
149 NeighborhoodIteratorType neighborIt = NeighborhoodIteratorType(neighborhoodRadius, inputPtr, inputRegion);
151 for (neighborIt.GoToBegin(); !neighborIt.IsAtEnd(); ++neighborIt)
153 const InputPixelType centerPixelIntensity = neighborIt.GetCenterPixel();
155 const InputPixelType pixelIntensity = neighborIt.GetPixel(currentOffset, pixelInBounds);
160 GLCIList->AddPixelPair(centerPixelIntensity, pixelIntensity);
165 double totalFrequency =
static_cast<double>(GLCIList->GetTotalFrequency());
169 constVectorIt = glcVector.begin();
170 while (constVectorIt != glcVector.end())
174 inertia += (index[0] - index[1]) * (index[0] - index[1]) * frequency;
186 progress.CompletedPixel();