Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImageStatisticsCalculator.h
Go to the documentation of this file.
1 #ifndef MITKIMAGESTATISTICSCALCULATOR
2 #define MITKIMAGESTATISTICSCALCULATOR
3 
5 #include <mitkImage.h>
6 #include <mitkMaskGenerator.h>
7 #include <itkImage.h>
8 #include <limits>
9 #include <itkObject.h>
10 #include <itkSmartPointer.h>
11 
12 namespace mitk
13 {
15  {
16  public:
19  typedef itk::Object Superclass;
22 
24  itkNewMacro(Self)
25 
26 
27  itkTypeMacro(ImageStatisticsCalculator_v2, itk::Object)
28 
29  typedef double statisticsValueType;
30  typedef std::map<std::string, statisticsValueType> statisticsMapType;
31  typedef itk::Statistics::Histogram<double> HistogramType;
32  typedef unsigned short MaskPixelType;
33 
59  {
60  public:
63  typedef itk::Object Superclass;
66 
68  itkNewMacro(Self)
69 
70 
71  itkTypeMacro(StatisticsContainer, itk::Object)
72 
73  typedef double RealType;
74 
77  statisticsMapType GetStatisticsAsMap();
78 
81  void Reset();
82 
83  void SetN(long n)
84  {
85  m_N = n;
86  }
87 
88  const long& GetN() const
89  {
90  return m_N;
91  }
92 
93  void SetMean(RealType mean)
94  {
95  m_Mean = mean;
96  }
97 
98  const RealType& GetMean() const
99  {
100  return m_Mean;
101  }
102 
103  void SetVariance(RealType variance)
104  {
105  m_Variance = variance;
106  }
107 
108  const RealType& GetVariance() const
109  {
110  return m_Variance;
111  }
112 
114  {
115  m_Std = std;
116  }
117 
118  const RealType& GetStd() const
119  {
120  return m_Std;
121  }
122 
123  void SetMin(RealType minVal)
124  {
125  m_Min = minVal;
126  }
127 
128  const RealType& GetMin() const
129  {
130  return m_Min;
131  }
132 
133  void SetMax(RealType maxVal)
134  {
135  m_Max = maxVal;
136  }
137 
138  const RealType& GetMax() const
139  {
140  return m_Max;
141  }
142 
143  void SetRMS(RealType rms)
144  {
145  m_RMS = rms;
146  }
147 
148  const RealType& GetRMS() const
149  {
150  return m_RMS;
151  }
152 
153  void SetSkewness(RealType skewness)
154  {
155  m_Skewness = skewness;
156  }
157 
158  const RealType& GetSkewness() const
159  {
160  return m_Skewness;
161  }
162 
163  void SetKurtosis(RealType kurtosis)
164  {
165  m_Kurtosis = kurtosis;
166  }
167 
168  const RealType& GetKurtosis() const
169  {
170  return m_Kurtosis;
171  }
172 
173  void SetMPP(RealType mpp)
174  {
175  m_MPP = mpp;
176  }
177 
178  const RealType& GetMPP() const
179  {
180  return m_MPP;
181  }
182 
183  void SetLabel(unsigned int label)
184  {
185  m_Label = label;
186  }
187 
188  const unsigned int& GetLabel() const
189  {
190  return m_Label;
191  }
192 
193  void SetMinIndex(vnl_vector<int> minIndex)
194  {
195  m_minIndex = minIndex;
196  }
197 
198  vnl_vector<int> GetMinIndex() const
199  {
200  return m_minIndex;
201  }
202 
203  void SetMaxIndex(vnl_vector<int> maxIndex)
204  {
205  m_maxIndex = maxIndex;
206  }
207 
208  vnl_vector<int> GetMaxIndex() const
209  {
210  return m_maxIndex;
211  }
212 
214  {
215  if (m_Histogram != hist)
216  {
217  m_Histogram = hist;
218  }
219  }
220 
222  {
223  return m_Histogram;
224  }
225 
226  void SetEntropy(RealType entropy)
227  {
228  m_Entropy = entropy;
229  }
230 
231  const RealType & GetEntropy() const
232  {
233  return m_Entropy;
234  }
235 
236  void SetMedian(RealType median)
237  {
238  m_Median = median;
239  }
240 
241  const RealType & GetMedian() const
242  {
243  return m_Median;
244  }
245 
246  void SetUniformity(RealType uniformity)
247  {
248  m_Uniformity = uniformity;
249  }
250 
251  const RealType & GetUniformity() const
252  {
253  return m_Uniformity;
254  }
255 
256  void SetUPP(RealType upp)
257  {
258  m_UPP = upp;
259  }
260 
261  const RealType & GetUPP() const
262  {
263  return m_UPP;
264  }
265 
268  void Print();
269 
272  std::string GetAsString();
273 
274 
275  protected:
277 
278  private:
279  itk::LightObject::Pointer InternalClone() const
280  {
281  itk::LightObject::Pointer ioPtr = Superclass::InternalClone();
282  Self::Pointer rval = dynamic_cast<Self*>(ioPtr.GetPointer());
283  if (rval.IsNull())
284  {
285  itkExceptionMacro(<< "downcast to type "
286  << "StatisticsContainer"
287  << " failed.");
288  }
289 
290  rval->SetEntropy(this->GetEntropy());
291  rval->SetKurtosis(this->GetKurtosis());
292  rval->SetLabel(this->GetLabel());
293  rval->SetMax(this->GetMax());
294  rval->SetMin(this->GetMin());
295  rval->SetMean(this->GetMean());
296  rval->SetMedian(this->GetMedian());
297  rval->SetMPP(this->GetMPP());
298  rval->SetN(this->GetN());
299  rval->SetRMS(this->GetRMS());
300  rval->SetSkewness(this->GetSkewness());
301  rval->SetStd(this->GetStd());
302  rval->SetUniformity(this->GetUniformity());
303  rval->SetUPP(this->GetUPP());
304  rval->SetVariance(this->GetVariance());
305  rval->SetHistogram(this->GetHistogram());
306  rval->SetMinIndex(this->GetMinIndex());
307  rval->SetMaxIndex(this->GetMaxIndex());
308  return ioPtr;
309  }
310 
311  // not pretty, is temporary
312  long m_N;
313  RealType m_Mean, m_Min, m_Max, m_Std, m_Variance;
314  RealType m_Skewness;
315  RealType m_Kurtosis;
316  RealType m_RMS;
317  RealType m_MPP;
318  vnl_vector<int> m_minIndex, m_maxIndex;
319  RealType m_Median;
320  RealType m_Uniformity;
321  RealType m_UPP;
322  RealType m_Entropy;
323  unsigned int m_Label;
324  HistogramType::Pointer m_Histogram;
325 
326  };
327 
330  void SetInputImage(mitk::Image::Pointer image);
331 
334  void SetMask(mitk::MaskGenerator::Pointer mask);
335 
339  void SetSecondaryMask(mitk::MaskGenerator::Pointer mask);
340 
343  void SetNBinsForHistogramStatistics(unsigned int nBins);
344 
348  unsigned int GetNBinsForHistogramStatistics() const;
349 
352  void SetBinSizeForHistogramStatistics(double binSize);
353 
357  double GetBinSizeForHistogramStatistics() const;
358 
363  StatisticsContainer::Pointer GetStatistics(unsigned int timeStep=0, unsigned int label=1);
364 
365  protected:
367  m_nBinsForHistogramStatistics = 100;
368  m_binSizeForHistogramStatistics = 10;
369  m_UseBinSizeOverNBins = false;
370  };
371 
372 
373  private:
374  template < typename TPixel, unsigned int VImageDimension > void InternalCalculateStatisticsUnmasked(
375  typename itk::Image< TPixel, VImageDimension >* image,
376  unsigned int timeStep);
377 
378  template < typename TPixel, unsigned int VImageDimension > typename HistogramType::Pointer InternalCalculateHistogramUnmasked(
379  typename itk::Image< TPixel, VImageDimension >* image,
380  double minVal,
381  double maxVal);
382 
383  template < typename TPixel, unsigned int VImageDimension > void InternalCalculateStatisticsMasked(
384  typename itk::Image< TPixel, VImageDimension >* image,
385  unsigned int timeStep);
386 
387  bool IsUpdateRequired(unsigned int timeStep) const;
388 
389  std::string GetNameOfClass()
390  {
391  return std::string("ImageStatisticsCalculator_v2");
392  }
393 
394  mitk::Image::Pointer m_Image;
395  mitk::Image::Pointer m_ImageTimeSlice;
396  mitk::Image::Pointer m_InternalImageForStatistics;
397 
398  mitk::MaskGenerator::Pointer m_MaskGenerator;
399  mitk::Image::Pointer m_InternalMask;
400 
401  mitk::MaskGenerator::Pointer m_SecondaryMaskGenerator;
402  mitk::Image::Pointer m_SecondaryMask;
403 
404  unsigned int m_nBinsForHistogramStatistics;
405  double m_binSizeForHistogramStatistics;
406  bool m_UseBinSizeOverNBins;
407 
408  std::vector<std::vector<StatisticsContainer::Pointer>> m_StatisticsByTimeStep;
409  std::vector<unsigned long> m_StatisticsUpdateTimePerTimeStep;
410  };
411 
412 }
413 #endif // MITKIMAGESTATISTICSCALCULATOR
414 
itk::SmartPointer< Self > Pointer
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
Class for common statistics, includig hotspot properties.
#define MITKIMAGESTATISTICS_EXPORT
itk::Statistics::Histogram< double > HistogramType
Class for calculating statistics and histogram for an (optionally masked) image.
Container class for storing the computed image statistics.
std::map< std::string, statisticsValueType > statisticsMapType
itk::SmartPointer< const Self > ConstPointer