Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkGIFLocalIntensityTest.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 
13 #include <mitkTestingMacros.h>
14 #include <mitkTestFixture.h>
15 #include "mitkIOUtil.h"
16 #include <cmath>
17 
18 #include <mitkGIFLocalIntensity.h>
19 
20 class mitkGIFLocalIntensityTestSuite : public mitk::TestFixture
21 {
22  CPPUNIT_TEST_SUITE(mitkGIFLocalIntensityTestSuite);
23 
24  MITK_TEST(ImageDescription_PhantomTest_Small);
25  MITK_TEST(ImageDescription_PhantomTest_Large);
26  MITK_TEST(ImageDescription_PhantomTest_Large_RangeChanged);
27 
28  CPPUNIT_TEST_SUITE_END();
29 
30 private:
31  mitk::Image::Pointer m_IBSI_Phantom_Image_Small;
32  mitk::Image::Pointer m_IBSI_Phantom_Image_Large;
33  mitk::Image::Pointer m_IBSI_Phantom_Mask_Small;
34  mitk::Image::Pointer m_IBSI_Phantom_Mask_Large;
35 
36 public:
37 
38  void setUp(void) override
39  {
40  m_IBSI_Phantom_Image_Small = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("Radiomics/IBSI_Phantom_Image_Small.nrrd"));
41  m_IBSI_Phantom_Image_Large = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("Radiomics/IBSI_Phantom_Image_Large.nrrd"));
42  m_IBSI_Phantom_Mask_Small = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("Radiomics/IBSI_Phantom_Mask_Small.nrrd"));
43  m_IBSI_Phantom_Mask_Large = mitk::IOUtil::Load<mitk::Image>(GetTestDataFilePath("Radiomics/IBSI_Phantom_Mask_Large.nrrd"));
44  }
45 
46  void ImageDescription_PhantomTest_Small()
47  {
49 
50  auto featureList = featureCalculator->CalculateFeatures(m_IBSI_Phantom_Image_Small, m_IBSI_Phantom_Mask_Small);
51 
52  std::map<std::string, double> results;
53  for (auto valuePair : featureList)
54  {
55  MITK_INFO << valuePair.first << " : " << valuePair.second;
56  results[valuePair.first] = valuePair.second;
57  }
58  CPPUNIT_ASSERT_EQUAL_MESSAGE("Image Diagnostics should calculate 2 features.", std::size_t(2), featureList.size());
59 
60  // These values are obtained in cooperation with IBSI
61  // Reported with an accuracy of 0.1
62  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Local Intensity::Local Intensity Peak with Large IBSI Phantom Image", 2.6, results["Local Intensity::2. Local Intensity Peak"], 0.1);
63  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Local Intensity::Global Intensity Peak with Large IBSI Phantom Image", 3.1, results["Local Intensity::2. Global Intensity Peak"], 0.1);
64  }
65 
66  void ImageDescription_PhantomTest_Large()
67  {
69 
70  auto featureList = featureCalculator->CalculateFeatures(m_IBSI_Phantom_Image_Large, m_IBSI_Phantom_Mask_Large);
71 
72  std::map<std::string, double> results;
73  for (auto valuePair : featureList)
74  {
75  MITK_INFO << valuePair.first << " : " << valuePair.second;
76  results[valuePair.first] = valuePair.second;
77  }
78  CPPUNIT_ASSERT_EQUAL_MESSAGE("Image Diagnostics should calculate 2 features.", std::size_t(2), featureList.size());
79 
80  // These values are obtained by running the tool
81  // They might be wrong
82  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Local Intensity::Local Intensity Peak with Large IBSI Phantom Image", 1.43, results["Local Intensity::2. Local Intensity Peak"], 0.01);
83  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Local Intensity::Global Intensity Peak with Large IBSI Phantom Image", 1.43, results["Local Intensity::2. Global Intensity Peak"], 0.01);
84  }
85 
86  void ImageDescription_PhantomTest_Large_RangeChanged()
87  {
89 
90  featureCalculator->SetRange(1);
91 
92  auto featureList = featureCalculator->CalculateFeatures(m_IBSI_Phantom_Image_Large, m_IBSI_Phantom_Mask_Large);
93 
94  std::map<std::string, double> results;
95  for (auto valuePair : featureList)
96  {
97  MITK_INFO << valuePair.first << " : " << valuePair.second;
98  results[valuePair.first] = valuePair.second;
99  }
100  CPPUNIT_ASSERT_EQUAL_MESSAGE("Image Diagnostics should calculate 2 features.", std::size_t(2), featureList.size());
101 
102  // These values are obtained by running the tool
103  // They might be wrong
104  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Local Intensity::Local Intensity Peak with Large IBSI Phantom Image", 6, results["Local Intensity::2. Local Intensity Peak"], 0.01);
105  CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Local Intensity::Global Intensity Peak with Large IBSI Phantom Image", 6, results["Local Intensity::2. Global Intensity Peak"], 0.01);
106  }
107 
108 };
109 
110 MITK_TEST_SUITE_REGISTRATION(mitkGIFLocalIntensity )
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
static std::string GetTestDataFilePath(const std::string &testData)
Get the absolute path for test data.
Test fixture for parameterized tests.
static Pointer New()