22 #ifndef otbLocalRxDetectorFilter_h
23 #define otbLocalRxDetectorFilter_h
25 #include "itkImageToImageFilter.h"
27 #include "itkListSample.h"
28 #include "itkCovarianceSampleFilter.h"
29 #include "itkConstNeighborhoodIterator.h"
45 template <
typename TInput,
typename TOutput = TInput>
55 typedef typename CovarianceCalculatorType::MatrixType
MatrixType;
67 void SetInternalRadius(
const unsigned int internalRadiusX,
const unsigned int internalRadiusY)
87 typename ListSampleType::Pointer listSample = ListSampleType::New();
90 auto centerPixel = in.GetCenterPixel();
91 listSample->SetMeasurementVectorSize(centerPixel.Size());
95 auto externalRadius = in.GetRadius();
102 const int externalRadiusX =
static_cast<int>(externalRadius[0]);
103 const int externalRadiusY =
static_cast<int>(externalRadius[0]);
105 for (
int y = -externalRadiusY; y <= externalRadiusY; y++)
108 for (
int x = -externalRadiusX; x <= externalRadiusX; x++)
111 if ((abs(x) > internalRadiusX) || (abs(y) > internalRadiusY))
113 listSample->PushBack(in.GetPixel(off));
119 typename CovarianceCalculatorType::Pointer covarianceCalculator = CovarianceCalculatorType::New();
120 covarianceCalculator->SetInput(listSample);
121 covarianceCalculator->Update();
126 for (
unsigned int i = 0; i < meanVector.GetNumberOfElements(); ++i)
128 meanVec.SetElement(i, meanVector.GetElement(i));
131 MatrixType covarianceMatrix = covarianceCalculator->GetCovarianceMatrix();
132 typename MatrixType::InternalMatrixType invCovMat = covarianceMatrix.GetInverse();
134 typename MatrixType::InternalMatrixType centeredTestPixMat(meanVector.GetNumberOfElements(), 1);
136 for (
unsigned int i = 0; i < centeredTestPixMat.rows(); ++i)
138 centeredTestPixMat.put(i, 0, (centerPixel.GetElement(i) - meanVector.GetElement(i)));
142 typename MatrixType::InternalMatrixType rxValue = centeredTestPixMat.transpose() * invCovMat * centeredTestPixMat;
144 return static_cast<TOutput
>(rxValue.get(0, 0));