Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
ImageStatisticsMiniapp_3.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkCommandLineParser.h"
18 #include "mitkImage.h"
19 #include <mitkImageStatisticsCalculator.h>
20 #include <mitkExtendedLabelStatisticsImageFilter.h>
22 #include <mitkPlanarFigure.h>
23 #include "mitkIOUtil.h"
24 #include <iostream>
25 #include <usAny.h>
26 #include <fstream>
27 #include <itkImageRegionConstIterator.h>
28 #include "mitkImageAccessByItk.h"
29 #include <boost/accumulators/accumulators.hpp>
30 #include <boost/accumulators/statistics/stats.hpp>
31 #include <boost/accumulators/statistics/mean.hpp>
32 #include <boost/accumulators/statistics/variance.hpp>
33 #include <boost/accumulators/statistics/min.hpp>
34 #include <boost/accumulators/statistics/max.hpp>
35 #include <boost/accumulators/statistics/count.hpp>
36 #include <boost/accumulators/statistics/moment.hpp>
37 #include <mitkImageMaskGenerator.h>
39 #include <mitkImageGenerator.h>
40 
41 
42 int main( int argc, char* argv[] )
43 {
44  unsigned int timeStep = 0;
45  std::string inputImageFile, maskImageFile;
46  inputImageFile = "/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D.nrrd";
47  maskImageFile = "/home/fabian/MITK/MITK_platform_project/bin/MITK-superbuild/MITK-Data/Pic3D_someSegmentation.nrrd";
48  // Load image
49  mitk::Image::Pointer inputImage = mitk::IOUtil::LoadImage(inputImageFile);
50  mitk::Image::Pointer maskImage = mitk::IOUtil::LoadImage(maskImageFile);
51 
52 
53  // Calculate statistics
55 
56  std::cout << "calculating statistics (unmasked) itk: " << std::endl;
58 
60  imgMaskGen->SetImageMask(maskImage);
61 
62  calculator->SetMask(imgMaskGen.GetPointer());
63  calculator->SetInputImage(inputImage);
64  calculator->SetNBinsForHistogramStatistics(100);
65 
66  for (unsigned int i=0; i < inputImage->GetTimeSteps(); i++)
67  {
68  std::cout << "Results for time step " << i << ":" << std::endl;
69  result = calculator->GetStatistics(i, 1);
70  result->Print();
71  std::cout << std::endl;
72  }
73  MITK_INFO << "-------------";
74  mitk::Image::Pointer test = imgMaskGen->GetMask();
75  MITK_INFO << "-------------";
76 
77  mitk::Image::Pointer test2 = imgMaskGen->GetMask();
78  MITK_INFO << "-------------";
79  imgMaskGen->SetTimeStep(2);
80  mitk::Image::Pointer test3 = imgMaskGen->GetMask();
81 
82 
83  return EXIT_SUCCESS;
84 }
int main(int argc, char *argv[])
#define MITK_INFO
Definition: mitkLogMacros.h:22
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
Definition: testcase.h:32
static Pointer New()
static mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597