Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkPixelBasedParameterFitImageGeneratorTest.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 <iostream>
14 
15 #include "itkImageRegionIterator.h"
16 
17 #include "mitkTestingMacros.h"
18 #include "mitkImage.h"
20 
23 
25 
27 
28 int mitkPixelBasedParameterFitImageGeneratorTest(int /*argc*/, char*[] /*argv[]*/)
29 {
30  // always start with this!
31  MITK_TEST_BEGIN("mitkPixelBasedParameterFitImageGenerator")
32 
33  //Prepare test artifacts and helper
34 
35  itk::Index<3> testIndex1;
36  testIndex1[0] = 0;
37  testIndex1[1] = 0;
38  testIndex1[2] = 0;
39 
40  itk::Index<3> testIndex2;
41  testIndex2[0] = 2;
42  testIndex2[1] = 0;
43  testIndex2[2] = 1;
44 
45  itk::Index<3> testIndex3;
46  testIndex3[0] = 1;
47  testIndex3[1] = 1;
48  testIndex3[2] = 2;
49 
50  itk::Index<3> testIndex4;
51  testIndex4[0] = 2;
52  testIndex4[1] = 2;
53  testIndex4[2] = 0;
54 
55  itk::Index<3> testIndex5;
56  testIndex5[0] = 1;
57  testIndex5[1] = 1;
58  testIndex5[2] = 1;
59 
60  itk::Index<3> testIndex6;
61  testIndex6[0] = 2;
62  testIndex6[1] = 1;
63  testIndex6[2] = 1;
64 
65 
67 
70 
71  //Test default usage of filter
72  mitk::PixelBasedParameterFitImageGenerator::Pointer generator = mitk::PixelBasedParameterFitImageGenerator::New();
74  generator->SetDynamicImage(dynamicImage);
75  generator->SetModelParameterizer(parameterizer);
76  generator->SetFitFunctor(testFunctor);
77 
78  generator->Generate();
79 
80  mitk::PixelBasedParameterFitImageGenerator::ParameterImageMapType resultImages = generator->GetParameterImages();
81  mitk::PixelBasedParameterFitImageGenerator::ParameterImageMapType derivedResultImages = generator->GetDerivedParameterImages();
82 
83  CPPUNIT_ASSERT_MESSAGE("Check number of parameter images", 2 == resultImages.size());
84  MITK_TEST_CONDITION(resultImages.find("slope") != resultImages.end(),"Check if \"slope\" parameter image exists.");
85  MITK_TEST_CONDITION(resultImages.find("offset") != resultImages.end(),"Check if \"offset\" parameter image exists.");
86  CPPUNIT_ASSERT_MESSAGE("Check number of derived parameter images", 1 == derivedResultImages.size());
87  MITK_TEST_CONDITION(derivedResultImages.find("x-intercept") != derivedResultImages.end(),"Check if \"x-intercept\" derived parameter image exists.");
88 
89  mitk::ImagePixelReadAccessor<mitk::ScalarType,3> slopeAccessor(resultImages["slope"]);
90  mitk::ImagePixelReadAccessor<mitk::ScalarType,3> offsetAccessor(resultImages["offset"]);
91 
92  double testValue = slopeAccessor.GetPixelByIndex(testIndex1);
93  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #1 (slope) at index #1");
94  testValue = slopeAccessor.GetPixelByIndex(testIndex2);
95  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(2000,testValue, 1e-4, true)==true, "Check param #1 (slope) at index #2");
96  testValue = slopeAccessor.GetPixelByIndex(testIndex3);
97  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(4000,testValue, 1e-4, true)==true, "Check param #1 (slope) at index #3");
98  testValue = slopeAccessor.GetPixelByIndex(testIndex4);
99  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(8000,testValue, 1e-4, true)==true, "Check param #1 (slope) at index #4");
100 
101  testValue = offsetAccessor.GetPixelByIndex(testIndex1);
102  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #1");
103  testValue = offsetAccessor.GetPixelByIndex(testIndex2);
104  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(10,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #2");
105  testValue = offsetAccessor.GetPixelByIndex(testIndex3);
106  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(20,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #3");
107  testValue = offsetAccessor.GetPixelByIndex(testIndex4);
108  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #4");
109 
110  //Test with mask set
112  generator->SetMask(maskImage);
113 
114  generator->Generate();
115 
116  resultImages = generator->GetParameterImages();
117  derivedResultImages = generator->GetDerivedParameterImages();
118 
119  CPPUNIT_ASSERT_MESSAGE("Check number of parameter images", 2 == resultImages.size());
120  MITK_TEST_CONDITION(resultImages.find("slope") != resultImages.end(),"Check if \"slope\" parameter image exists.");
121  MITK_TEST_CONDITION(resultImages.find("offset") != resultImages.end(),"Check if \"offset\" parameter image exists.");
122  CPPUNIT_ASSERT_MESSAGE("Check number of derived parameter images", 1 == derivedResultImages.size());
123  MITK_TEST_CONDITION(derivedResultImages.find("x-intercept") != derivedResultImages.end(),"Check if \"x-intercept\" derived parameter image exists.");
124 
125  mitk::ImagePixelReadAccessor<mitk::ScalarType,3> slopeAccessor2(resultImages["slope"]);
126  mitk::ImagePixelReadAccessor<mitk::ScalarType,3> offsetAccessor2(resultImages["offset"]);
127 
128  testValue = slopeAccessor2.GetPixelByIndex(testIndex1);
129  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #1 (slope) at index #1");
130  testValue = slopeAccessor2.GetPixelByIndex(testIndex2);
131  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(2000,testValue, 1e-4, true)==true, "Check param #1 (slope) at index #2");
132  testValue = slopeAccessor2.GetPixelByIndex(testIndex3);
133  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #1 (slope) at index #3");
134  testValue = slopeAccessor2.GetPixelByIndex(testIndex4);
135  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(8000,testValue, 1e-4, true)==true, "Check param #1 (slope) at index #4");
136  testValue = slopeAccessor2.GetPixelByIndex(testIndex5);
137  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(4000,testValue, 1e-4, true)==true, "Check param #1 (slope) at index #5");
138  testValue = slopeAccessor2.GetPixelByIndex(testIndex6);
139  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #1 (slope) at index #6");
140 
141  testValue = offsetAccessor2.GetPixelByIndex(testIndex1);
142  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #1");
143  testValue = offsetAccessor2.GetPixelByIndex(testIndex2);
144  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(10,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #2");
145  testValue = offsetAccessor2.GetPixelByIndex(testIndex3);
146  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #3");
147  testValue = offsetAccessor2.GetPixelByIndex(testIndex4);
148  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #4");
149  testValue = offsetAccessor2.GetPixelByIndex(testIndex5);
150  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(10,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #5");
151  testValue = offsetAccessor2.GetPixelByIndex(testIndex6);
152  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0,testValue, 1e-5, true)==true, "Check param #2 (offset) at index #6");
153 
154  MITK_TEST_END()
155 }
Image::Pointer MITKTESTINGHELPER_EXPORT GenerateTestMaskMITK()
Gives locked and index-based read access for a particular image part. The class provides several set-...
ParameterFitImageGeneratorBase::ParameterImageMapType ParameterImageMapType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
const TPixel & GetPixelByIndex(const itk::Index< VDimension > &idx) const
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
#define MITK_TEST_CONDITION(COND, MSG)
Image::Pointer MITKTESTINGHELPER_EXPORT GenerateDynamicTestImageMITK()
static Pointer New()
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
int mitkPixelBasedParameterFitImageGeneratorTest(int, char *[])
and MITK_TEST_END()