Medical Imaging Interaction Toolkit  2026.06.00
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 
46 
48  bool RequestedRegionIsOutsideOfTheBufferedRegion() override { return false; }
49 
51  bool VerifyRequestedRegion() override { return true; }
52 
54  void SetRequestedRegion(const itk::DataObject*) override {}
55 
62  public:
64 
65  using RealType = double;
66  using IndexType = vnl_vector<int>;
67  using VoxelCountType = unsigned long;
68 
69  using StatisticsVariantType = boost::variant<RealType, VoxelCountType, IndexType >;
70 
75  void AddStatistic(const std::string_view key, StatisticsVariantType value);
76 
77  using StatisticNameVector = std::vector<std::string>;
78 
84 
89 
95 
101 
107  bool HasStatistic(const std::string_view name) const;
108 
114  template <typename TType>
115  TType GetValueConverted(const std::string_view name) const
116  {
117  auto value = GetValueNonConverted(name);
118  return boost::get<TType>(value);
119  }
120 
125  StatisticsVariantType GetValueNonConverted(const std::string_view name) const;
126 
128  void Reset();
129 
131  HistogramType::ConstPointer m_Histogram=nullptr;
132  private:
133 
134  using StatisticsMapType = std::map < std::string, StatisticsVariantType, std::less<>>;
135 
136  StatisticsMapType m_Statistics;
137  StatisticNameVector m_CustomNames;
138  static const StatisticNameVector m_DefaultNames;
139  };
140 
145 
147  using TimeStepVectorType = std::vector<TimeStepType>;
148 
155 
157  static constexpr LabelValueType NO_MASK_LABEL_VALUE = Label::UNLABELED_VALUE;
159 
165 
169  void Reset();
170 
179 
184  void SetStatistics(LabelValueType labelValue, TimeStepType timeStep, const ImageStatisticsObject& statistics);
185 
190  bool StatisticsExist(LabelValueType labelValue, TimeStepType timeStep) const;
191 
195  const HistogramType* GetHistogram(LabelValueType labelValue, TimeStepType timeStep) const;
196 
201  bool IgnoresZeroVoxel() const;
202 
207  bool IsWIP() const;
208 
209  protected:
212  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
213 
215 
216  private:
217 
218  using TimeStepMapType = std::map<TimeStepType, ImageStatisticsObject>;
219  using LabelMapType = std::map<LabelValueType, TimeStepMapType>;
220 
221  LabelMapType m_LabelTimeStep2StatisticsMap;
222  };
223 
230 
237 }
238 #endif
#define MITKIMAGESTATISTICS_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Container class for storing the computed image statistics.
StatisticNameVector GetExistingStatisticNames() const
Returns the names of statistics that actually have stored values.
bool HasStatistic(const std::string_view name) const
Check whether a statistic with the given name exists.
StatisticNameVector GetAllStatisticNames() const
Returns the names of all statistics (default and custom defined) Additional custom keys are added at ...
void Reset()
Clear all stored statistics and custom names.
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
Retrieve the statistics object for a given label and time step.
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
bool IgnoresZeroVoxel() const
Check whether this container was computed with zero-voxel ignoring enabled.
ImageStatisticsObject::VoxelCountType VoxelCountType
void Reset()
Delete all stored statistics for all labels and time steps.
ImageStatisticsObject::IndexType IndexType
LabelValueVectorType GetExistingLabelValues() const
Get all label values for which statistics have been stored.
TimeStepVectorType GetExistingTimeSteps(LabelValueType labelValue) const
Get all time steps for which statistics exist for the given label.
void PrintSelf(std::ostream &os, itk::Indent indent) const override
ImageStatisticsObject::StatisticsVariantType StatisticsVariantType
void SetRequestedRegion(const itk::DataObject *) override
Required by BaseData. No-op for this container.
bool VerifyRequestedRegion() override
Required by BaseData. Always returns true.
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
Required by BaseData. Always returns false (data is always buffered).
ImageStatisticsContainer(const ImageStatisticsContainer &other)
std::vector< TimeStepType > TimeStepVectorType
Vector of time step indices.
void SetRequestedRegionToLargestPossibleRegion() override
Required by BaseData. Sets requested region to largest possible. No-op.
bool IsWIP() const
Check whether this container is a work-in-progress placeholder.
static constexpr PixelType UNLABELED_VALUE
Value indicating pixels that are not labeled at all (background).
Definition: mitkLabel.h:115
std::vector< LabelValueType > LabelValueVectorType
mitk::Label::PixelType LabelValueType
Find image slices visible on a given plane.
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
MITKIMAGESTATISTICS_EXPORT ImageStatisticsContainer::ImageStatisticsObject::StatisticNameVector GetAllStatisticNames(const ImageStatisticsContainer *container)
Collect all statistic names (default and custom) from a single container.