22 #ifndef otbBoxAndWhiskerImageFilter_hxx
23 #define otbBoxAndWhiskerImageFilter_hxx
28 #include "itkConstNeighborhoodIterator.h"
29 #include "itkImageRegionIterator.h"
30 #include "itkNeighborhoodAlgorithm.h"
31 #include "itkProgressReporter.h"
39 template <
class TInputImage>
42 this->SetNumberOfRequiredInputs(1);
43 this->SetNumberOfRequiredOutputs(1);
50 template <
class TInputImage>
53 const TInputImage* inputPtr = this->GetInput();
57 typedef typename itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> ImageBoundaryFacesCalculatorType;
58 typename ImageBoundaryFacesCalculatorType::FaceListType faceList;
59 ImageBoundaryFacesCalculatorType boundaryCalculator;
60 faceList = boundaryCalculator(inputPtr, outputRegionForThread, this->GetRadius());
63 typename ImageBoundaryFacesCalculatorType::FaceListType::iterator faceIterator;
66 itk::ImageRegionConstIterator<InputImageType> inputIter;
67 itk::ImageRegionIterator<OutputImageType> outputIter;
70 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
76 for (faceIterator = faceList.begin(); faceIterator != faceList.end(); ++faceIterator)
78 inputIter = itk::ImageRegionConstIterator<InputImageType>(inputPtr, *faceIterator);
79 inputIter.GoToBegin();
82 outputIter = itk::ImageRegionIterator<OutputImageType>(outputPtr, *faceIterator);
83 outputIter.GoToBegin();
85 while (!outputIter.IsAtEnd())
87 outputIter.Set(this->PerformBoxAndWhiskerDetection(inputIter.Get()));
92 progress.CompletedPixel();
97 template <
class TInputImage>
104 const unsigned int vectorSize = pixel.Size();
105 const unsigned int medianPosition = vectorSize / 2;
106 const unsigned int firstQuartilePosition = vectorSize / 4;
107 const unsigned int thirdQuartilePosition = (3 * vectorSize) / 4;
110 for (i = 0; i < vectorSize; ++i)
113 std::sort(data.begin(), data.end());
115 double box = m_Beta *
static_cast<double>(data[thirdQuartilePosition] - data[firstQuartilePosition]);
116 double median = ::fabs(
static_cast<double>(data[medianPosition]));
119 for (i = 0; i < vectorSize; ++i)
121 if (::fabs(
static_cast<double>(outputPixel[i]) - box) >
median)
123 OutlierType::SetToMissingValue(outputPixel[i]);
131 template <
class TInputImage>
134 Superclass::GenerateOutputInformation();
135 this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetInput()->GetNumberOfComponentsPerPixel());
137 this->GetOutput()->CopyInformation(this->GetInput());
140 template <
class TInputImage>
144 output->SetNumberOfComponentsPerPixel(this->GetInput()->GetNumberOfComponentsPerPixel());
145 output->SetBufferedRegion(output->GetRequestedRegion());