Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImageStatisticsCalculator.cpp
Go to the documentation of this file.
1 
2 #include <limits>
3 #include <math.h>
4 
5 #include <itkImageToHistogramFilter.h>
6 #include <itkMaskedImageToHistogramFilter.h>
7 #include <itkHistogram.h>
8 #include <itkExtractImageFilter.h>
9 #include <itkImageRegionConstIterator.h>
10 #include <itkChangeInformationImageFilter.h>
11 #include <itkMinimumMaximumImageCalculator.h>
12 #include <itkMinimumMaximumImageFilter.h>
13 #include <itkMaskImageFilter.h>
14 #include <itkExceptionObject.h>
15 
17 #include <mitkImage.h>
19 #include <mitkImageAccessByItk.h>
20 #include <mitkImageToItk.h>
23 #include <mitkImageTimeSelector.h>
26 #include <mitkitkMaskImageFilter.h>
27 #include <mitkImageCast.h>
28 
29 
30 
31 #include <mitkMaskUtilities.h>
32 
33 #include "itkImageFileWriter.h"
34 
35 namespace mitk
36 {
37 
39  {
40  if (image != m_Image)
41  {
42  m_Image = image;
43  m_StatisticsByTimeStep.resize(m_Image->GetTimeSteps());
44  m_StatisticsUpdateTimePerTimeStep.resize(m_Image->GetTimeSteps());
45  std::fill(m_StatisticsUpdateTimePerTimeStep.begin(), m_StatisticsUpdateTimePerTimeStep.end(), 0);
46  this->Modified();
47  }
48  }
49 
51  {
52 
53  if (mask != m_MaskGenerator)
54  {
55  m_MaskGenerator = mask;
56  this->Modified();
57  }
58 
59  }
60 
62  {
63 
64  if (mask != m_SecondaryMaskGenerator)
65  {
66  m_SecondaryMaskGenerator = mask;
67  this->Modified();
68  }
69 
70  }
71 
72 
74  {
75  if (nBins != m_nBinsForHistogramStatistics)
76  {
77  m_nBinsForHistogramStatistics = nBins;
78  this->Modified();
79  this->m_UseBinSizeOverNBins = false;
80  }
81  if (m_UseBinSizeOverNBins)
82  {
83  this->Modified();
84  this->m_UseBinSizeOverNBins = false;
85  }
86  }
87 
89  {
90  return m_nBinsForHistogramStatistics;
91  }
92 
94  {
95  if (binSize != m_binSizeForHistogramStatistics)
96  {
97  m_binSizeForHistogramStatistics = binSize;
98  this->Modified();
99  this->m_UseBinSizeOverNBins = true;
100  }
101  if (!m_UseBinSizeOverNBins)
102  {
103  this->Modified();
104  this->m_UseBinSizeOverNBins = true;
105  }
106  }
107 
109  {
110  return m_binSizeForHistogramStatistics;
111  }
112 
114  {
115 
116  if (timeStep >= m_StatisticsByTimeStep.size())
117  {
118  mitkThrow() << "invalid timeStep in ImageStatisticsCalculator_v2::GetStatistics";
119  }
120 
121  if (m_Image.IsNull())
122  {
123  mitkThrow() << "no image";
124  }
125 
126  if (!m_Image->IsInitialized())
127  {
128  mitkThrow() << "Image not initialized!";
129  }
130 
131  if (IsUpdateRequired(timeStep))
132  {
133  if (m_MaskGenerator.IsNotNull())
134  {
135  m_MaskGenerator->SetTimeStep(timeStep);
136  m_InternalMask = m_MaskGenerator->GetMask();
137  if (m_MaskGenerator->GetReferenceImage().IsNotNull())
138  {
139  m_InternalImageForStatistics = m_MaskGenerator->GetReferenceImage();
140  }
141  else
142  {
143  m_InternalImageForStatistics = m_Image;
144  }
145  }
146  else
147  {
148  m_InternalImageForStatistics = m_Image;
149  }
150 
151  if (m_SecondaryMaskGenerator.IsNotNull())
152  {
153  m_SecondaryMaskGenerator->SetTimeStep(timeStep);
154  m_SecondaryMask = m_SecondaryMaskGenerator->GetMask();
155  }
156 
158  imgTimeSel->SetInput(m_InternalImageForStatistics);
159  imgTimeSel->SetTimeNr(timeStep);
160  imgTimeSel->UpdateLargestPossibleRegion();
161  m_ImageTimeSlice = imgTimeSel->GetOutput();
162 
163 
164  // Calculate statistics with/without mask
165  if (m_MaskGenerator.IsNull() && m_SecondaryMaskGenerator.IsNull())
166  {
167  // 1) calculate statistics unmasked:
168  AccessByItk_1(m_ImageTimeSlice, InternalCalculateStatisticsUnmasked, timeStep)
169 
170  }
171  else
172  {
173  // 2) calculate statistics masked
174  AccessByItk_1(m_ImageTimeSlice, InternalCalculateStatisticsMasked, timeStep)
175  }
176 
177 
178  //this->Modified();
179  }
180 
181  m_StatisticsUpdateTimePerTimeStep[timeStep] = m_StatisticsByTimeStep[timeStep][m_StatisticsByTimeStep[timeStep].size()-1]->GetMTime();
182 
183  for (std::vector<StatisticsContainer::Pointer>::iterator it = m_StatisticsByTimeStep[timeStep].begin(); it != m_StatisticsByTimeStep[timeStep].end(); ++it)
184  {
185  StatisticsContainer::Pointer statCont = *it;
186  if (statCont->GetLabel() == label)
187  {
188  return statCont->Clone();
189  }
190  }
191 
192  // these lines will ony be executed if the requested label could not be found!
193  MITK_WARN << "Invalid label: " << label << " in time step: " << timeStep;
194  return StatisticsContainer::New();
195  }
196 
197  template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator::InternalCalculateStatisticsUnmasked(
198  typename itk::Image< TPixel, VImageDimension >* image, unsigned int timeStep)
199  {
200  typedef typename itk::Image< TPixel, VImageDimension > ImageType;
201  typedef typename itk::ExtendedStatisticsImageFilter<ImageType> ImageStatisticsFilterType;
202  typedef typename itk::MinMaxImageFilterWithIndex<ImageType> MinMaxFilterType;
203 
205 
207  statisticsFilter->SetInput(image);
208  statisticsFilter->SetCoordinateTolerance(0.001);
209  statisticsFilter->SetDirectionTolerance(0.001);
210 
211  // TODO: this is single threaded. Implement our own image filter that does this multi threaded
212 // typename itk::MinimumMaximumImageCalculator<ImageType>::Pointer imgMinMaxFilter = itk::MinimumMaximumImageCalculator<ImageType>::New();
213 // imgMinMaxFilter->SetImage(image);
214 // imgMinMaxFilter->Compute();
215  vnl_vector<int> minIndex, maxIndex;
216 
217  typename MinMaxFilterType::Pointer minMaxFilter = MinMaxFilterType::New();
218  minMaxFilter->SetInput(image);
219  minMaxFilter->UpdateLargestPossibleRegion();
220  typename ImageType::PixelType minval = minMaxFilter->GetMin();
221  typename ImageType::PixelType maxval = minMaxFilter->GetMax();
222 
223  typename ImageType::IndexType tmpMinIndex = minMaxFilter->GetMinIndex();
224  typename ImageType::IndexType tmpMaxIndex = minMaxFilter->GetMaxIndex();
225 
226 // typename ImageType::IndexType tmpMinIndex = imgMinMaxFilter->GetIndexOfMinimum();
227 // typename ImageType::IndexType tmpMaxIndex = imgMinMaxFilter->GetIndexOfMaximum();
228 
229  minIndex.set_size(tmpMaxIndex.GetIndexDimension());
230  maxIndex.set_size(tmpMaxIndex.GetIndexDimension());
231 
232  for (unsigned int i=0; i < tmpMaxIndex.GetIndexDimension(); i++)
233  {
234  minIndex[i] = tmpMinIndex[i];
235  maxIndex[i] = tmpMaxIndex[i];
236  }
237 
238  statisticsResult->SetMinIndex(minIndex);
239  statisticsResult->SetMaxIndex(maxIndex);
240 
241  //convert m_binSize in m_nBins if necessary
242  unsigned int nBinsForHistogram;
243  if (m_UseBinSizeOverNBins)
244  {
245  nBinsForHistogram = std::max(static_cast<double>(std::ceil(maxval - minval)) / m_binSizeForHistogramStatistics, 10.); // do not allow less than 10 bins
246  }
247  else
248  {
249  nBinsForHistogram = m_nBinsForHistogramStatistics;
250  }
251 
252  statisticsFilter->SetHistogramParameters(nBinsForHistogram, minval, maxval);
253 
254  try
255  {
256  statisticsFilter->Update();
257  }
258  catch (const itk::ExceptionObject& e)
259  {
260  mitkThrow() << "Image statistics calculation failed due to following ITK Exception: \n " << e.what();
261  }
262 
263  // no mask, therefore just one label = the whole image
264  m_StatisticsByTimeStep[timeStep].resize(1);
265  statisticsResult->SetLabel(1);
266  statisticsResult->SetN(image->GetLargestPossibleRegion().GetNumberOfPixels());
267  statisticsResult->SetMean(statisticsFilter->GetMean());
268  statisticsResult->SetMin(statisticsFilter->GetMinimum());
269  statisticsResult->SetMax(statisticsFilter->GetMaximum());
270  statisticsResult->SetVariance(statisticsFilter->GetVariance());
271  statisticsResult->SetStd(statisticsFilter->GetSigma());
272  statisticsResult->SetSkewness(statisticsFilter->GetSkewness());
273  statisticsResult->SetKurtosis(statisticsFilter->GetKurtosis());
274  statisticsResult->SetRMS(std::sqrt(std::pow(statisticsFilter->GetMean(), 2.) + statisticsFilter->GetVariance())); // variance = sigma^2
275  statisticsResult->SetMPP(statisticsFilter->GetMPP());
276 
277  statisticsResult->SetEntropy(statisticsFilter->GetEntropy());
278  statisticsResult->SetMedian(statisticsFilter->GetMedian());
279  statisticsResult->SetUniformity(statisticsFilter->GetUniformity());
280  statisticsResult->SetUPP(statisticsFilter->GetUPP());
281  statisticsResult->SetHistogram(statisticsFilter->GetHistogram());
282 
283  m_StatisticsByTimeStep[timeStep][0] = statisticsResult;
284  }
285 
286 
287  template < typename TPixel, unsigned int VImageDimension > void ImageStatisticsCalculator::InternalCalculateStatisticsMasked(
288  typename itk::Image< TPixel, VImageDimension >* image,
289  unsigned int timeStep)
290  {
291  typedef itk::Image< TPixel, VImageDimension > ImageType;
292  typedef itk::Image< MaskPixelType, VImageDimension > MaskType;
293  typedef typename MaskType::PixelType LabelPixelType;
294  typedef itk::ExtendedLabelStatisticsImageFilter< ImageType, MaskType > ImageStatisticsFilterType;
295  typedef MaskUtilities< TPixel, VImageDimension > MaskUtilType;
296  typedef typename itk::MinMaxLabelImageFilterWithIndex<ImageType, MaskType> MinMaxLabelFilterType;
297  typedef typename ImageType::PixelType InputImgPixelType;
298 
299  // workaround: if m_SecondaryMaskGenerator ist not null but m_MaskGenerator is! (this is the case if we request a 'ignore zuero valued pixels'
300  // mask in the gui but do not define a primary mask)
301  bool swapMasks = false;
302  if (m_SecondaryMask.IsNotNull() && m_InternalMask.IsNull())
303  {
304  m_InternalMask = m_SecondaryMask;
305  m_SecondaryMask = nullptr;
306  swapMasks = true;
307  }
308 
309  // maskImage has to have the same dimension as image
310  typename MaskType::Pointer maskImage = MaskType::New();
311  try {
312  // try to access the pixel values directly (no copying or casting). Only works if mask pixels are of pixelType unsigned short
313  maskImage = ImageToItkImage< MaskPixelType, VImageDimension >(m_InternalMask);
314  }
315  catch (itk::ExceptionObject & e)
316 
317  {
318  // if the pixel type of the mask is not short, then we have to make a copy of m_InternalMask (and cast the values)
319  CastToItkImage(m_InternalMask, maskImage);
320  }
321 
322  // if we have a secondary mask (say a ignoreZeroPixelMask) we need to combine the masks (corresponds to AND)
323  if (m_SecondaryMask.IsNotNull())
324  {
325  // dirty workaround for a bug when pf mask + any other mask is used in conjunction. We need a proper fix for this (Fabian Isensee is responsible and probably working on it!)
326  if (m_InternalMask->GetDimension() == 2 && (m_SecondaryMask->GetDimension() == 3 || m_SecondaryMask->GetDimension() == 4))
327  {
328  mitk::Image::Pointer old_img = m_SecondaryMaskGenerator->GetReferenceImage();
329  m_SecondaryMaskGenerator->SetInputImage(m_MaskGenerator->GetReferenceImage());
330  m_SecondaryMask = m_SecondaryMaskGenerator->GetMask();
331  m_SecondaryMaskGenerator->SetInputImage(old_img);
332  }
333  typename MaskType::Pointer secondaryMaskImage = MaskType::New();
334  secondaryMaskImage = ImageToItkImage< MaskPixelType, VImageDimension >(m_SecondaryMask);
335 
336  // secondary mask should be a ignore zero value pixel mask derived from image. it has to be cropped to the mask region (which may be planar or simply smaller)
338  secondaryMaskMaskUtil->SetImage(secondaryMaskImage.GetPointer());
339  secondaryMaskMaskUtil->SetMask(maskImage.GetPointer());
340  typename MaskType::Pointer adaptedSecondaryMaskImage = secondaryMaskMaskUtil->ExtractMaskImageRegion();
341 
343  maskFilter->SetInput1(maskImage);
344  maskFilter->SetInput2(adaptedSecondaryMaskImage);
345  maskFilter->SetMaskingValue(1); // all pixels of maskImage where secondaryMaskImage==1 will be kept, all the others are set to 0
346  maskFilter->UpdateLargestPossibleRegion();
347  maskImage = maskFilter->GetOutput();
348  }
349 
350  typename MaskUtilType::Pointer maskUtil = MaskUtilType::New();
351  maskUtil->SetImage(image);
352  maskUtil->SetMask(maskImage.GetPointer());
353 
354  // if mask is smaller than image, extract the image region where the mask is
355  typename ImageType::Pointer adaptedImage = ImageType::New();
356 
357  adaptedImage = maskUtil->ExtractMaskImageRegion(); // this also checks mask sanity
358 
359  // find min, max, minindex and maxindex
361  minMaxFilter->SetInput(adaptedImage);
362  minMaxFilter->SetLabelInput(maskImage);
363  minMaxFilter->UpdateLargestPossibleRegion();
364 
365  // set histogram parameters for each label individually (min/max may be different for each label)
366  typedef typename std::map<LabelPixelType, InputImgPixelType> MapType;
367  typedef typename std::pair<LabelPixelType, InputImgPixelType> PairType;
368 
369  std::vector<LabelPixelType> relevantLabels = minMaxFilter->GetRelevantLabels();
370  MapType minVals;
371  MapType maxVals;
372  std::map<LabelPixelType, unsigned int> nBins;
373 
374  for (LabelPixelType label:relevantLabels)
375  {
376  minVals.insert(PairType(label, minMaxFilter->GetMin(label)));
377  maxVals.insert(PairType(label, minMaxFilter->GetMax(label)));
378 
379  unsigned int nBinsForHistogram;
380  if (m_UseBinSizeOverNBins)
381  {
382  nBinsForHistogram = std::max(static_cast<double>(std::ceil(minMaxFilter->GetMax(label) - minMaxFilter->GetMin(label))) / m_binSizeForHistogramStatistics, 10.); // do not allow less than 10 bins
383  }
384  else
385  {
386  nBinsForHistogram = m_nBinsForHistogramStatistics;
387  }
388 
389  nBins.insert(typename std::pair<LabelPixelType, unsigned int>(label, nBinsForHistogram));
390  }
391 
392  typename ImageStatisticsFilterType::Pointer imageStatisticsFilter = ImageStatisticsFilterType::New();
393  imageStatisticsFilter->SetDirectionTolerance(0.001);
394  imageStatisticsFilter->SetCoordinateTolerance(0.001);
395  imageStatisticsFilter->SetInput(adaptedImage);
396  imageStatisticsFilter->SetLabelInput(maskImage);
397  imageStatisticsFilter->SetHistogramParametersForLabels(nBins, minVals, maxVals);
398  imageStatisticsFilter->Update();
399 
400  std::list<int> labels = imageStatisticsFilter->GetRelevantLabels();
401  std::list<int>::iterator it = labels.begin();
402  m_StatisticsByTimeStep[timeStep].resize(0);
403 
404  while(it != labels.end())
405  {
407 
408  // find min, max, minindex and maxindex
409  // make sure to only look in the masked region, use a masker for this
410 
411  vnl_vector<int> minIndex, maxIndex;
412  mitk::Point3D worldCoordinateMin;
413  mitk::Point3D worldCoordinateMax;
414  mitk::Point3D indexCoordinateMin;
415  mitk::Point3D indexCoordinateMax;
416  m_InternalImageForStatistics->GetGeometry()->IndexToWorld(minMaxFilter->GetMinIndex(*it), worldCoordinateMin);
417  m_InternalImageForStatistics->GetGeometry()->IndexToWorld(minMaxFilter->GetMaxIndex(*it), worldCoordinateMax);
418  m_Image->GetGeometry()->WorldToIndex(worldCoordinateMin, indexCoordinateMin);
419  m_Image->GetGeometry()->WorldToIndex(worldCoordinateMax, indexCoordinateMax);
420 
421  //typename ImageType::IndexType tmpMinIndex = minMaxFilter->GetMinIndex(*it);
422  //typename ImageType::IndexType tmpMaxIndex = minMaxFilter->GetMaxIndex(*it);
423 
424  //minIndex.set_size(tmpMaxIndex.GetIndexDimension());
425  //maxIndex.set_size(tmpMaxIndex.GetIndexDimension());
426  minIndex.set_size(3);
427  maxIndex.set_size(3);
428 
429  //for (unsigned int i=0; i < tmpMaxIndex.GetIndexDimension(); i++)
430  for (unsigned int i=0; i < 3; i++)
431  {
432  //minIndex[i] = tmpMinIndex[i] + (maskImage->GetOrigin()[i] - image->GetOrigin()[i]) / (double) maskImage->GetSpacing()[i];
433  //maxIndex[i] = tmpMaxIndex[i] + (maskImage->GetOrigin()[i] - image->GetOrigin()[i]) / (double) maskImage->GetSpacing()[i];
434  minIndex[i] = indexCoordinateMin[i];
435  maxIndex[i] = indexCoordinateMax[i];
436  }
437 
438  statisticsResult->SetMinIndex(minIndex);
439  statisticsResult->SetMaxIndex(maxIndex);
440 
441  // just debug
442  TPixel min_Filter = minMaxFilter->GetMin(*it);
443  TPixel max_Filter = minMaxFilter->GetMax(*it);
444  TPixel min_Itk = imageStatisticsFilter->GetMinimum(*it);
445  TPixel max_Itk = imageStatisticsFilter->GetMaximum(*it);
446 
447  assert(abs(minMaxFilter->GetMax(*it) - imageStatisticsFilter->GetMaximum(*it)) < mitk::eps);
448  assert(abs(minMaxFilter->GetMin(*it) - imageStatisticsFilter->GetMinimum(*it)) < mitk::eps);
449 
450 
451  statisticsResult->SetN(imageStatisticsFilter->GetSum(*it) / (double) imageStatisticsFilter->GetMean(*it));
452  statisticsResult->SetMean(imageStatisticsFilter->GetMean(*it));
453  statisticsResult->SetMin(imageStatisticsFilter->GetMinimum(*it));
454  statisticsResult->SetMax(imageStatisticsFilter->GetMaximum(*it));
455  statisticsResult->SetVariance(imageStatisticsFilter->GetVariance(*it));
456  statisticsResult->SetStd(imageStatisticsFilter->GetSigma(*it));
457  statisticsResult->SetSkewness(imageStatisticsFilter->GetSkewness(*it));
458  statisticsResult->SetKurtosis(imageStatisticsFilter->GetKurtosis(*it));
459  statisticsResult->SetRMS(std::sqrt(std::pow(imageStatisticsFilter->GetMean(*it), 2.) + imageStatisticsFilter->GetVariance(*it))); // variance = sigma^2
460  statisticsResult->SetMPP(imageStatisticsFilter->GetMPP(*it));
461  statisticsResult->SetLabel(*it);
462 
463  statisticsResult->SetEntropy(imageStatisticsFilter->GetEntropy(*it));
464  statisticsResult->SetMedian(imageStatisticsFilter->GetMedian(*it));
465  statisticsResult->SetUniformity(imageStatisticsFilter->GetUniformity(*it));
466  statisticsResult->SetUPP(imageStatisticsFilter->GetUPP(*it));
467  statisticsResult->SetHistogram(imageStatisticsFilter->GetHistogram(*it));
468 
469  m_StatisticsByTimeStep[timeStep].push_back(statisticsResult);
470  ++it;
471  }
472 
473  // swap maskGenerators back
474  if (swapMasks)
475  {
476  m_SecondaryMask = m_InternalMask;
477  m_InternalMask = nullptr;
478  }
479  }
480 
481  bool ImageStatisticsCalculator::IsUpdateRequired(unsigned int timeStep) const
482  {
483  unsigned long thisClassTimeStamp = this->GetMTime();
484  unsigned long inputImageTimeStamp = m_Image->GetMTime();
485  unsigned long statisticsTimeStamp = m_StatisticsUpdateTimePerTimeStep[timeStep];
486 
487  if (thisClassTimeStamp > statisticsTimeStamp) // inputs have changed
488  {
489  return true;
490  }
491 
492  if (inputImageTimeStamp > statisticsTimeStamp) // image has changed
493  {
494  return true;
495  }
496 
497  if (m_MaskGenerator.IsNotNull())
498  {
499  unsigned long maskGeneratorTimeStamp = m_MaskGenerator->GetMTime();
500  if (maskGeneratorTimeStamp > statisticsTimeStamp) // there is a mask generator and it has changed
501  {
502  return true;
503  }
504  }
505 
506  if (m_SecondaryMaskGenerator.IsNotNull())
507  {
508  unsigned long maskGeneratorTimeStamp = m_SecondaryMaskGenerator->GetMTime();
509  if (maskGeneratorTimeStamp > statisticsTimeStamp) // there is a secondary mask generator and it has changed
510  {
511  return true;
512  }
513  }
514 
515  return false;
516  }
517 
518 
520  m_N(nan("")),
521  m_Mean(nan("")),
522  m_Min(nan("")),
523  m_Max(nan("")),
524  m_Std(nan("")),
525  m_Variance(nan("")),
526  m_Skewness(nan("")),
527  m_Kurtosis(nan("")),
528  m_RMS(nan("")),
529  m_MPP(nan("")),
530  m_Median(nan("")),
531  m_Uniformity(nan("")),
532  m_UPP(nan("")),
533  m_Entropy(nan(""))
534  {
535  m_minIndex.set_size(0);
536  m_maxIndex.set_size(0);
537  }
538 
540  {
542 
543  statisticsAsMap["N"] = m_N;
544  statisticsAsMap["Mean"] = m_Mean;
545  statisticsAsMap["Min"] = m_Min;
546  statisticsAsMap["Max"] = m_Max;
547  statisticsAsMap["StandardDeviation"] = m_Std;
548  statisticsAsMap["Variance"] = m_Variance;
549  statisticsAsMap["Skewness"] = m_Skewness;
550  statisticsAsMap["Kurtosis"] = m_Kurtosis;
551  statisticsAsMap["RMS"] = m_RMS;
552  statisticsAsMap["MPP"] = m_MPP;
553  statisticsAsMap["Median"] = m_Median;
554  statisticsAsMap["Uniformity"] = m_Uniformity;
555  statisticsAsMap["UPP"] = m_UPP;
556  statisticsAsMap["Entropy"] = m_Entropy;
557  statisticsAsMap["Label"] = m_Label;
558 
559  return statisticsAsMap;
560  }
561 
562 
564  {
565  m_N = nan("");
566  m_Mean = nan("");
567  m_Min = nan("");
568  m_Max = nan("");
569  m_Std = nan("");
570  m_Variance = nan("");
571  m_Skewness = nan("");
572  m_Kurtosis = nan("");
573  m_RMS = nan("");
574  m_MPP = nan("");
575  m_Median = nan("");
576  m_Uniformity = nan("");
577  m_UPP = nan("");
578  m_Entropy = nan("");
579  m_Histogram = HistogramType::New();
580  m_minIndex.set_size(0);
581  m_maxIndex.set_size(0);
582  m_Label = 0;
583  }
584 
586  {
587  ImageStatisticsCalculator::statisticsMapType statMap = this->GetStatisticsAsMap();
588  // print all map key value pairs
589  // const auto& val:statMap
590  for (auto it = statMap.begin(); it != statMap.end(); ++it)
591  {
592  std::cout << it->first << ": " << it->second << std::endl;
593  }
594 
595  // print the min and max index
596  std::cout << "Min Index:" << std::endl;
597  for (auto it = this->GetMinIndex().begin(); it != this->GetMinIndex().end(); ++it)
598  {
599  std::cout << *it << " ";
600  }
601  std::cout << std::endl;
602 
603  // print the min and max index
604  std::cout << "Max Index:" << std::endl;
605  for (auto it = this->GetMaxIndex().begin(); it != this->GetMaxIndex().end(); ++it)
606  {
607  std::cout << *it << " ";
608  }
609  std::cout << std::endl;
610  }
611 
613  {
614  std::string res = "";
615  ImageStatisticsCalculator::statisticsMapType statMap = this->GetStatisticsAsMap();
616  // print all map key value pairs
617  // const auto& val:statMap
618  for (auto it = statMap.begin(); it != statMap.end(); ++it)
619  {
620  res += std::string(it->first) + ": " + std::to_string(it->second) + "\n";
621  }
622 
623  // print the min and max index
624  res += "Min Index:" + std::string("\n");
625  for (auto it = this->GetMinIndex().begin(); it != this->GetMinIndex().end(); it++)
626  {
627  res += std::to_string(*it) + std::string(" ");
628  }
629  res += "\n";
630 
631  // print the min and max index
632  res += "Max Index:" + std::string("\n");
633  for (auto it = this->GetMaxIndex().begin(); it != this->GetMaxIndex().end(); it++)
634  {
635  res += std::to_string(*it) + " ";
636  }
637  res += "\n";
638  return res;
639  }
640 
641 
642 }
itk::SmartPointer< Self > Pointer
statisticsMapType GetStatisticsAsMap()
Returns a std::map containing all real valued statisti...
Extension of the itkLabelStatisticsImageFilter that also calculates the Skewness,Kurtosis,Entropy,Uniformity.
DataCollection - Class to facilitate loading/accessing structured data.
StatisticsContainer::Pointer GetStatistics(unsigned int timeStep=0, unsigned int label=1)
Returns the statistics for label label and timeStep timeStep. If these requested statistics are not c...
unsigned int GetNBinsForHistogramStatistics() const
Retrieve the number of bins used for histogram statistics. Careful: The return value does not indicat...
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
void SetInputImage(mitk::Image::Pointer image)
Set the image for which the statistics are to be computed.
static Pointer New()
void SetNBinsForHistogramStatistics(unsigned int nBins)
Set number of bins to be used for histogram statistics. If Bin size is set after number of bins...
map::core::discrete::Elements< 3 >::InternalImageType ImageType
#define MITK_WARN
Definition: mitkLogMacros.h:23
void SetSecondaryMask(mitk::MaskGenerator::Pointer mask)
Set this if more than one mask should be applied (for instance if a IgnorePixelValueMask were to be u...
#define mitkThrow()
void Print()
Creates a StatisticsMapType containing all real valued statistics stored in this class (= all statist...
static T max(T x, T y)
Definition: svm.cpp:70
void SetMask(mitk::MaskGenerator::Pointer mask)
Set the mask generator that creates the mask which is to be used to calculate statistics. If no more mask is desired simply set.
std::map< std::string, statisticsValueType > statisticsMapType
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
Extension of the itkStatisticsImageFilter that also calculates the Skewness and Kurtosis.
std::string GetAsString()
Generates a string that contains all real valued statistics stored in this class (= all statistics ex...
static Pointer New()
MITKCORE_EXPORT const ScalarType eps
unsigned short PixelType
double GetBinSizeForHistogramStatistics() const
Retrieve the bin size for histogram statistics. Careful: The return value does not indicate whether N...
void SetBinSizeForHistogramStatistics(double binSize)
Set bin size to be used for histogram statistics. If nbins is set after bin size, nbins will be used ...
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.