Page MenuHomePhabricator

Write migration guide for image statistics calculation
Open, NormalPublic

Description

Some parts of ImageStatisticsCalculator have changed, especially the usage of ImageStatisticsContainer.

Before

//instantiate ImageStatisticsCalculator and add image
mitk::ImageStatisticsCalculator::Pointer calculator = mitk::ImageStatisticsCalculator::New();
calculator->SetInputImage(image);

//statistics are calculated for each time step on the fly if requested
unsigned int startT = 0;
unsigned int endT = image->GetTimeSteps();
for (unsigned int t = startT; t<=endT; t++){
  //request statistics for current timestep
  mitk::StatisticsContainer::Pointer statistics = calculator->GetStatistics(t);
  double mean = statistics->GetMean();
  double median = statistics->GetMedian();
  double min = statistics->GetMin();
  double max = statistics->GetMax();
  const vnl_vector<int> minIndex = statistics->GetMinIndex();
  const HistogramType::Pointer histogram = statistics->GetHistogram();
}

After

//instantiate ImageStatisticsCalculator and add image
mitk::ImageStatisticsCalculator::Pointer calculator = mitk::ImageStatisticsCalculator::New();
//now takes a ConstPointer as input
calculator->SetInputImage(image.GetPointer());
//all statistics are automatically computed for each timestep 
mitk::ImageStatisticsContainer::Pointer statistics = calculator->GetStatistics();

//iterate over timesteps
unsigned int startT = 0;
unsigned int endT = image->GetTimeSteps();
for (unsigned int t = startT; t<=endT; t++){
  //check if time step exists
  if (statistics->TimeStepExists(t)){
    //request statistics object for current timestep
    mitk::StatisticsObject aStatistic = statistics->GetStatisticsForTimeStep(t);
    //request all default statistic names
    mitk::ImageStatisticsContainer::StatisticsObject::StatisticNameVector names = GetDefaultStatisticNames();
    //iteration over all statistics could not be done previously
    for (const auto name : names){
      //returning variable is a boost::variant
      mitk::ImageStatisticsContainer::StatisticsVariantType statisticValue = aStatistic.GetValueNonConverted(name);
      std::cout << statisticValue << std::endl;
    }
    //returning variable can also be converted if output type is known (identification of statistic is by name)
    const std::string meanName= mitk::ImageStatisticsConstants::MEAN();
    const std::string medianName = mitk::ImageStatisticsConstants::MEDIAN();
    const std::string minName = mitk::ImageStatisticsConstants::MIN();
    const std::string maxName = mitk::ImageStatisticsConstants::MAX();
    const std::string minIndexName = mitk::ImageStatisticsConstants::MINIMUMPOSITION();
    double mean = aStatistic.GetValueConverted<mitk::ImageStatisticsContainer::RealType>(meanName);
    double median = aStatistic.GetValueConverted<mitk::ImageStatisticsContainer::RealType>(medianName);
    double min = aStatistic.GetValueConverted<mitk::ImageStatisticsContainer::RealType>(minName);
    double max = aStatistic.GetValueConverted<mitk::ImageStatisticsContainer::RealType>(maxName);
    const vnl_vector<int> minIndex = aStatistic.GetValueConverted<mitk::ImageStatisticsContainer::IndexType>(minIndexName);
    //Histogram is a public variable
    mitk::ImageStatisticsContainer::HistogramType::ConstPointer histogram = aStatistic._m_Histogram;
  }
}

Related Objects

StatusAssignedTask
OpenNone
OpenNone

Event Timeline

hentsch triaged this task as Normal priority.Jan 10 2019, 9:38 AM
hentsch created this task.
kislinsk renamed this task from Write migration guide to Write migration guide for image statistics calculation.Mar 29 2019, 8:43 AM