Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkClassificationTest.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 #ifdef _MSC_VER
13 # pragma warning(disable : 4996)
14 #endif
15 
16 #include "mitkTestFixture.h"
17 #include "mitkTestingMacros.h"
18 
20 #include "mitkIOUtil.h"
21 
22 #include "mitkDataCollection.h"
26 
27 #include <vtkSmartPointer.h>
28 
37 class mitkClassificationTestSuite : public mitk::TestFixture
38 {
39  CPPUNIT_TEST_SUITE(mitkClassificationTestSuite);
40  MITK_TEST(TestClassification);
41  CPPUNIT_TEST_SUITE_END();
42 
43 public:
48  void setUp() override {}
49  void tearDown() override {}
50  void TestClassification()
51  {
52  size_t forestSize = 10;
53  size_t treeDepth = 2;
54 
55  std::string train = GetTestDataFilePath("DiffusionImaging/ProgressionAnalysis/Classification/Train.xml");
56  std::string eval = GetTestDataFilePath("DiffusionImaging/ProgressionAnalysis/Classification/Test.xml");
57 
58  std::vector<std::string> modalities;
59 
60  modalities.push_back("MOD0");
61  modalities.push_back("MOD1");
62 
64  mitk::DataCollection::Pointer collection = colReader.LoadCollection(train);
65  colReader.Clear();
66  // read evaluation collection
67 
68  mitk::DataCollection::Pointer evaluation = colReader.LoadCollection(eval);
69 
71 
72  progression.SetClassRatio(1);
73  progression.SetTrainMargin(4, 0);
74  progression.SetMaskID("MASK");
75 
76  progression.SelectTrainingSamples(collection);
77  progression.LearnProgressionFeatures(collection, modalities, forestSize, treeDepth);
78 
79  progression.PredictInvasion(evaluation, modalities);
80 
81  auto refImage = mitk::IOUtil::Load<mitk::Image>(
82  GetTestDataFilePath("DiffusionImaging/ProgressionAnalysis/Classification/TESTING_RESULT.nrrd"));
83 
84  mitk::DataCollection *patCol = dynamic_cast<mitk::DataCollection *>(evaluation->GetData(0).GetPointer());
85  mitk::DataCollection *subCol = dynamic_cast<mitk::DataCollection *>(patCol->GetData(0).GetPointer());
86  mitk::Image::Pointer resultImage = subCol->GetMitkImage("RESULT");
87 
88  // Test result against fixed reference.
89  // Require more than 90% to be correct.
90  // 10% margin due to
91  // 1) unsure classification in transitional regions and
92  // 2) stochastic training procedure
93 
94  // Total number of voxels 2400 -> 10% err -> 240 voxels margin
95 
97  compareFilter->SetInput(0, refImage.GetPointer());
98  compareFilter->SetInput(1, resultImage);
99  compareFilter->SetTolerance(.1);
100  compareFilter->Update();
101 
102  MITK_TEST_CONDITION_REQUIRED(compareFilter->GetResult(240), "Compare prediction results to reference image.")
103  }
104 };
105 MITK_TEST_SUITE_REGISTRATION(mitkClassification)
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
void SetTrainMargin(vcl_size_t dil2d, vcl_size_t dil3d)
void SetMaskID(std::string maskID="BRAINMASK")
SetMaskID sets binary mask denoting area that is evluated/included in training.
mitk::Image::Pointer GetMitkImage(vcl_size_t index)
GetMitkImage - casts data to mitk::Image and returns it.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
void SelectTrainingSamples(DataCollection *collection, unsigned int mode=0)
SelectTrainingSamples.
void PredictInvasion(DataCollection *collection, std::vector< std::string > modalitiesList)
PredictGrowth - Classify voxels into remaining healthy / turning into tumor.
static Pointer New()
Test fixture for parameterized tests.
DataCollection::Pointer LoadCollection(const std::string &xmlFileName)
Build up a mitk::DataCollection from a XML resource.
The TumorInvasionAnalysis class - Classifies Tumor progression using RF and predicts on new cases...
void LearnProgressionFeatures(DataCollection *collection, std::vector< std::string > modalitiesList, vcl_size_t forestSize=300, vcl_size_t treeDepth=10)
LearnProgressionFeatures.
void SetClassRatio(ScalarType ratio)
SetClassRatio - set ratio of tumor voxels to healthy voxels that is to be used for training...