Medical Imaging Interaction Toolkit  2022.04.99-b878213f
Medical Imaging Interaction Toolkit
mitkStatisticsImageFilter.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 // This file is based on ITK's itkStatisticsImageFilter.h
14 
15 #ifndef mitkStatisticsImageFilter
16 #define mitkStatisticsImageFilter
17 
18 #include <mitkCommon.h>
19 
20 #include <itkArray.h>
21 #include <itkCompensatedSummation.h>
22 #include <itkHistogram.h>
23 #include <itkImageSink.h>
24 #include <itkNumericTraits.h>
25 #include <itkSimpleDataObjectDecorator.h>
26 
27 #include <mutex>
28 
29 namespace mitk
30 {
31  template <typename TInputImage>
32  class StatisticsImageFilter : public itk::ImageSink<TInputImage>
33  {
34  public:
36  using Superclass = itk::ImageSink<TInputImage>;
39 
40  itkFactorylessNewMacro(Self);
41 
42  itkTypeMacro(StatisticsImageFilter, itk::ImageSink);
43 
44  using RegionType = typename TInputImage::RegionType;
45  using PixelType = typename TInputImage::PixelType;
46 
47  using RealType = typename itk::NumericTraits<PixelType>::RealType;
48 
49  using HistogramType = typename itk::Statistics::Histogram<RealType>;
51 
52  using DataObjectPointer = typename itk::DataObject::Pointer;
53 
54  template <typename T>
55  using SimpleDataObjectDecorator = itk::SimpleDataObjectDecorator<T>;
56 
59  using ProcessObject = itk::ProcessObject;
60 
67  itkGetDecoratedOutputMacro(SumOfSquares, RealType);
69  itkGetDecoratedOutputMacro(SumOfQuadruples, RealType);
78 
79  void SetHistogramParameters(unsigned int size, RealType lowerBound, RealType upperBound);
80 
81  using DataObjectIdentifierType = itk::ProcessObject::DataObjectIdentifierType;
82  using Superclass::MakeOutput;
83 
86 
87  protected:
90 
97  itkSetDecoratedOutputMacro(SumOfSquares, RealType);
99  itkSetDecoratedOutputMacro(SumOfQuadruples, RealType);
108 
109  void BeforeStreamedGenerateData() override;
110  void ThreadedStreamedGenerateData(const RegionType&) override;
111  void AfterStreamedGenerateData() override;
112 
113  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
114 
115  private:
116  HistogramPointer CreateInitializedHistogram() const;
117 
118  bool m_ComputeHistogram;
119  unsigned int m_HistogramSize;
120  RealType m_HistogramLowerBound;
121  RealType m_HistogramUpperBound;
122  HistogramPointer m_Histogram;
123 
124  itk::CompensatedSummation<RealType> m_Sum;
125  itk::CompensatedSummation<RealType> m_SumOfPositivePixels;
126  itk::CompensatedSummation<RealType> m_SumOfSquares;
127  itk::CompensatedSummation<RealType> m_SumOfCubes;
128  itk::CompensatedSummation<RealType> m_SumOfQuadruples;
129 
130  itk::SizeValueType m_Count;
131  itk::SizeValueType m_CountOfPositivePixels;
132  PixelType m_Min;
133  PixelType m_Max;
134 
135  std::mutex m_Mutex;
136  };
137 }
138 
139 #ifndef ITK_MANUAL_INSTANTIATION
140 #include <mitkStatisticsImageFilter.hxx>
141 #endif
142 
143 #endif
itkSetDecoratedOutputMacro(Minimum, PixelType)
typename TInputImage::PixelType PixelType
void AfterStreamedGenerateData() override
itk::ProcessObject::DataObjectIdentifierType DataObjectIdentifierType
typename itk::DataObject::Pointer DataObjectPointer
DataCollection - Class to facilitate loading/accessing structured data.
itk::ImageSink< TInputImage > Superclass
typename TInputImage::RegionType RegionType
SimpleDataObjectDecorator< PixelType > PixelObjectType
itkGetDecoratedOutputMacro(Minimum, PixelType)
void BeforeStreamedGenerateData() override
itk::SimpleDataObjectDecorator< T > SimpleDataObjectDecorator
void SetHistogramParameters(unsigned int size, RealType lowerBound, RealType upperBound)
void ThreadedStreamedGenerateData(const RegionType &) override
SimpleDataObjectDecorator< RealType > RealObjectType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
typename itk::Statistics::Histogram< RealType > HistogramType
typename itk::NumericTraits< PixelType >::RealType RealType
DataObjectPointer MakeOutput(const DataObjectIdentifierType &name) override