Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
Medical Imaging Interaction Toolkit
mitkImageStatisticsCalculator.cpp
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 
16 #include <mitkImage.h>
17 #include <mitkImageAccessByItk.h>
18 #include <mitkImageCast.h>
20 #include <mitkImageTimeSelector.h>
21 #include <mitkImageToItk.h>
22 #include <mitkMaskUtilities.h>
25 #include <mitkitkMaskImageFilter.h>
26 
27 namespace mitk
28 {
30  {
31  if (image != m_Image)
32  {
33  m_Image = image;
34  this->Modified();
35  }
36  }
37 
39  {
40  if (mask != m_MaskGenerator)
41  {
42  m_MaskGenerator = mask;
43  this->Modified();
44  }
45  }
46 
48  {
49  if (mask != m_SecondaryMaskGenerator)
50  {
51  m_SecondaryMaskGenerator = mask;
52  this->Modified();
53  }
54  }
55 
57  {
58  if (nBins != m_nBinsForHistogramStatistics)
59  {
60  m_nBinsForHistogramStatistics = nBins;
61  this->Modified();
62  this->m_UseBinSizeOverNBins = false;
63  }
64  if (m_UseBinSizeOverNBins)
65  {
66  this->Modified();
67  this->m_UseBinSizeOverNBins = false;
68  }
69  }
70 
72  {
73  return m_nBinsForHistogramStatistics;
74  }
75 
77  {
78  if (binSize != m_binSizeForHistogramStatistics)
79  {
80  m_binSizeForHistogramStatistics = binSize;
81  this->Modified();
82  this->m_UseBinSizeOverNBins = true;
83  }
84  if (!m_UseBinSizeOverNBins)
85  {
86  this->Modified();
87  this->m_UseBinSizeOverNBins = true;
88  }
89  }
90 
91  double ImageStatisticsCalculator::GetBinSizeForHistogramStatistics() const { return m_binSizeForHistogramStatistics; }
92 
94  {
95  if (m_Image.IsNull())
96  {
97  mitkThrow() << "no image";
98  }
99 
100  if (!m_Image->IsInitialized())
101  {
102  mitkThrow() << "Image not initialized!";
103  }
104 
105  if (IsUpdateRequired(label))
106  {
107  auto timeGeometry = m_Image->GetTimeGeometry();
108  // always compute statistics on all timesteps
109  for (unsigned int timeStep = 0; timeStep < m_Image->GetTimeSteps(); timeStep++)
110  {
111  if (m_MaskGenerator.IsNotNull())
112  {
113  m_MaskGenerator->SetTimeStep(timeStep);
114  //See T25625: otherwise, the mask is not computed again after setting a different time step
115  m_MaskGenerator->Modified();
116  m_InternalMask = m_MaskGenerator->GetMask();
117  if (m_MaskGenerator->GetReferenceImage().IsNotNull())
118  {
119  m_InternalImageForStatistics = m_MaskGenerator->GetReferenceImage();
120  }
121  else
122  {
123  m_InternalImageForStatistics = m_Image;
124  }
125  }
126  else
127  {
128  m_InternalImageForStatistics = m_Image;
129  }
130 
131  if (m_SecondaryMaskGenerator.IsNotNull())
132  {
133  m_SecondaryMaskGenerator->SetTimeStep(timeStep);
134  m_SecondaryMask = m_SecondaryMaskGenerator->GetMask();
135  }
136 
138  imgTimeSel->SetInput(m_InternalImageForStatistics);
139  imgTimeSel->SetTimeNr(timeStep);
140  imgTimeSel->UpdateLargestPossibleRegion();
141  imgTimeSel->Update();
142  m_ImageTimeSlice = imgTimeSel->GetOutput();
143 
144  // Calculate statistics with/without mask
145  if (m_MaskGenerator.IsNull() && m_SecondaryMaskGenerator.IsNull())
146  {
147  // 1) calculate statistics unmasked:
148  AccessByItk_2(m_ImageTimeSlice, InternalCalculateStatisticsUnmasked, timeGeometry, timeStep)
149  }
150  else
151  {
152  // 2) calculate statistics masked
153  AccessByItk_2(m_ImageTimeSlice, InternalCalculateStatisticsMasked, timeGeometry, timeStep)
154  }
155  }
156  }
157 
158  auto it = m_StatisticContainers.find(label);
159  if (it != m_StatisticContainers.end())
160  {
161  return (it->second).GetPointer();
162  }
163  else
164  {
165  mitkThrow() << "unknown label";
166  return nullptr;
167  }
168  }
169 
170  template <typename TPixel, unsigned int VImageDimension>
171  void ImageStatisticsCalculator::InternalCalculateStatisticsUnmasked(
172  typename itk::Image<TPixel, VImageDimension> *image, const TimeGeometry *timeGeometry, TimeStepType timeStep)
173  {
174  typedef typename itk::Image<TPixel, VImageDimension> ImageType;
175  typedef typename itk::ExtendedStatisticsImageFilter<ImageType> ImageStatisticsFilterType;
176  typedef typename itk::MinMaxImageFilterWithIndex<ImageType> MinMaxFilterType;
177 
178  // reset statistics container if exists
179  ImageStatisticsContainer::Pointer statisticContainerForImage;
180  LabelIndex labelNoMask = 1;
181  auto it = m_StatisticContainers.find(labelNoMask);
182  if (it != m_StatisticContainers.end())
183  {
184  statisticContainerForImage = it->second;
185  }
186  else
187  {
188  statisticContainerForImage = ImageStatisticsContainer::New();
189  statisticContainerForImage->SetTimeGeometry(const_cast<mitk::TimeGeometry*>(timeGeometry));
190  m_StatisticContainers.emplace(labelNoMask, statisticContainerForImage);
191  }
192 
194 
195  typename ImageStatisticsFilterType::Pointer statisticsFilter = ImageStatisticsFilterType::New();
196  statisticsFilter->SetInput(image);
197  statisticsFilter->SetCoordinateTolerance(0.001);
198  statisticsFilter->SetDirectionTolerance(0.001);
199 
200  // TODO: this is single threaded. Implement our own image filter that does this multi threaded
201  // typename itk::MinimumMaximumImageCalculator<ImageType>::Pointer imgMinMaxFilter =
202  // itk::MinimumMaximumImageCalculator<ImageType>::New(); imgMinMaxFilter->SetImage(image);
203  // imgMinMaxFilter->Compute();
204  vnl_vector<int> minIndex, maxIndex;
205 
206  typename MinMaxFilterType::Pointer minMaxFilter = MinMaxFilterType::New();
207  minMaxFilter->SetInput(image);
208  minMaxFilter->UpdateLargestPossibleRegion();
209  typename ImageType::PixelType minval = minMaxFilter->GetMin();
210  typename ImageType::PixelType maxval = minMaxFilter->GetMax();
211 
212  typename ImageType::IndexType tmpMinIndex = minMaxFilter->GetMinIndex();
213  typename ImageType::IndexType tmpMaxIndex = minMaxFilter->GetMaxIndex();
214 
215  // typename ImageType::IndexType tmpMinIndex = imgMinMaxFilter->GetIndexOfMinimum();
216  // typename ImageType::IndexType tmpMaxIndex = imgMinMaxFilter->GetIndexOfMaximum();
217 
218  minIndex.set_size(tmpMaxIndex.GetIndexDimension());
219  maxIndex.set_size(tmpMaxIndex.GetIndexDimension());
220 
221  for (unsigned int i = 0; i < tmpMaxIndex.GetIndexDimension(); i++)
222  {
223  minIndex[i] = tmpMinIndex[i];
224  maxIndex[i] = tmpMaxIndex[i];
225  }
226 
227  statObj.AddStatistic(mitk::ImageStatisticsConstants::MINIMUMPOSITION(), minIndex);
228  statObj.AddStatistic(mitk::ImageStatisticsConstants::MAXIMUMPOSITION(), maxIndex);
229 
230  // convert m_binSize in m_nBins if necessary
231  unsigned int nBinsForHistogram;
232  if (m_UseBinSizeOverNBins)
233  {
234  nBinsForHistogram = std::max(static_cast<double>(std::ceil(maxval - minval)) / m_binSizeForHistogramStatistics,
235  10.); // do not allow less than 10 bins
236  }
237  else
238  {
239  nBinsForHistogram = m_nBinsForHistogramStatistics;
240  }
241 
242  statisticsFilter->SetHistogramParameters(nBinsForHistogram, minval, maxval);
243 
244  try
245  {
246  statisticsFilter->Update();
247  }
248  catch (const itk::ExceptionObject &e)
249  {
250  mitkThrow() << "Image statistics calculation failed due to following ITK Exception: \n " << e.what();
251  }
252 
253  auto voxelVolume = GetVoxelVolume<TPixel, VImageDimension>(image);
254 
255  auto numberOfPixels = image->GetLargestPossibleRegion().GetNumberOfPixels();
256  auto volume = static_cast<double>(numberOfPixels) * voxelVolume;
257  auto variance = statisticsFilter->GetSigma() * statisticsFilter->GetSigma();
258  auto rms =
259  std::sqrt(std::pow(statisticsFilter->GetMean(), 2.) + statisticsFilter->GetVariance()); // variance = sigma^2
260 
261  statObj.AddStatistic(mitk::ImageStatisticsConstants::NUMBEROFVOXELS(),
262  static_cast<ImageStatisticsContainer::VoxelCountType>(numberOfPixels));
263  statObj.AddStatistic(mitk::ImageStatisticsConstants::VOLUME(), volume);
264  statObj.AddStatistic(mitk::ImageStatisticsConstants::MEAN(), statisticsFilter->GetMean());
265  statObj.AddStatistic(mitk::ImageStatisticsConstants::MINIMUM(),
266  static_cast<ImageStatisticsContainer::RealType>(statisticsFilter->GetMinimum()));
267  statObj.AddStatistic(mitk::ImageStatisticsConstants::MAXIMUM(),
268  static_cast<ImageStatisticsContainer::RealType>(statisticsFilter->GetMaximum()));
269  statObj.AddStatistic(mitk::ImageStatisticsConstants::STANDARDDEVIATION(), statisticsFilter->GetSigma());
270  statObj.AddStatistic(mitk::ImageStatisticsConstants::VARIANCE(), variance);
271  statObj.AddStatistic(mitk::ImageStatisticsConstants::SKEWNESS(), statisticsFilter->GetSkewness());
272  statObj.AddStatistic(mitk::ImageStatisticsConstants::KURTOSIS(), statisticsFilter->GetKurtosis());
273  statObj.AddStatistic(mitk::ImageStatisticsConstants::RMS(), rms);
274  statObj.AddStatistic(mitk::ImageStatisticsConstants::MPP(), statisticsFilter->GetMPP());
275  statObj.AddStatistic(mitk::ImageStatisticsConstants::ENTROPY(), statisticsFilter->GetEntropy());
276  statObj.AddStatistic(mitk::ImageStatisticsConstants::MEDIAN(), statisticsFilter->GetMedian());
277  statObj.AddStatistic(mitk::ImageStatisticsConstants::UNIFORMITY(), statisticsFilter->GetUniformity());
278  statObj.AddStatistic(mitk::ImageStatisticsConstants::UPP(), statisticsFilter->GetUPP());
279  statObj.m_Histogram = statisticsFilter->GetHistogram().GetPointer();
280  statisticContainerForImage->SetStatisticsForTimeStep(timeStep, statObj);
281  }
282 
283  template <typename TPixel, unsigned int VImageDimension>
284  double ImageStatisticsCalculator::GetVoxelVolume(typename itk::Image<TPixel, VImageDimension> *image) const
285  {
286  auto spacing = image->GetSpacing();
287  double voxelVolume = 1.;
288  for (unsigned int i = 0; i < image->GetImageDimension(); i++)
289  {
290  voxelVolume *= spacing[i];
291  }
292  return voxelVolume;
293  }
294 
295  template <typename TPixel, unsigned int VImageDimension>
296  void ImageStatisticsCalculator::InternalCalculateStatisticsMasked(typename itk::Image<TPixel, VImageDimension> *image,
297  const TimeGeometry *timeGeometry,
298  unsigned int timeStep)
299  {
300  typedef itk::Image<TPixel, VImageDimension> ImageType;
301  typedef itk::Image<MaskPixelType, VImageDimension> MaskType;
302  typedef typename MaskType::PixelType LabelPixelType;
303  typedef itk::ExtendedLabelStatisticsImageFilter<ImageType, MaskType> ImageStatisticsFilterType;
304  typedef MaskUtilities<TPixel, VImageDimension> MaskUtilType;
305  typedef typename itk::MinMaxLabelImageFilterWithIndex<ImageType, MaskType> MinMaxLabelFilterType;
306  typedef typename ImageType::PixelType InputImgPixelType;
307 
308  // workaround: if m_SecondaryMaskGenerator ist not null but m_MaskGenerator is! (this is the case if we request a
309  // 'ignore zuero valued pixels' mask in the gui but do not define a primary mask)
310  bool swapMasks = false;
311  if (m_SecondaryMask.IsNotNull() && m_InternalMask.IsNull())
312  {
313  m_InternalMask = m_SecondaryMask;
314  m_SecondaryMask = nullptr;
315  swapMasks = true;
316  }
317 
318  // maskImage has to have the same dimension as image
319  typename MaskType::Pointer maskImage = MaskType::New();
320  try
321  {
322  // try to access the pixel values directly (no copying or casting). Only works if mask pixels are of pixelType
323  // unsigned short
324  maskImage = ImageToItkImage<MaskPixelType, VImageDimension>(m_InternalMask);
325  }
326  catch (const itk::ExceptionObject &)
327 
328  {
329  // if the pixel type of the mask is not short, then we have to make a copy of m_InternalMask (and cast the values)
330  CastToItkImage(m_InternalMask, maskImage);
331  }
332 
333  // if we have a secondary mask (say a ignoreZeroPixelMask) we need to combine the masks (corresponds to AND)
334  if (m_SecondaryMask.IsNotNull())
335  {
336  // dirty workaround for a bug when pf mask + any other mask is used in conjunction. We need a proper fix for this
337  // (Fabian Isensee is responsible and probably working on it!)
338  if (m_InternalMask->GetDimension() == 2 &&
339  (m_SecondaryMask->GetDimension() == 3 || m_SecondaryMask->GetDimension() == 4))
340  {
341  mitk::Image::ConstPointer old_img = m_SecondaryMaskGenerator->GetReferenceImage();
342  m_SecondaryMaskGenerator->SetInputImage(m_MaskGenerator->GetReferenceImage());
343  m_SecondaryMask = m_SecondaryMaskGenerator->GetMask();
344  m_SecondaryMaskGenerator->SetInputImage(old_img);
345  }
346  typename MaskType::Pointer secondaryMaskImage = MaskType::New();
347  secondaryMaskImage = ImageToItkImage<MaskPixelType, VImageDimension>(m_SecondaryMask);
348 
349  // secondary mask should be a ignore zero value pixel mask derived from image. it has to be cropped to the mask
350  // region (which may be planar or simply smaller)
351  typename MaskUtilities<MaskPixelType, VImageDimension>::Pointer secondaryMaskMaskUtil =
353  secondaryMaskMaskUtil->SetImage(secondaryMaskImage.GetPointer());
354  secondaryMaskMaskUtil->SetMask(maskImage.GetPointer());
355  typename MaskType::Pointer adaptedSecondaryMaskImage = secondaryMaskMaskUtil->ExtractMaskImageRegion();
356 
359  maskFilter->SetInput1(maskImage);
360  maskFilter->SetInput2(adaptedSecondaryMaskImage);
361  maskFilter->SetMaskingValue(
362  1); // all pixels of maskImage where secondaryMaskImage==1 will be kept, all the others are set to 0
363  maskFilter->UpdateLargestPossibleRegion();
364  maskImage = maskFilter->GetOutput();
365  }
366 
367  typename MaskUtilType::Pointer maskUtil = MaskUtilType::New();
368  maskUtil->SetImage(image);
369  maskUtil->SetMask(maskImage.GetPointer());
370 
371  // if mask is smaller than image, extract the image region where the mask is
372  typename ImageType::Pointer adaptedImage = ImageType::New();
373 
374  adaptedImage = maskUtil->ExtractMaskImageRegion(); // this also checks mask sanity
375 
376  // find min, max, minindex and maxindex
377  typename MinMaxLabelFilterType::Pointer minMaxFilter = MinMaxLabelFilterType::New();
378  minMaxFilter->SetInput(adaptedImage);
379  minMaxFilter->SetLabelInput(maskImage);
380  minMaxFilter->UpdateLargestPossibleRegion();
381 
382  // set histogram parameters for each label individually (min/max may be different for each label)
383  typedef typename std::map<LabelPixelType, InputImgPixelType> MapType;
384  typedef typename std::pair<LabelPixelType, InputImgPixelType> PairType;
385 
386  std::vector<LabelPixelType> relevantLabels = minMaxFilter->GetRelevantLabels();
387  MapType minVals;
388  MapType maxVals;
389  std::map<LabelPixelType, unsigned int> nBins;
390 
391  for (LabelPixelType label : relevantLabels)
392  {
393  minVals.insert(PairType(label, minMaxFilter->GetMin(label)));
394  maxVals.insert(PairType(label, minMaxFilter->GetMax(label)));
395 
396  unsigned int nBinsForHistogram;
397  if (m_UseBinSizeOverNBins)
398  {
399  nBinsForHistogram =
400  std::max(static_cast<double>(std::ceil(minMaxFilter->GetMax(label) - minMaxFilter->GetMin(label))) /
401  m_binSizeForHistogramStatistics,
402  10.); // do not allow less than 10 bins
403  }
404  else
405  {
406  nBinsForHistogram = m_nBinsForHistogramStatistics;
407  }
408 
409  nBins.insert(typename std::pair<LabelPixelType, unsigned int>(label, nBinsForHistogram));
410  }
411 
412  typename ImageStatisticsFilterType::Pointer imageStatisticsFilter = ImageStatisticsFilterType::New();
413  imageStatisticsFilter->SetDirectionTolerance(0.001);
414  imageStatisticsFilter->SetCoordinateTolerance(0.001);
415  imageStatisticsFilter->SetInput(adaptedImage);
416  imageStatisticsFilter->SetLabelInput(maskImage);
417  imageStatisticsFilter->SetHistogramParametersForLabels(nBins, minVals, maxVals);
418  imageStatisticsFilter->Update();
419 
420  std::list<int> labels = imageStatisticsFilter->GetRelevantLabels();
421  auto it = labels.begin();
422 
423  while (it != labels.end())
424  {
425  ImageStatisticsContainer::Pointer statisticContainerForLabelImage;
426  auto labelIt = m_StatisticContainers.find(*it);
427  // reset if statisticContainer already exist
428  if (labelIt != m_StatisticContainers.end())
429  {
430  statisticContainerForLabelImage = labelIt->second;
431  }
432  // create new statisticContainer
433  else
434  {
435  statisticContainerForLabelImage = ImageStatisticsContainer::New();
436  statisticContainerForLabelImage->SetTimeGeometry(const_cast<mitk::TimeGeometry*>(timeGeometry));
437  // link label (*it) to statisticContainer
438  m_StatisticContainers.emplace(*it, statisticContainerForLabelImage);
439  }
440 
442 
443  // find min, max, minindex and maxindex
444  // make sure to only look in the masked region, use a masker for this
445 
446  vnl_vector<int> minIndex, maxIndex;
447  mitk::Point3D worldCoordinateMin;
448  mitk::Point3D worldCoordinateMax;
449  mitk::Point3D indexCoordinateMin;
450  mitk::Point3D indexCoordinateMax;
451  m_InternalImageForStatistics->GetGeometry()->IndexToWorld(minMaxFilter->GetMinIndex(*it), worldCoordinateMin);
452  m_InternalImageForStatistics->GetGeometry()->IndexToWorld(minMaxFilter->GetMaxIndex(*it), worldCoordinateMax);
453  m_Image->GetGeometry()->WorldToIndex(worldCoordinateMin, indexCoordinateMin);
454  m_Image->GetGeometry()->WorldToIndex(worldCoordinateMax, indexCoordinateMax);
455 
456  minIndex.set_size(3);
457  maxIndex.set_size(3);
458 
459  // for (unsigned int i=0; i < tmpMaxIndex.GetIndexDimension(); i++)
460  for (unsigned int i = 0; i < 3; i++)
461  {
462  minIndex[i] = indexCoordinateMin[i];
463  maxIndex[i] = indexCoordinateMax[i];
464  }
465 
468 
469  assert(std::abs(minMaxFilter->GetMax(*it) - imageStatisticsFilter->GetMaximum(*it)) < mitk::eps);
470  assert(std::abs(minMaxFilter->GetMin(*it) - imageStatisticsFilter->GetMinimum(*it)) < mitk::eps);
471 
472  auto voxelVolume = GetVoxelVolume<TPixel, VImageDimension>(image);
473  auto numberOfVoxels =
474  static_cast<unsigned long>(imageStatisticsFilter->GetSum(*it) / (double)imageStatisticsFilter->GetMean(*it));
475  auto volume = static_cast<double>(numberOfVoxels) * voxelVolume;
476  auto rms = std::sqrt(std::pow(imageStatisticsFilter->GetMean(*it), 2.) +
477  imageStatisticsFilter->GetVariance(*it)); // variance = sigma^2
478  auto variance = imageStatisticsFilter->GetSigma(*it) * imageStatisticsFilter->GetSigma(*it);
479 
482  statObj.AddStatistic(mitk::ImageStatisticsConstants::MEAN(), imageStatisticsFilter->GetMean(*it));
483  statObj.AddStatistic(mitk::ImageStatisticsConstants::MINIMUM(), imageStatisticsFilter->GetMinimum(*it));
484  statObj.AddStatistic(mitk::ImageStatisticsConstants::MAXIMUM(), imageStatisticsFilter->GetMaximum(*it));
485  statObj.AddStatistic(mitk::ImageStatisticsConstants::STANDARDDEVIATION(), imageStatisticsFilter->GetSigma(*it));
487  statObj.AddStatistic(mitk::ImageStatisticsConstants::SKEWNESS(), imageStatisticsFilter->GetSkewness(*it));
488  statObj.AddStatistic(mitk::ImageStatisticsConstants::KURTOSIS(), imageStatisticsFilter->GetKurtosis(*it));
490  statObj.AddStatistic(mitk::ImageStatisticsConstants::MPP(), imageStatisticsFilter->GetMPP(*it));
491  statObj.AddStatistic(mitk::ImageStatisticsConstants::ENTROPY(), imageStatisticsFilter->GetEntropy(*it));
492  statObj.AddStatistic(mitk::ImageStatisticsConstants::MEDIAN(), imageStatisticsFilter->GetMedian(*it));
493  statObj.AddStatistic(mitk::ImageStatisticsConstants::UNIFORMITY(), imageStatisticsFilter->GetUniformity(*it));
494  statObj.AddStatistic(mitk::ImageStatisticsConstants::UPP(), imageStatisticsFilter->GetUPP(*it));
495  statObj.m_Histogram = imageStatisticsFilter->GetHistogram(*it).GetPointer();
496 
497  statisticContainerForLabelImage->SetStatisticsForTimeStep(timeStep, statObj);
498  ++it;
499  }
500 
501  // swap maskGenerators back
502  if (swapMasks)
503  {
504  m_SecondaryMask = m_InternalMask;
505  m_InternalMask = nullptr;
506  }
507  }
508 
509  bool ImageStatisticsCalculator::IsUpdateRequired(LabelIndex label) const
510  {
511  unsigned long thisClassTimeStamp = this->GetMTime();
512  unsigned long inputImageTimeStamp = m_Image->GetMTime();
513 
514  auto it = m_StatisticContainers.find(label);
515  if (it == m_StatisticContainers.end())
516  {
517  return true;
518  }
519 
520  unsigned long statisticsTimeStamp = it->second->GetMTime();
521 
522  if (thisClassTimeStamp > statisticsTimeStamp) // inputs have changed
523  {
524  return true;
525  }
526 
527  if (inputImageTimeStamp > statisticsTimeStamp) // image has changed
528  {
529  return true;
530  }
531 
532  if (m_MaskGenerator.IsNotNull())
533  {
534  unsigned long maskGeneratorTimeStamp = m_MaskGenerator->GetMTime();
535  if (maskGeneratorTimeStamp > statisticsTimeStamp) // there is a mask generator and it has changed
536  {
537  return true;
538  }
539  }
540 
541  if (m_SecondaryMaskGenerator.IsNotNull())
542  {
543  unsigned long maskGeneratorTimeStamp = m_SecondaryMaskGenerator->GetMTime();
544  if (maskGeneratorTimeStamp > statisticsTimeStamp) // there is a secondary mask generator and it has changed
545  {
546  return true;
547  }
548  }
549 
550  return false;
551  }
552 } // namespace mitk
ImageStatisticsContainer * GetStatistics(LabelIndex label=1)
Returns the statistics for label label. If these requested statistics are not computed yet the comput...
itk::Image< unsigned char, 3 > ImageType
Extension of the itkLabelStatisticsImageFilter that also calculates the Skewness,Kurtosis,Entropy,Uniformity.
double GetBinSizeForHistogramStatistics() const
Retrieve the bin size for histogram statistics. Careful: The return value does not indicate whether N...
void SetSecondaryMask(mitk::MaskGenerator *mask)
Set this if more than one mask should be applied (for instance if a IgnorePixelValueMask were to be u...
Base Class for all Mask Generators. Mask generators are classes that provide functionality for the cr...
DataCollection - Class to facilitate loading/accessing structured data.
Utility class for mask operations. It checks whether an image and a mask are compatible (spacing...
void AddStatistic(const std::string &key, StatisticsVariantType value)
Adds a statistic to the statistics object.
unsigned int GetNBinsForHistogramStatistics() const
Retrieve the number of bins used for histogram statistics. Careful: The return value does not indicat...
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...
void SetMask(mitk::MaskGenerator *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.
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:72
std::vcl_size_t TimeStepType
static T max(T x, T y)
Definition: svm.cpp:56
mitk::Image::Pointer image
ImageStatisticsContainer::LabelIndex LabelIndex
static const std::string STANDARDDEVIATION()
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.
static Pointer New()
MITKCORE_EXPORT const ScalarType eps
unsigned short PixelType
mitk::Image::Pointer mask
#define AccessByItk_2(mitkImage, itkImageTypeFunction, arg1, arg2)
void SetBinSizeForHistogramStatistics(double binSize)
Set bin size to be used for histogram statistics. If nbins is set after bin size, nbins will be used ...
Container class for storing the computed image statistics.
itk::SmartPointer< Self > Pointer
Definition: mitkBaseData.h:41
void SetInputImage(const mitk::Image *image)
Set the image for which the statistics are to be computed.
Container class for storing a StatisticsObject for each timestep.
static Pointer New()