Medical Imaging Interaction Toolkit  2024.06.00
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 #ifndef mitkStatisticsImageFilter_h
14 #define mitkStatisticsImageFilter_h
15 
16 // This file is based on ITK's itkStatisticsImageFilter.h
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
mitk::StatisticsImageFilter::Superclass
itk::ImageSink< TInputImage > Superclass
Definition: mitkStatisticsImageFilter.h:36
mitk::StatisticsImageFilter::BeforeStreamedGenerateData
void BeforeStreamedGenerateData() override
mitk::StatisticsImageFilter::SetHistogramParameters
void SetHistogramParameters(unsigned int size, RealType lowerBound, RealType upperBound)
itk::SmartPointer< Self >
mitk::StatisticsImageFilter::PixelType
typename TInputImage::PixelType PixelType
Definition: mitkStatisticsImageFilter.h:45
mitk::StatisticsImageFilter::itkSetDecoratedOutputMacro
itkSetDecoratedOutputMacro(Minimum, PixelType)
mitk::StatisticsImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::StatisticsImageFilter
Definition: mitkStatisticsImageFilter.h:32
mitk::StatisticsImageFilter::HistogramType
typename itk::Statistics::Histogram< RealType > HistogramType
Definition: mitkStatisticsImageFilter.h:49
mitk::StatisticsImageFilter::DataObjectIdentifierType
itk::ProcessObject::DataObjectIdentifierType DataObjectIdentifierType
Definition: mitkStatisticsImageFilter.h:81
mitk::StatisticsImageFilter::ThreadedStreamedGenerateData
void ThreadedStreamedGenerateData(const RegionType &) override
mitk::StatisticsImageFilter::RegionType
typename TInputImage::RegionType RegionType
Definition: mitkStatisticsImageFilter.h:44
mitk::StatisticsImageFilter::DataObjectPointer
typename itk::DataObject::Pointer DataObjectPointer
Definition: mitkStatisticsImageFilter.h:52
mitkCommon.h
mitk::StatisticsImageFilter::StatisticsImageFilter
StatisticsImageFilter()
mitk::StatisticsImageFilter::RealType
typename itk::NumericTraits< PixelType >::RealType RealType
Definition: mitkStatisticsImageFilter.h:47
mitk::StatisticsImageFilter::MakeOutput
DataObjectPointer MakeOutput(const DataObjectIdentifierType &name) override
mitk::StatisticsImageFilter::RealObjectType
SimpleDataObjectDecorator< RealType > RealObjectType
Definition: mitkStatisticsImageFilter.h:57
mitk::StatisticsImageFilter::ProcessObject
itk::ProcessObject ProcessObject
Definition: mitkStatisticsImageFilter.h:59
mitk::StatisticsImageFilter::PixelObjectType
SimpleDataObjectDecorator< PixelType > PixelObjectType
Definition: mitkStatisticsImageFilter.h:58
mitk::StatisticsImageFilter::~StatisticsImageFilter
~StatisticsImageFilter()
mitk::StatisticsImageFilter::AfterStreamedGenerateData
void AfterStreamedGenerateData() override
mitk::StatisticsImageFilter::SimpleDataObjectDecorator
itk::SimpleDataObjectDecorator< T > SimpleDataObjectDecorator
Definition: mitkStatisticsImageFilter.h:55
mitk::StatisticsImageFilter::itkGetDecoratedOutputMacro
itkGetDecoratedOutputMacro(Minimum, PixelType)