Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkSimpleHistogram.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 mitkSimpleHistogram_h
14 #define mitkSimpleHistogram_h
15 
16 #ifndef __itkHistogram_h
17 #include <itkHistogram.h>
18 #endif
19 
21 
22 #include <mitkImage.h>
23 #include <mitkWeakPointer.h>
24 
25 #include <itkImageRegionIterator.h>
26 #include <itkImageRegionIteratorWithIndex.h>
27 
28 namespace mitk
29 {
41  {
42  public:
47  virtual double GetMin() const = 0;
48 
53  virtual double GetMax() const = 0;
54 
59  virtual void ComputeFromBaseData(BaseData *source) = 0;
60 
67  virtual float GetRelativeBin(double start, double end) const = 0;
68  };
69 
80  {
81  public:
83  typedef itk::Statistics::Histogram<double> HistogramType;
84 
86  {
87  valid = false;
88  }
89 
91  {
92  }
93 
98  bool GetValid();
99 
100  typedef itk::Image<short, 3> CTImage;
101  typedef itk::ImageRegionIterator<CTImage> CTIteratorType;
102  typedef itk::ImageRegionIteratorWithIndex<CTImage> CTIteratorIndexType;
103 
104  typedef itk::Image<unsigned char, 3> BinImage;
105  typedef itk::ImageRegionIterator<BinImage> BinIteratorType;
106  typedef itk::ImageRegionIteratorWithIndex<BinImage> BinIteratorIndexType;
107 
108  typedef unsigned long CountType;
109 
110  protected:
111  HistogramType::ConstPointer histogram;
112 
113  bool valid;
114  unsigned int nBins = 256;
115  double invLogHighest;
116 
117  public:
119  double GetMin() const override;
120 
122  double GetMax() const override;
123 
131  void ComputeFromBaseData(BaseData *source) override;
132 
134  float GetRelativeBin(double start, double end) const override;
135  };
136 
148  {
149  public:
151  static const unsigned int maxCacheSize = 64;
152 
160  {
161  public:
163  itk::TimeStamp m_LastUpdateTime;
164 
165  virtual ~Element();
166 
171  virtual void ComputeFromBaseData(BaseData *baseData) = 0;
172 
178  };
179 
180  typedef std::list<Element *> CacheContainer;
181 
183 
185  ~SimpleHistogramCache() { TrimCache(true); }
186 
192  SimpleHistogram *operator[](BaseData::Pointer sp_BaseData);
193 
194  protected:
195  void TrimCache(bool full = false)
196  {
197  unsigned int targetSize = full ? 0 : maxCacheSize;
198 
199  while (cache.size() > targetSize)
200  {
201  delete cache.back();
202  cache.pop_back();
203  }
204  }
205  };
206 }
207 
208 #endif
#define MITKALGORITHMSEXT_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
Abstract base element stored in the histogram cache.
mitk::WeakPointer< BaseData > baseData
Weak reference to the source data.
virtual SimpleHistogram * GetHistogram()=0
Get the computed histogram.
itk::TimeStamp m_LastUpdateTime
Timestamp of last computation.
virtual void ComputeFromBaseData(BaseData *baseData)=0
Compute the histogram from the given BaseData.
Cache for SimpleHistogram objects to avoid redundant recomputation.
std::list< Element * > CacheContainer
CacheContainer cache
The list of cached elements.
SimpleHistogram * operator[](BaseData::Pointer sp_BaseData)
Retrieve or compute a histogram for the given BaseData.
void TrimCache(bool full=false)
Abstract base class for simple histograms with double values.
virtual void ComputeFromBaseData(BaseData *source)=0
Compute the histogram from the given BaseData source.
virtual double GetMin() const =0
Returns the minimum value of the histogram.
virtual double GetMax() const =0
Returns the maximum value of the histogram.
virtual float GetRelativeBin(double start, double end) const =0
Get the relative frequency of bins in the range [start, end].
Histogram implementation for mitk::Image data.
void ComputeFromBaseData(BaseData *source) override
Compute the histogram from an image.
HistogramType::ConstPointer histogram
The computed ITK histogram.
double GetMax() const override
Returns the maximum value of the histogram.
bool valid
Whether the histogram is valid.
itk::Image< unsigned char, 3 > BinImage
itk::ImageRegionIterator< CTImage > CTIteratorType
float GetRelativeBin(double start, double end) const override
Get the relative frequency of bins in the range [start, end].
itk::Statistics::Histogram< double > HistogramType
The underlying ITK histogram type.
itk::ImageRegionIteratorWithIndex< BinImage > BinIteratorIndexType
itk::ImageRegionIteratorWithIndex< CTImage > CTIteratorIndexType
double invLogHighest
Inverse log of the highest bin frequency (for normalization).
double GetMin() const override
Returns the minimum value of the histogram.
bool GetValid()
Check whether the histogram has been computed successfully.
itk::Image< short, 3 > CTImage
itk::ImageRegionIterator< BinImage > BinIteratorType
A weak pointer that observes an itk::Object without preventing its deletion.
Find image slices visible on a given plane.