21 #ifndef __otbStreamingStatisticsImageFilter_txx
22 #define __otbStreamingStatisticsImageFilter_txx
27 #include "itkNumericTraits.h"
34 template<
class TInputImage>
42 m_IgnoreInfiniteValues(true),
43 m_IgnoreUserDefinedValue(false)
50 for (
int i = 1; i < 3; ++i)
58 for (
int i = 3; i < 7; ++i)
65 this->GetMinimumOutput()->Set(itk::NumericTraits<PixelType>::max());
66 this->GetMaximumOutput()->Set(itk::NumericTraits<PixelType>::NonpositiveMin());
67 this->GetMeanOutput()->Set(itk::NumericTraits<RealType>::max());
68 this->GetSigmaOutput()->Set(itk::NumericTraits<RealType>::max());
69 this->GetVarianceOutput()->Set(itk::NumericTraits<RealType>::max());
70 this->GetSumOutput()->Set(itk::NumericTraits<RealType>::Zero);
73 m_IgnoredInfinitePixelCount= std::vector<unsigned int>(this->GetNumberOfThreads(), 0);
74 m_IgnoredUserPixelCount= std::vector<unsigned int>(this->GetNumberOfThreads(), 0);
79 template<
class TInputImage>
90 return static_cast<itk::DataObject*
>(PixelObjectType::New().GetPointer());
93 return static_cast<itk::DataObject*
>(PixelObjectType::New().GetPointer());
99 return static_cast<itk::DataObject*
>(RealObjectType::New().GetPointer());
108 template<
class TInputImage>
116 template<
class TInputImage>
124 template<
class TInputImage>
132 template<
class TInputImage>
140 template<
class TInputImage>
148 template<
class TInputImage>
156 template<
class TInputImage>
164 template<
class TInputImage>
172 template<
class TInputImage>
180 template<
class TInputImage>
188 template<
class TInputImage>
196 template<
class TInputImage>
203 template<
class TInputImage>
208 Superclass::GenerateOutputInformation();
209 if (this->GetInput())
211 this->GetOutput()->CopyInformation(this->GetInput());
212 this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
214 if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
216 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
220 template<
class TInputImage>
232 template<
class TInputImage>
241 int numberOfThreads = this->GetNumberOfThreads();
250 sum = sumOfSquares = itk::NumericTraits<RealType>::Zero;
255 minimum = itk::NumericTraits<PixelType>::max();
256 maximum = itk::NumericTraits<PixelType>::NonpositiveMin();
257 for (i = 0; i < numberOfThreads; ++i)
260 sum += m_ThreadSum[i];
261 sumOfSquares += m_SumOfSquares[i];
263 if (m_ThreadMin[i] < minimum)
265 minimum = m_ThreadMin[i];
267 if (m_ThreadMax[i] > maximum)
269 maximum = m_ThreadMax[i];
273 mean = sum /
static_cast<RealType>(count);
276 variance = (sumOfSquares - (sum * sum /
static_cast<RealType>(count)))
277 / (static_cast<RealType>(count) - 1);
278 sigma = vcl_sqrt(variance);
281 this->GetMinimumOutput()->Set(minimum);
282 this->GetMaximumOutput()->Set(maximum);
283 this->GetMeanOutput()->Set(mean);
284 this->GetSigmaOutput()->Set(sigma);
285 this->GetVarianceOutput()->Set(variance);
286 this->GetSumOutput()->Set(sum);
289 template<
class TInputImage>
294 int numberOfThreads = this->GetNumberOfThreads();
297 m_Count.SetSize(numberOfThreads);
298 m_SumOfSquares.SetSize(numberOfThreads);
299 m_ThreadSum.SetSize(numberOfThreads);
300 m_ThreadMin.SetSize(numberOfThreads);
301 m_ThreadMax.SetSize(numberOfThreads);
303 m_Count.Fill(itk::NumericTraits<long>::Zero);
304 m_ThreadSum.Fill(itk::NumericTraits<RealType>::Zero);
305 m_SumOfSquares.Fill(itk::NumericTraits<RealType>::Zero);
306 m_ThreadMin.Fill(itk::NumericTraits<PixelType>::max());
307 m_ThreadMax.Fill(itk::NumericTraits<PixelType>::NonpositiveMin());
308 if (m_IgnoreInfiniteValues)
310 m_IgnoredInfinitePixelCount= std::vector<unsigned int>(numberOfThreads, 0);
313 if (m_IgnoreUserDefinedValue)
315 m_IgnoredUserPixelCount= std::vector<unsigned int>(this->GetNumberOfThreads(), 0);
319 template<
class TInputImage>
342 realValue =
static_cast<RealType>(value);
343 if (m_IgnoreInfiniteValues && !(vnl_math_isfinite(realValue)))
345 m_IgnoredInfinitePixelCount[threadId] ++;
349 if (m_IgnoreUserDefinedValue && (value == m_UserIgnoredValue))
351 m_IgnoredUserPixelCount[threadId] ++;
355 if (value < m_ThreadMin[threadId])
357 m_ThreadMin[threadId] = value;
359 if (value > m_ThreadMax[threadId])
361 m_ThreadMax[threadId] = value;
364 m_ThreadSum[threadId] += realValue;
365 m_SumOfSquares[threadId] += (realValue * realValue);
370 progress.CompletedPixel();
373 template <
class TImage>
378 Superclass::PrintSelf(os, indent);
380 os << indent <<
"Minimum: "
381 <<
static_cast<typename itk::NumericTraits<PixelType>::PrintType
>(this->GetMinimum()) << std::endl;
382 os << indent <<
"Maximum: "
383 <<
static_cast<typename itk::NumericTraits<PixelType>::PrintType
>(this->GetMaximum()) << std::endl;
384 os << indent <<
"Sum: " << this->GetSum() << std::endl;
385 os << indent <<
"Mean: " << this->GetMean() << std::endl;
386 os << indent <<
"Sigma: " << this->GetSigma() << std::endl;
387 os << indent <<
"Variance: " << this->GetVariance() << std::endl;