Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
mitkImageStatisticsContainer.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 mitkImageStatisticsContainer_h
14 #define mitkImageStatisticsContainer_h
15 
17 #include <mitkBaseData.h>
18 #include <itkHistogram.h>
19 #include <mitkLabelSetImage.h>
21 
22 #include <boost/variant.hpp>
23 
24 namespace mitk
25 {
26 
35  {
36  public:
38  itkFactorylessNewMacro(Self);
39  itkCloneMacro(Self);
40 
41  using HistogramType = itk::Statistics::Histogram<double>;
43 
45 
46  bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
47 
48  bool VerifyRequestedRegion() override { return true; }
49 
50  void SetRequestedRegion(const itk::DataObject*) override {}
51 
58  public:
60 
61  using RealType = double;
62  using IndexType = vnl_vector<int>;
63  using VoxelCountType = unsigned long;
64 
65  using StatisticsVariantType = boost::variant<RealType, VoxelCountType, IndexType >;
66 
71  void AddStatistic(const std::string_view key, StatisticsVariantType value);
72 
73  using StatisticNameVector = std::vector<std::string>;
74 
80 
85 
91 
93 
94  bool HasStatistic(const std::string_view name) const;
95 
101  template <typename TType>
102  TType GetValueConverted(const std::string_view name) const
103  {
104  auto value = GetValueNonConverted(name);
105  return boost::get<TType>(value);
106  }
107 
112  StatisticsVariantType GetValueNonConverted(const std::string_view name) const;
113 
114  void Reset();
115 
116  HistogramType::ConstPointer m_Histogram=nullptr;
117  private:
118 
119  using StatisticsMapType = std::map < std::string, StatisticsVariantType, std::less<>>;
120 
121  StatisticsMapType m_Statistics;
122  StatisticNameVector m_CustomNames;
123  static const StatisticNameVector m_DefaultNames;
124  };
125 
130 
131  using TimeStepVectorType = std::vector<TimeStepType>;
133 
135  static constexpr LabelValueType NO_MASK_LABEL_VALUE = Label::UNLABELED_VALUE;
138 
141  void Reset();
142 
144 
149  void SetStatistics(LabelValueType labelValue, TimeStepType timeStep, const ImageStatisticsObject& statistics);
150 
155  bool StatisticsExist(LabelValueType labelValue, TimeStepType timeStep) const;
156 
160  const HistogramType* GetHistogram(LabelValueType labelValue, TimeStepType timeStep) const;
161 
162  bool IgnoresZeroVoxel() const;
163 
164  bool IsWIP() const;
165 
166  protected:
168  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
169 
170  private:
171  itk::LightObject::Pointer InternalClone() const override;
172 
173  using TimeStepMapType = std::map<TimeStepType, ImageStatisticsObject>;
174  using LabelMapType = std::map<LabelValueType, TimeStepMapType>;
175 
176  LabelMapType m_LabelTimeStep2StatisticsMap;
177  };
178 
181 }
182 #endif
#define MITKIMAGESTATISTICS_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
Container class for storing the computed image statistics.
bool HasStatistic(const std::string_view name) const
StatisticNameVector GetAllStatisticNames() const
Returns the names of all statistics (default and custom defined) Additional custom keys are added at ...
boost::variant< RealType, VoxelCountType, IndexType > StatisticsVariantType
static const StatisticNameVector & GetDefaultStatisticNames()
Returns the names of the default statistics.
TType GetValueConverted(const std::string_view name) const
Converts the requested value to the defined type.
void AddStatistic(const std::string_view key, StatisticsVariantType value)
Adds a statistic to the statistics object.
StatisticsVariantType GetValueNonConverted(const std::string_view name) const
Returns the requested value.
const StatisticNameVector & GetCustomStatisticNames() const
Returns the names of all custom statistics (defined at runtime and no default names).
Container class for storing a StatisticsObject for each time step.
const ImageStatisticsObject & GetStatistics(LabelValueType labelValue, TimeStepType timeStep) const
ImageStatisticsObject::RealType RealType
bool StatisticsExist(LabelValueType labelValue, TimeStepType timeStep) const
Checks if the Time step exists.
mitkClassMacro(ImageStatisticsContainer, mitk::BaseData)
const HistogramType * GetHistogram(LabelValueType labelValue, TimeStepType timeStep) const
ImageStatisticsObject::VoxelCountType VoxelCountType
void Reset()
Deletes all stored values.
ImageStatisticsObject::IndexType IndexType
LabelValueVectorType GetExistingLabelValues() const
TimeStepVectorType GetExistingTimeSteps(LabelValueType labelValue) const
void PrintSelf(std::ostream &os, itk::Indent indent) const override
ImageStatisticsObject::StatisticsVariantType StatisticsVariantType
void SetRequestedRegion(const itk::DataObject *) override
Set the requested region from this data object to match the requested region of the data object passe...
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
MultiLabelSegmentation::LabelValueVectorType LabelValueVectorType
itk::Statistics::Histogram< double > HistogramType
MultiLabelSegmentation::LabelValueType LabelValueType
void SetStatistics(LabelValueType labelValue, TimeStepType timeStep, const ImageStatisticsObject &statistics)
Sets the statisticObject for the given Timestep.
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.
std::vector< TimeStepType > TimeStepVectorType
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
static constexpr PixelType UNLABELED_VALUE
Definition: mitkLabel.h:103
std::vector< LabelValueType > LabelValueVectorType
mitk::Label::PixelType LabelValueType
Find image slices visible on a given plane.
std::size_t TimeStepType
MITKIMAGESTATISTICS_EXPORT ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector GetAllStatisticNames(const ImageStatisticsContainer *container)